Exemple simple qui fait clignoter une LED à chaque réception d'un paquet et qui renvoit une réponse. Elle récupère l'état d'un bouton poussoir envoyé par chaque capteur et bascule l'état d'une uatre LED en fonction.
#include <avrio/led.h>
#include <avrio/button.h>
#include <avrio/serial.h>
#include <avrio/delay.h>
#define AVRIO_DEBUG_STREAM &xSerialPort
#include <avrio/debug.h>
#include <idwarf/hub.h>
#define LED_RX LED_LED1
#define LED_TX LED_LED2
#define BUTTON BUTTON_BUTTON1
#define DEBUG_BAUDRATE 115200
uint8_t ucValid[10];
uint8_t ucValue = 0;
#if defined(AVRIO_DEBUG_STREAM)
void
prvvDebugInit (void) {
}
#else
# define prvvDebugInit()
#endif
void cbSensorPacketReceived (
PACKET_TYPES, uint16_t, uint8_t,
volatile uint8_t *);
int
main (void) {
bool xOldButton = false;
prvvDebugInit();
vDbgPuts_P (PSTR("Testcode for the tutorial - hub style\r"));
for (;;) {
if (xOldButton == false) {
for (uint8_t n = 0; n < 10; n ++) {
vDbgPutDec (ucValid[n]);
vDbgPutc ('.');
}
vDbgPutc (' ');
for (ucValue++; ucValue < 10; ucValue++) {
if (ucValid[ucValue])
break;
}
if (ucValue == 10) {
for (ucValue = 0; ucValue < 10; ucValue++) {
if (ucValid[ucValue])
break;
}
}
if (ucValue == 10)
ucValue = 0;
vDbgPutDec (ucValue);
vDbgPutc (' ');
for (uint8_t n = 0; n < 10; n++) {
ucValid[n] = 0;
}
xOldButton = true;
}
}
else {
if (xOldButton == true)
xOldButton = false;
}
}
}
void cbSensorPacketReceived (
PACKET_TYPES xPacketType, uint16_t usDeviceId,
uint8_t ucUserDataCount, volatile uint8_t * pucBuffer) {
uint8_t lastPacket;
if (ucUserDataCount > 1) {
if (*pucBuffer == 1) {
lastPacket = pucBuffer[1];
}
else {
}
}
ucValid[usDeviceId] = 1;
}
}