/**
* @file gpioPin.c
*
* This is sample Legato CF3 GPIO app by using le_gpio.api.
*
*
*
* Copyright (C) Sierra Wireless, Inc. Use of this work is subject to license.
*/
/* Legato Framework */
#include "legato.h"
#include "interfaces.h"
static int Pin38 = 38;
static void Pin38ChangeCallback(bool state, void *ctx){
LE_INFO("State change %s", state?"TRUE":"FALSE");
LE_INFO("Context pointer came back as %d", *(int *)ctx);
}
//-------------------------------------------------------------------------------------------------
/**
* Pin-per-service GPIO pin38 as example
*/
// -------------------------------------------------------------------------------------------------
static void Pin38GpioSignal()
{
bool value = false;
le_gpioPin38_SetInput(LE_GPIOPIN38_ACTIVE_HIGH);
value = le_gpioPin38_Read();
LE_INFO("Pin38 read active: %d", value);
le_gpioPin38_AddChangeEventHandler(LE_GPIOPIN38_EDGE_RISING, Pin38ChangeCallback, &Pin38, 0);
// Change the edge setting
le_gpioPin38_SetEdgeSense(LE_GPIOPIN38_EDGE_BOTH);
le_gpioPin38_DisableEdgeSense();
le_gpioPin38_SetEdgeSense(LE_GPIOPIN38_EDGE_BOTH);
// Remove the handler
//le_gpioPin38_RemoveChangeEventHandler(ref);
}
static void PinsReadConfig()
{
le_gpioPin38_Edge_t edge = le_gpioPin38_GetEdgeSense();
if (edge == LE_GPIOPIN38_EDGE_FALLING)
{
LE_INFO("Pin 38 edge sense = falling");
}
else if (edge == LE_GPIOPIN38_EDGE_RISING)
{
LE_INFO("Pin 38 edge sense = rising");
}
else if (edge == LE_GPIOPIN38_EDGE_BOTH)
{
LE_INFO("Pin 38 edge sense = both");
}
else if (edge == LE_GPIOPIN38_EDGE_NONE)
{
LE_INFO("Pin 38 edge sense = none");
}
LE_INFO("Pin 38 is output = %s", le_gpioPin38_IsOutput()?"true":"false");
le_gpioPin38_PullUpDown_t pud = le_gpioPin38_GetPullUpDown();
if (pud == LE_GPIOPIN38_PULL_DOWN)
{
LE_INFO("Pin 38 pull up/down = down");
}
else if (pud == LE_GPIOPIN38_PULL_UP)
{
LE_INFO("Pin 38 pull up/down = up");
}
else
{
LE_INFO("Pin 38 pull up/down = none");
}
}
COMPONENT_INIT
{
LE_INFO("This is sample gpioctl Legato CF3 GPIO app by using le_gpio.api\n");
Pin38GpioSignal();
PinsReadConfig();
}