Giter VIP home page Giter VIP logo

eventually's People

Contributors

benjenkinson avatar johnnyb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eventually's Issues

Bug in EvtContext::addListener ?

Hi,

And many thanks for this nice library! I intend to use in for a project with my students.

I have two questions and one suggestion about the EvtContext::addListener method.

Question 1 :

I think that there is a bug in EvtContext::addListener.
In the first for loop, I think you should use i as the index of listeners[] instead of listenerCount.

In other words, you should replace

for(int i = 0; i < listenerCount; i++) { // Try to add in empty slot
  if(listeners[listenerCount] == 0) {
    listeners[listenerCount] = lstn;
    return;
  }
}

by

for(int i = 0; i < listenerCount; i++) { // Try to add in empty slot
  if(listeners[i] == 0) {
    listeners[i] = lstn;
    return;
  }
}

Question 2 :

I'm not sure of that, but I think you should also add lstn->setupListener(); in this loop.
The result would then be:

for(int i = 0; i < listenerCount; i++) { // Try to add in empty slot
  if(listeners[i] == 0) {
    listeners[i] = lstn;
    lstn->setupListener();
    return;
  }
}

Suggestion :

This method could return a pointer to the EvtListener * that it got in parameter.
Thus the prototype would become
EvtListener * EvtContext::addListener(EvtListener *lstn);
and the method return lstn.

This would enable to make calls like:

EvtListener *pLstn;
pLstn = EvtContext::addListener(new EvtPinListener(SOME_PIN, (EvtAction)some_action));

and then use pLstn as an id to remove this event:

mgr.removeListener(pLstn);

Feature request. Add pin listener for high and low.

Hi I really like the library. It would be nice to have the ability to add a listener for high and a listener for low states. Right now is seems the listener only fires when high? Just from my testing.

The feature I would like would be Similar to how other programming languages have addListenerButtonDown(run once on button down) and addListenerButtonUp(run once on button up) and addListenerButton(usually means continues firing while down)

Expander Serial

What if I want to listen (EvtPinListener) to change pin state not in Arduino itself but in expander chip ?

esp8266 - event fire not work

I made a temperature measurer station with an esp8266 and an oled distpay. I add event handlers at setup: a Timer event handled and a Http event handler. Because I want access measured info over wifi network. I add two listener but events fired only for the first one. Second event not fired, only just the first registration.
Code is here:
https://infokristaly.hu/?q=node/850

Example with mgr.resetContext() misleading, leads to exception and program termination

I started out with the example code from the Readme page and from there started developing some more complex scenario involving two timers. I quickly stumbled across the issues already reported related to the addListeners method, found another problem with non-multiFire listeners (added comment in existing issue report) but then came across a much more serious issue that crashes the executing program with an exception.

Per readme, I figured I can kill all existing timers with mgr.resetContext() from within a callback method.

bool start_blinking() {
  mgr.resetContext(); 
  mgr.addListener(new EvtTimeListener(500, true, (EvtAction)blink_pin));
  mgr.addListener(new EvtPinListener(BUTTON_PIN, (EvtAction)stop_blinking));
  return true;
}

The problem is that as part of the mgr.resetContext() method, the existing listener objects get deleted, while start_blinking() is called FROM a listener object. Once the callback method, here start_blinking, has completed the handleTimerEvent() still accesses member variables of the listener object like multiFire and even calls the non-static method setupListener() on a deleted object. Per CPP spec, this is undefined behavior. During my experiments I see an exception with subsequent termination of the program.

My background is managed languages (C#, JS, Java) so I'm still trying to wrap my head around this, trying to figure out how this chicken-egg problem can be avoided. I guess the listener deletion would have to be deferred until the performTriggerAction method has completed.

In the meantime, do NOT use the construct that is shown in the Readme.

stepper motor control

Hi Jonathan

I've been using "Eventually" to de-bouncing control inputs and to control a stepper motor, at present I'm doing the following:

To control stepper motor speed I'm using the following:
mgr.addListener(new EvtTimeListener(0, true, (EvtAction)motorspeed)); //Pulse Stepper Motor

bool motorspeed() { //Pulse output to step motor
if (motorstep == 0) {
motorstep = 1;
digitalWrite(8, HIGH);
} else {
motorstep = 0;
digitalWrite(8, LOW);
}
return false;
}

However the sketch is limiting the stepper motor speed compared to using
#include <AccelStepper.h> and a while statement

Look forward to your comments

Thanks
James
stepperMotor_control.zip

Line 81 - looking for an empty slot...

It uses i to seek an empty slot then puts the new even on the end (eventcount) anyway(!)

I was having problems - with events just disappearing (not being set up) - and traced it back to this.

BUG: EvtTimeListener endless fire

I would like to create a one time event, but it trigger endless fire.
Code snipped:

#include "Eventually.h"

EvtManager mgr;

void setup() 
{
  Serial.begin(9600);
  mgr.addListener(new EvtTimeListener(1000, false, (EvtAction)sayHelloSerial));   
}

void loop() 
{
  mgr.loopIteration();
}

bool sayHelloSerial() {
  Serial.println("Hello Serial");
  return false;
}

Expected result (after 1s says):

Hello Serial

Actual result (immediately prints endless):

Hello Serial
Hello Serial
Hello Serial
...

I am using version 0.1.5

Main loop question

Is it possible to use this library while retaining the main loop? I would like to integrate it into an existing project but I don't want to rewrite the code currently in loop().

removeListener

Hi,

Hi, would I remove a particular listener, please?
Thanks
Stephen

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.