BigW Consortium Gitlab

Commit 14d55b21 by David Frey

Merge branch 'ashsyal-adc_gpio_tutorials'

parents 13758e3a 2b875853
sandboxed: true
version: 1.0.0
maxFileSystemBytes: 512K
start: manual
executables:
{
noiseData = ( noiseDataComponent )
}
processes:
{
envVars:
{
LE_LOG_LEVEL = DEBUG
}
run:
{
( noiseData )
}
faultAction: restart
}
bindings:
{
noiseData.noiseDataComponent.le_adc -> modemService.le_adc
}
requires:
{
api:
{
${LEGATO_ROOT}/interfaces/modemServices/le_adc.api
}
}
sources:
{
noiseData.c
}
//--------------------------------------------------------------------------------------------------
/**
* This app reads the current adc reading every 1 seconds
*/
//--------------------------------------------------------------------------------------------------
#include "legato.h"
#include "interfaces.h"
//--------------------------------------------------------------------------------------------------
/**
* The time between publishing ADC location readings
*
* @note Please change this timeout value as needed.
*/
//--------------------------------------------------------------------------------------------------
#define ADC_SAMPLE_INTERVAL_IN_MILLISECONDS (1000)
//--------------------------------------------------------------------------------------------------
/**
* Timer handler will publish the current ADC reading.
*/
//--------------------------------------------------------------------------------------------------
static void adcTimer
(
le_timer_Ref_t adcTimerRef
)
{
int32_t value;
const le_result_t result = le_adc_ReadValue("EXT_ADC1", &value);
if (result == LE_OK)
{
LE_INFO("EXT_ADC1 value is: %d", value);
}
else
{
LE_INFO("Couldn't get ADC value");
}
}
//--------------------------------------------------------------------------------------------------
/**
* Main program starts here
*/
//--------------------------------------------------------------------------------------------------
COMPONENT_INIT
{
LE_INFO("---------------------- ADC Reading started");
le_timer_Ref_t adcTimerRef = le_timer_Create("ADC Timer");
le_timer_SetMsInterval(adcTimerRef, ADC_SAMPLE_INTERVAL_IN_MILLISECONDS);
le_timer_SetRepeat(adcTimerRef, 0);
le_timer_SetHandler(adcTimerRef, adcTimer);
le_timer_Start(adcTimerRef);
}
sandboxed: true
version: 1.0.0
maxFileSystemBytes: 512K
start: manual
executables:
{
cf3GpioControl = ( cf3GpioControlComponent )
}
processes:
{
envVars:
{
LE_LOG_LEVEL = DEBUG
}
run:
{
( cf3GpioControl )
}
faultAction: restart
}
bindings:
{
cf3GpioControl.cf3GpioControlComponent.le_sensorGpio -> <root>.le_gpioPin25
cf3GpioControl.cf3GpioControlComponent.mangoh_ledGpio -> gpioExpanderService.mangoh_gpioExp1Pin5
}
requires:
{
api:
{
le_sensorGpio = ${LEGATO_ROOT}/interfaces/le_gpio.api
mangoh_ledGpio = ${LEGATO_ROOT}/interfaces/le_gpio.api
}
}
sources:
{
cf3GpioControl.c
}
//--------------------------------------------------------------------------------------------------
/**
* This sample app reads state of IoT1_GPIO1 (gpio25).
* If state change is detected, it makes corresponding change in state of LED D750.
* Use this sample to understand how to configure a gpio as an input or output
* and use call back function.
*/
//--------------------------------------------------------------------------------------------------
#include "legato.h"
#include "interfaces.h"
//--------------------------------------------------------------------------------------------------
/**
* Sets default configuration LED D750 as on
*/
//--------------------------------------------------------------------------------------------------
static void ConfigureLed
(
void
)
{
// Configure initial value as LED on
LE_FATAL_IF(mangoh_ledGpio_SetPushPullOutput(MANGOH_LEDGPIO_ACTIVE_HIGH, true) != LE_OK,
"Couldn't configure LED PLAY as a push pull output");
}
//--------------------------------------------------------------------------------------------------
/**
* Performs initial configuration of the CF3 gpio (IoT1_GPIO1)
*/
//--------------------------------------------------------------------------------------------------
static void ConfigureSensorGpio
(
void
)
{
// Configure IoT1_GPIO1 as input and set its initial value as high
LE_FATAL_IF(le_sensorGpio_SetInput(LE_SENSORGPIO_ACTIVE_HIGH ) != LE_OK,
"Couldn't configure cf3 gpio as default input high");
}
//--------------------------------------------------------------------------------------------------
/**
* LED D750 changes state when IoT1_GPIO1 changes state
*/
//--------------------------------------------------------------------------------------------------
static void touch_ledGpio_ChangeHandler
(
bool state, void *ctx
)
{
// set call back for change in state of GPIO
mangoh_ledGpio_SetEdgeSense(MANGOH_LEDGPIO_EDGE_BOTH);
if (state)
{
mangoh_ledGpio_Activate();
}
else
{
mangoh_ledGpio_Deactivate();
}
}
//--------------------------------------------------------------------------------------------------
/**
* Main program starts here
*/
//--------------------------------------------------------------------------------------------------
COMPONENT_INIT
{
LE_INFO("===============CF3 gpio application has started");
ConfigureLed();
ConfigureSensorGpio();
le_sensorGpio_AddChangeEventHandler(LE_SENSORGPIO_EDGE_BOTH,
touch_ledGpio_ChangeHandler,
NULL,
0);
}
sandboxed: true
version: 1.0.0
maxFileSystemBytes: 512K
start: manual
executables:
{
timerLed = ( timerLedComponent )
}
processes:
{
envVars:
{
LE_LOG_LEVEL = DEBUG
}
run:
{
( timerLed )
}
faultAction: restart
}
bindings:
{
timerLed.timerLedComponent.mangoh_ledGpio -> gpioExpanderService.mangoh_gpioExp1Pin5
}
requires:
{
api:
{
mangoh_ledGpio = ${LEGATO_ROOT}/interfaces/le_gpio.api
}
}
sources:
{
timerLed.c
}
//--------------------------------------------------------------------------------------------------
/*
* This sample app is a blinking LED at 1 second interval
*/
//--------------------------------------------------------------------------------------------------
#include "legato.h"
#include "interfaces.h"
#define LED_SAMPLE_INTERVAL_IN_MILLISECONDS (1000)
static int8_t state = 0;
//--------------------------------------------------------------------------------------------------
/**
* Sets default configuration LED D750 as on
*/
//--------------------------------------------------------------------------------------------------
static void ConfigureLed
(
void
)
{
// Configure initial value as LED off
LE_FATAL_IF(mangoh_ledGpio_SetPushPullOutput(MANGOH_LEDGPIO_ACTIVE_HIGH, true) != LE_OK,
"Couldn't configure LED PLAY as a push pull output");
}
//--------------------------------------------------------------------------------------------------
/**
* LED D750 changes state as defined by LED_SAMPLE_INTERVAL_IN_SECONDS
*/
//--------------------------------------------------------------------------------------------------
static void ledTimer
(
le_timer_Ref_t ledTimerRef
)
{
mangoh_ledGpio_SetEdgeSense(MANGOH_LEDGPIO_EDGE_BOTH);
if (state)
{
mangoh_ledGpio_Activate();
state = false;
}
else
{
mangoh_ledGpio_Deactivate();
state = true;
}
}
//--------------------------------------------------------------------------------------------------
/**
* Main program starts here
*/
//--------------------------------------------------------------------------------------------------
COMPONENT_INIT
{
LE_INFO("===============blinking LED application has started");
ConfigureLed();
le_timer_Ref_t ledTimerRef = le_timer_Create("LED Timer");
le_timer_SetMsInterval(ledTimerRef, LED_SAMPLE_INTERVAL_IN_MILLISECONDS);
le_timer_SetRepeat(ledTimerRef, 0);
le_timer_SetHandler(ledTimerRef,ledTimer);
le_timer_Start(ledTimerRef);
}
sandboxed: true
version: 1.0.0
maxFileSystemBytes: 512K
start: manual
executables:
{
touchData = ( touchDataComponent )
}
processes:
{
envVars:
{
LE_LOG_LEVEL = DEBUG
}
run:
{
( touchData )
}
faultAction: restart
}
bindings:
{
touchData.touchDataComponent.mangoh_pushButton -> gpioExpanderService.mangoh_gpioExp1Pin7
touchData.touchDataComponent.mangoh_ledGpio -> gpioExpanderService.mangoh_gpioExp1Pin5
}
requires:
{
api:
{
mangoh_ledGpio = ${LEGATO_ROOT}/interfaces/le_gpio.api
mangoh_pushButton = ${LEGATO_ROOT}/interfaces/le_gpio.api
}
}
sources:
{
touchData.c
}
//--------------------------------------------------------------------------------------------------
/**
* This sample app reads state of IoT1_GPIO1 (gpio25) or Push Button SW200
* If state change is detected, it makes corresponding change in state of LED D750
* Use this sample to understand how to configure a gpio as an input or output
* and use call back function
*/
//--------------------------------------------------------------------------------------------------
#include "legato.h"
#include "interfaces.h"
//--------------------------------------------------------------------------------------------------
/**
* Sets default configuration LED D750 as on
*/
//--------------------------------------------------------------------------------------------------
static void ConfigureLed
(
void
)
{
// Configure initial value as LED on
LE_FATAL_IF(mangoh_ledGpio_SetPushPullOutput(MANGOH_LEDGPIO_ACTIVE_HIGH, true) != LE_OK,
"Couldn't configure LED PLAY as a push pull output");
}
//--------------------------------------------------------------------------------------------------
/**
* Performs initial configuration of the push button (SW200)
*/
//--------------------------------------------------------------------------------------------------
static void ConfigurePushButton
(
void
)
{
// Configure Push Button as input and set its initial value as high
LE_FATAL_IF(mangoh_pushButton_SetInput(MANGOH_PUSHBUTTON_ACTIVE_HIGH ) != LE_OK,
"Couldn't configure touch sensor as default input high");
}
//--------------------------------------------------------------------------------------------------
/**
* LED D750 changes state when Push Button changes state
*/
//--------------------------------------------------------------------------------------------------
static void touch_ledGpio_ChangeHandler
(
bool state, void *ctx
)
{
// set call back for change in state of GPIO
mangoh_ledGpio_SetEdgeSense(MANGOH_LEDGPIO_EDGE_BOTH);
if (state)
{
mangoh_ledGpio_Activate();
}
else
{
mangoh_ledGpio_Deactivate();
}
}
//--------------------------------------------------------------------------------------------------
/**
* Main program starts here
*/
//--------------------------------------------------------------------------------------------------
COMPONENT_INIT
{
LE_INFO("===============touchsensor application has started");
ConfigureLed();
ConfigurePushButton();
mangoh_pushButton_AddChangeEventHandler(MANGOH_PUSHBUTTON_EDGE_BOTH,
touch_ledGpio_ChangeHandler,
NULL,
0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment