mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Change C++ Notifier to allow std::function callback.
Also provide templated varags constructor for backwards compatibility and ease of use. Update PIDController to use new constructor, eliminating static function CallCalculate(). Change-Id: Iaeae95aa5953f294f5debc5fc569ef6d4684f223
This commit is contained in:
@@ -16,11 +16,10 @@
|
||||
* @param handler The handler is called at the notification time which is set
|
||||
* using StartSingle or StartPeriodic.
|
||||
*/
|
||||
Notifier::Notifier(TimerEventHandler handler, void *param) {
|
||||
Notifier::Notifier(TimerEventHandler handler) {
|
||||
if (handler == nullptr)
|
||||
wpi_setWPIErrorWithContext(NullParameter, "handler must not be nullptr");
|
||||
m_handler = handler;
|
||||
m_param = param;
|
||||
int32_t status = 0;
|
||||
m_notifier = initializeNotifier(&Notifier::Notify, this, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
@@ -62,12 +61,11 @@ void Notifier::Notify(uint32_t currentTimeInt, void *param) {
|
||||
}
|
||||
|
||||
auto handler = notifier->m_handler;
|
||||
auto hparam = notifier->m_param;
|
||||
|
||||
notifier->m_handlerMutex.lock();
|
||||
notifier->m_processMutex.unlock();
|
||||
|
||||
if (handler) handler(hparam);
|
||||
if (handler) handler();
|
||||
notifier->m_handlerMutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user