Skip to content

Commit 7ba153f

Browse files
committed
Timers: install timer
1 parent 9d8b0fc commit 7ba153f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

hardware/zpuino/zpu20/cores/zpuino/Timer.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,14 @@ namespace ZPUino {
109109

110110
m_intrTimerPtr = tmr;
111111

112-
return attachInterrupt(tmr->getInterruptLine(), &timerInterruptHandlerSS, (void*)this);
112+
if (attachInterrupt(tmr->getInterruptLine(), &timerInterruptHandlerSS, (void*)this))
113+
return -1;
114+
if (tmr->setPeriodMilliseconds(msec)<0) {
115+
detachInterrupt(tmr->getInterruptLine());
116+
return -1;
117+
}
118+
return 0;
119+
113120
}
114121

115122
int Timers_class::singleShot( int msec, void (*function)(void))
@@ -126,7 +133,13 @@ namespace ZPUino {
126133

127134
m_intrTimerPtr = tmr;
128135

129-
return attachInterrupt(tmr->getInterruptLine(), &timerInterruptHandler, (void*)this);
136+
if (attachInterrupt(tmr->getInterruptLine(), &timerInterruptHandler, (void*)this)<0)
137+
return -1;
138+
if (tmr->setPeriodMilliseconds(msec)<0) {
139+
detachInterrupt(tmr->getInterruptLine());
140+
return -1;
141+
}
142+
return 0;
130143
}
131144

132145
int Timers_class::periodic( int msec, bool (*function)(void) )

0 commit comments

Comments
 (0)