My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tiny_timer.h 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /****************
  2. * tiny_timer.h *
  3. ****************/
  4. /****************************************************************************
  5. * Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
  6. * *
  7. * This program is free software: you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation, either version 3 of the License, or *
  10. * (at your option) any later version. *
  11. * *
  12. * This program is distributed in the hope that it will be useful, *
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15. * GNU General Public License for more details. *
  16. * *
  17. * To view a copy of the GNU General Public License, go to the following *
  18. * location: <https://www.gnu.org/licenses/>. *
  19. ****************************************************************************/
  20. #pragma once
  21. /* Helpful Reference:
  22. *
  23. * https://arduino.stackexchange.com/questions/12587/how-can-i-handle-the-millis-rollover
  24. */
  25. /* tiny_interval_t downsamples a 32-bit millis() value
  26. into a 8-bit value which can record periods of
  27. a few seconds with a rougly 1/16th of second
  28. resolution. This allows us to measure small
  29. intervals without needing to use four-byte counters.
  30. */
  31. class tiny_time_t {
  32. private:
  33. friend class tiny_timer_t;
  34. uint8_t _duration;
  35. static uint8_t tiny_time(uint32_t ms) {return ceil(float(ms) / 64);};
  36. public:
  37. tiny_time_t() : _duration(0) {}
  38. tiny_time_t(uint32_t ms) : _duration(tiny_time(ms)) {}
  39. tiny_time_t & operator= (uint32_t ms) {_duration = tiny_time(ms); return *this;}
  40. bool operator == (uint32_t ms) {return _duration == tiny_time(ms);}
  41. };
  42. class tiny_timer_t {
  43. private:
  44. uint8_t _start;
  45. public:
  46. void start();
  47. bool elapsed(tiny_time_t interval);
  48. };