Code Monkey home page Code Monkey logo

Comments (7)

nrwiersma avatar nrwiersma commented on May 28, 2024

Can you explain more about what your are seeing?

from esp8266scheduler.

0x0ACB avatar 0x0ACB commented on May 28, 2024
void foo()
{
  delay(10 * 1000); // does not call Task::delay
}
class Foo : public Task {
 virtual void loop() final
 {
   foo();
 }
}s_fooTask;

In this code the daly in foo() will not call Task::delay which results in all other tasks being suspended for 10 seconds

from esp8266scheduler.

nrwiersma avatar nrwiersma commented on May 28, 2024

It would not call Task::delay as it is not in the task. It is an external method, as therefore would use the external delay. It has no reference to the task.

from esp8266scheduler.

0x0ACB avatar 0x0ACB commented on May 28, 2024

Yeah but thats kinda problematic if you can only call subroutines inside the Task the whole longjmp solution becomes kinda redundant

from esp8266scheduler.

nrwiersma avatar nrwiersma commented on May 28, 2024

What your proposed solution here?

I tend to disagree with your argument though. Expecting delay in an external function to suddenly call the Task::delay would be weird and wrong. The idea is for the each Task to contain its own logic, hence it has its own setup and loop functions. It is meant to be a contained unit.

An example of perhaps what you are perhaps trying to do is as follows:

#ifndef LIGHT_H
#define LIGHT_H

#include <Arduino.h>
#include <Task.h>

#define LIGHT_STATE_ON 930
#define LIGHT_STATE_OFF 0

class Light : public Task {
public:
    Light(uint8_t pin) : pin(pin), goal(0), state(0), steps(0), stepDelay(0) {}

    void setup() {
        pinMode(pin, OUTPUT);
        analogWrite(pin, state);
    }

    void loop() {
        int16_t state = state + ((goal - state) / steps);
        analogWrite(pin, state);

        if (state == goal) {
            steps = 0;
            return;
        }

        steps--;

        if (steps > 0) {
            delay(stepDelay);
        }
    }

    bool shouldRun() {
        bool run = Task::shouldRun();

        return run && steps > 0;
    }

    void set(uint16_t goal) {
        this->goal = goal;
        this->steps = 0;
        this->stepDelay = 0;
    }

    void set(uint16_t goal, uint16_t steps, uint16_t delay) {
        this->goal = goal;
        this->steps = steps;
        this->stepDelay = delay;
    }

protected:
    uint8_t pin;
    uint16_t goal;
    uint16_t state;
    uint16_t steps;
    uint16_t stepDelay;
};

#endif

Does that help perhaps?

from esp8266scheduler.

0x0ACB avatar 0x0ACB commented on May 28, 2024

No that does not help with my case. I have to call external code that calls delay and wanted to run other stuff during that time. Hence the whish for delay to work from any function. I guess I will have to write something myself or try to get this scheduler running

from esp8266scheduler.

nrwiersma avatar nrwiersma commented on May 28, 2024

Fair enough. Good luck.

from esp8266scheduler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.