-
-
Save ataffanel/33965c74119d3d2d33f2 to your computer and use it in GitHub Desktop.
Crazyflie 2.0 Expansion board driver prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdbool.h> | |
#include <gpio.h> | |
#include <exp.h> | |
#define RED EXP_IO1 | |
#define ORANGE EXP_IO2 | |
#define GREEN EXP_IO3 | |
static bool isInit = false; | |
static void traficLightInit() | |
{ | |
gpioInit(RED, GPIO_OUTPUT, GPIO_SLOW); | |
gpioInit(ORANGE, GPIO_OUTPUT, GPIO_SLOW); | |
gpioInit(GREEN, GPIO_OUTPUT, GPIO_SLOW); | |
isInit = true; | |
} | |
static struct expDefine_s { | |
.init = traficLightInit, | |
.type = "cftlh", //Type written in the OW memory | |
.uses = [RED, ORANGE, GREEN, NULL], //List of pins or peripheral used | |
} traficlightExp; | |
EXP_REGISTER(traficlightExp); | |
static int state; | |
static void traficlightVariableUpdated(void* variable) | |
{ | |
if (state > 3) { | |
return; | |
} | |
if (state == 0) { | |
gpioSet(RED, 0); | |
gpioSet(ORANGE, 0); | |
gpioSet(GREEN, 0); | |
} else if (state == 1) { | |
gpioSet(RED, 1); | |
gpioSet(ORANGE, 0); | |
gpioSet(GREEN, 0); | |
} else if (state == 2) { | |
gpioSet(RED, 0); | |
gpioSet(ORANGE, 1); | |
gpioSet(GREEN, 0); | |
} else if (state == 3) { | |
gpioSet(RED, 0); | |
gpioSet(ORANGE, 0); | |
gpioSet(GREEN, 1); | |
} | |
} | |
PARAM_GROUP_START_EN(E_traficlight, isInit) //The callbacks are enabled by isInit | |
PARAM_ADD(PARAM_UINT8 | PARAM_RO, present, &isInit) | |
PARAM_ADD_CB(PARAM_UINT8, state, &state, traficlightVariableUpdated) //Callback when the value is written | |
PARAM_GROUP_END(E_traficlight) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment