Added elapsed time support for seconds, minutes, hours and days.

// elapsed time support
uint8_t getNumberOfSeconds(uint32_t time);
uint8_t getNumberOfMinutes(uint32_t time);
uint8_t getNumberOfHours(uint32_t time);
uint8_t getNumberOfDays(uint32_t time);
uint32_t uClockClass::getNowTimer();
pull/7/head
midilab 7 years ago
parent 81b189186d
commit 7ba44d1c05
  1. 32
      src/uClock.cpp
  2. 14
      src/uClock.h

@ -87,6 +87,8 @@ static uint32_t phase_mult(uint32_t val)
void uClockClass::start() void uClockClass::start()
{ {
start_timer = millis();
if (mode == INTERNAL_CLOCK) { if (mode == INTERNAL_CLOCK) {
state = STARTED; state = STARTED;
mod6_counter = 0; mod6_counter = 0;
@ -287,17 +289,47 @@ void uClockClass::handleTimerInt()
} }
// elapsed time support
uint8_t uClockClass::getNumberOfSeconds(uint32_t time)
{
return ((millis() - time) / 1000) % SECS_PER_MIN;
}
uint8_t uClockClass::getNumberOfMinutes(uint32_t time)
{
return (((millis() - time) / 1000) / SECS_PER_MIN) % SECS_PER_MIN;
}
uint8_t uClockClass::getNumberOfHours(uint32_t time)
{
return (((millis() - time) / 1000) % SECS_PER_DAY) / SECS_PER_HOUR;
}
uint8_t uClockClass::getNumberOfDays(uint32_t time)
{
return ((millis() - time) / 1000) / SECS_PER_DAY;
}
uint32_t uClockClass::getNowTimer()
{
return _timer;
}
} } // end namespace umodular::clock } } // end namespace umodular::clock
umodular::clock::uClockClass uClock; umodular::clock::uClockClass uClock;
volatile uint16_t _clock = 0; volatile uint16_t _clock = 0;
volatile uint32_t _timer = 0;
// //
// TIMER1 HANDLER INTERRUPT // TIMER1 HANDLER INTERRUPT
// //
ISR(TIMER1_OVF_vect) ISR(TIMER1_OVF_vect)
{ {
// global timer counter
_timer = millis();
if (uClock.state == uClock.STARTED) { if (uClock.state == uClock.STARTED) {
_clock++; _clock++;
uClock.handleTimerInt(); uClock.handleTimerInt();

@ -33,6 +33,10 @@
#include <Arduino.h> #include <Arduino.h>
#include <inttypes.h> #include <inttypes.h>
#define SECS_PER_MIN (60UL)
#define SECS_PER_HOUR (3600UL)
#define SECS_PER_DAY (SECS_PER_HOUR * 24L)
namespace umodular { namespace clock { namespace umodular { namespace clock {
class uClockClass { class uClockClass {
@ -57,6 +61,7 @@ class uClockClass {
uint32_t indiv96th_counter; uint32_t indiv96th_counter;
uint16_t pll_x; uint16_t pll_x;
uint16_t tempo; uint16_t tempo;
uint32_t start_timer;
enum { enum {
PAUSED = 0, PAUSED = 0,
@ -108,6 +113,14 @@ class uClockClass {
void shuffle(); void shuffle();
void tap(); void tap();
// elapsed time support
uint8_t getNumberOfSeconds(uint32_t time);
uint8_t getNumberOfMinutes(uint32_t time);
uint8_t getNumberOfHours(uint32_t time);
uint8_t getNumberOfDays(uint32_t time);
uint32_t uClockClass::getNowTimer();
}; };
} } // end namespace umodular::clock } } // end namespace umodular::clock
@ -116,6 +129,7 @@ extern umodular::clock::uClockClass uClock;
extern "C" { extern "C" {
extern volatile uint16_t _clock; extern volatile uint16_t _clock;
extern volatile uint32_t _timer;
} }
#endif /* __U_CLOCK_H__ */ #endif /* __U_CLOCK_H__ */

Loading…
Cancel
Save