Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticker.h - Too-large timeouts should generate an error, not silently fail (was: big float and unt32_t numbers) #8066

Closed
enjoyneering opened this issue May 21, 2021 · 4 comments · Fixed by #8625

Comments

@enjoyneering
Copy link

enjoyneering commented May 21, 2021

Platform

  • Hardware: [ESP-12]
  • Core Version: [2.7.4] & [3.0.0]
  • Development Env: [Arduino IDE]
  • Operating System: [Windows]

Settings in IDE

  • Module: [Generic ESP8266]
  • Flash Mode: [qio]
  • Flash Size: [4MB]
  • lwip Variant: [v2 Higher Bandwidth]
  • Reset Method: [nodemcu]
  • Flash Frequency: [80Mhz]
  • CPU Frequency: [80Mhz]
  • Upload Using: [OTA|SERIAL]
  • Upload Speed: [115200]

Problem Description

Any Ticker tasks fire OK if time is short (tested up to 60 seconds (60 000ms)). However, when I try to control the brightness after sunset, the time gets big (for example 44944 sec (44 944 000ms)) & the same task no longer start. The code below is not exactly what I have in my project, but close.

MCVE Sketch

#include <Arduino.h>
#include <Ticker.h>

Ticker ticker_autoBrightness;

uint32_t timeSec = 44079; //12h:14m:39s

void setup() {
pinMode(2, OUTPUT);

task_clockDayBrightness();
}

void loop() {
//empty
}

void task_clockDayBrightness()
{
  digitalWrite(2, LOW); //turn LED on

  ticker_autoBrightness.once_scheduled(timeSec, task_clockNightBrightness);
}

void task_clockNightBrightness()
{
  digitalWrite(2, HIGH); //turn LED off

  ticker_autoBrightness.once_scheduled(timeSec, task_clockDayBrightness);
}

@mobizt
Copy link
Contributor

mobizt commented May 22, 2021

The allowed ranges of software timer (used in Ticker library) are 5 milliseconds to 1.9 hours or 6870 seconds (timing is in millisecond).

os_timer_arm(_timer, milliseconds, repeat);

See ESP8266 Non-OS SDK API Ref at section 3.1.1. os_timer_arm

@enjoyneering
Copy link
Author

enjoyneering commented May 22, 2021

Thank you mobizt. Didn't know about it. Float and uint32_t confused me.

once_scheduled(float seconds, callback_function_t callback)
void _attach_ms(uint32_t milliseconds, bool repeat)

If I wanted to learn Non-OS SDK API, I would not use additional Arduino layer. This should be in the Arduino doc - valid Ticker timer range 5msec..6870947msec (0.005sec..6870.947sec).

@earlephilhower earlephilhower changed the title Ticker.h - big float and unt32_t numbers Ticker.h - Too-large timeouts should generate an error, not silently fail (was: big float and unt32_t numbers) Jun 3, 2021
@earlephilhower
Copy link
Collaborator

Updated the title a bit. I haven't dug into it, but if Ticker is passed a value it can't actually support it should generate an error somehow, not just silently do nothing so it's somewhere between a bug and enhancement need IMHO.

@d-a-v d-a-v added this to the 3.0.1 milestone Jun 3, 2021
@dok-net
Copy link
Contributor

dok-net commented Jun 3, 2021

@earlephilhower Ticker has all "void" functions. Short of changing all of them, there are two solutions that come to mind:

  • assert() in Ticker::_attach_ms()
  • In Ticker::_attach_ms(), if the duration is not supported, set _timer = nullptr;, which in turn makes bool Ticker::active() const false, something a user can check for after calling any of the attach... functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants