Skip to content

Commit

Permalink
Add code to post managed events only if there are callbacks registered (
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Aug 27, 2018
1 parent e39705b commit d9810aa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,15 @@ static void debounceTimer_Callback( void* arg )
if(lastPadValue == currentValue)
{
// value hasn't change for debounce interval so this is a valid change
// post a managed event with the current pin value
PostManagedEvent( EVENT_GPIO, 0, pinNumber, currentValue );

// flag to determine if there are any callbacks registered in managed code
bool callbacksRegistered = (pThis[ Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___callbacks ].Dereference() != NULL);

// post a managed event with the current pin value, only if there is anyone listening otherwise don't bother
if(callbacksRegistered)
{
PostManagedEvent( EVENT_GPIO, 0, pinNumber, currentValue );
}
}
}

Expand Down Expand Up @@ -156,8 +163,14 @@ static void GpioEventCallback(void *arg)
// read pad
pThis[ Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___lastInputValue ].NumericByRef().s4 = palReadLine(ioLine);

// post a managed event with the current pin reading
PostManagedEvent( EVENT_GPIO, 0, pinNumber, palReadLine(ioLine) );
// flag to determine if there are any callbacks registered in managed code
bool callbacksRegistered = (pThis[ Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___callbacks ].Dereference() != NULL);

// post a managed event with the current pin reading, only if there is anyone listening otherwise don't bother
if(callbacksRegistered)
{
PostManagedEvent( EVENT_GPIO, 0, pinNumber, palReadLine(ioLine) );
}
}

chSysUnlockFromISR();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,11 @@ static void RxChar(UARTDriver *uartp, uint16_t c)
else
{
// no read operation ongoing, so fire an event

// post a managed event with the port index and event code (check if this is the watch char or just another another)
// TODO: check if callbacks are registered so this is called only if there is anyone listening otherwise don't bother
// for that to happen ChibiOS callback has to accept arg which we would passing the GpioPin CLR_RT_HeapBlock (see Gpio handler)
// check http://www.chibios.com/forum/viewtopic.php?f=36&t=4798
PostManagedEvent( EVENT_SERIAL, 0, portIndex, (c == palUart->WatchChar) ? SerialData_WatchChar : SerialData_Chars );
}

Expand Down

0 comments on commit d9810aa

Please sign in to comment.