Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work on GPIO events #657

Merged
merged 1 commit into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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