Skip to content

Commit

Permalink
Work on GPIO events (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Apr 2, 2018
1 parent e27c2e5 commit b1b2445
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin
static const int FIELD___debounceTimeout = 4;
static const int FIELD___callbacks = 5;
static const int FIELD___lastOutputValue = 6;
static const int FIELD___disposedValue = 7;
static const int FIELD___lastInputValue = 7;
static const int FIELD___disposedValue = 8;

NANOCLR_NATIVE_DECLARE(Read___WindowsDevicesGpioGpioPinValue);
NANOCLR_NATIVE_DECLARE(DisposeNative___VOID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ static void debounceTimer_Callback( void* arg )
// read line
uint16_t currentValue = palReadLine(GetIoLine(pinNumber));

// read pad
uint16_t lastPadValue = pThis[ Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___lastInputValue ].NumericByRef().s4;

if(lastPadValue == currentValue)
{
// value hasn't change for debounce interval so this is a valid change
Expand Down Expand Up @@ -127,7 +130,7 @@ static void GpioEventCallback(void *arg)

// check if there is a debounce time set
int64_t debounceTimeoutMilsec = (CLR_INT64_TEMP_CAST) pThis[ Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___debounceTimeout ].NumericByRefConst().s8 / TIME_CONVERSION__TO_MILLISECONDS;

if(debounceTimeoutMilsec > 0)
{
// debounce set, need to handle it
Expand All @@ -143,13 +146,16 @@ static void GpioEventCallback(void *arg)
}

// read pad
lastPadValue = palReadLine(ioLine);
pThis[ Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___lastInputValue ].NumericByRef().s4 = palReadLine(ioLine);

// setup timer
chVTSetI(&debounceTimer, TIME_MS2I(debounceTimeoutMilsec), debounceTimer_Callback, pThis);
}
else
{
// 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) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void PostManagedEvent(uint8_t category, uint8_t subCategory, uint16_t data1, uin
{
if(g_Context != NULL)
{
uint16_t d = ((uint16_t)data1 << 16) | (category << 8) | subCategory;
uint32_t d = ((uint32_t)data1 << 16) | (category << 8) | subCategory;

SaveNativeEventToHALQueue( g_Context, d, data2 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin
static const int FIELD___debounceTimeout = 4;
static const int FIELD___callbacks = 5;
static const int FIELD___lastOutputValue = 6;
static const int FIELD___disposedValue = 7;
static const int FIELD___lastInputValue = 7;
static const int FIELD___disposedValue = 8;

NANOCLR_NATIVE_DECLARE(Read___WindowsDevicesGpioGpioPinValue);
NANOCLR_NATIVE_DECLARE(DisposeNative___VOID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,3 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetAlter
}
NANOCLR_NOCLEANUP();
}




Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void PostManagedEvent(uint8_t category, uint8_t subCategory, uint16_t data1, uin
{
if(g_Context != NULL)
{
uint16_t d = ((uint16_t)data1 << 16) | (category << 8) | subCategory;
uint32_t d = ((uint32_t)data1 << 16) | (category << 8) | subCategory;

SaveNativeEventToHALQueue( g_Context, d, data2 );
}
Expand Down

0 comments on commit b1b2445

Please sign in to comment.