// ----------------------------------------------------------------------------- // cbSensorPacketReceived (callback) // xPacketType - the type of packet received: BIND_REQUEST or fixed/variable data packets // DeviceID - id of the device the data was send from // ucUserDataCount - amount of bytes / user data payload stored in pucBuffer // pucBuffer - pointer to the transmitted data bytes. Only ucUserDataCount bytes are ucValid // void cbSensorPacketReceived (PACKET_TYPES xPacketType, uint16_t usDeviceId, uint8_t ucUserDataCount, volatile uint8_t * pucBuffer) { uint8_t lastPacket; // a data paket from the sensor was received. Place your own code if (ucUserDataCount > 1) { if (*pucBuffer == 1) { // this packet triggers the LED toggle vLedToggle (LED_RX); lastPacket = pucBuffer[1]; // remember the packet number } else { vLedToggle (LED_TX); } } // set the backchannel data if there's storage free if (rfIsBackchannelFree (usDeviceId)) { // set the LED of the >ucValue< usDeviceId. All others are unset // The beacon time is set to 2 fo faster reaction time. // The packet number is retransmitted as an example. rfSetBackchannelData (usDeviceId, usDeviceId == ucValue, 2, &lastPacket, 1); ucValid[usDeviceId] = 1; // this Sensor is active & valid } }
// ----------------------------------------------------------------------------- // vSensorPacketReceived (callback) // xPacketType - Type de paquet reçu: BIND_REQUEST or fixed/variable data packets // usDeviceId - Identifiant du capteur qui a envoyé le paquet // ucUserDataCount - nombre d'octets de payload stockés dans pucBuffer // pucData - Pointeur sur les données transmises. Seuls les ucUserDataCount octets sont valides. // void vSensorPacketReceived (PACKET_TYPES xPacketType, uint16_t usDeviceId, uint8_t ucUserDataCount, volatile uint8_t * pucData) { // Un paquet a été reçu venant d'un capteur: Placez votre code ici. static uint8_t ucPacketCount; vLedToggle (LED_LED1); if (ucUserDataCount == 5) { if (pucData[4] != 0) { // this packet triggers the LED toggle vLedToggle (LED_LED2); } } ucPacketCount++; if (ucFlags & PRINT_FLAG) { printf_P (PSTR("%03d> S%d-"), ucPacketCount, xPacketType); switch (xPacketType) { case BIND_REQUEST_PACKET: // 0x00 puts_P (PSTR("BIND_REQUEST\n")); break; case FIXED_DATA_PACKET: // 0x04: Data packet of fixed length as defined by SIZE_OF_FIXED_DATA_PACKET // no break case VARIABLE_DATA_PACKET: // 0x05: Data packet of variable length printf_P (PSTR("ID%d <"), usDeviceId); // copy payload to the buffer for later, time intensive processing for (uint8_t n = 0; n < ucUserDataCount; n ++) { ucData[n] = *pucData++; } ucDataLen = ucUserDataCount; break; default: break; } } // set the backchannel data if there's storage free if (rfIsBackchannelFree (usDeviceId)) { rfSetBackchannelData (usDeviceId, 1, usBeaconTime, &ucPacketCount, 1); } }
/* internal public functions ================================================ */ int main (void) { eWNetErrorCode eError; vLedInit (); prvvDbgInit (); vAssert (iWNetTestSetup () == 0); (void) xWNetSetChannel (WNET_BIND_CHANNEL); (void) xWNetSetPnCode (WNET_BIND_PNCODE); vWNetSetCrcSeed (WPKT_BIND_CRC_SEED); vWNetSetChecksumSeed (WPKT_BIND_CHECKSUM_SEED); do { eError = eWNetTestSensorBind (10, 100, &xTestResult); prvvPrintResult (&xTestResult); } while (eError < 0); for (;;) { eError = eWNetTestSensorPing (1000, 10, &xTestResult); prvvPrintResult (&xTestResult); vLedToggle (TEST_LED); } return 0; }
/* ----------------------------------------------------------------------------- * Test de debug * Envoi d'un U */ void vTestDebug (void) { #ifdef TEST_DEBUG char cChar = 0x55; vSerialSwPutChar (cChar); vLedToggle (LED_LED1); #endif }
/* main ===================================================================== */ int main (void) { uint16_t usAdc; // pour valeur ADC double dValue; // pour la valeur de l'humidité xAdcSensor xSensor; /* * Repère d'étalonnage utilisé pour le test * * Le capteur est un modèle HIH4030 de Honeywell. Il est connecté à la * broche ADC0. C'est un capteur linéaire. * Le datasheet nous donne les valeurs de tension en sortie: * V1 = Vout(0%) = 958mV * V2 = Vout(75.3%) = 3268mV * comme Vref=5V, le quantum de l'ADC vaut LSB=5/1024=4.88mV donc : * V1 = Vout(0%) = 958mV et ADC = 196 LSB * V2 = Vout(75.3%) = 3268mV et ADC = 670 LSB * Ce qui donne le repère xSetting = (0, 75.3, 196, 670) */ xAdcSensorSetting xSetting = ADC_SENSOR_SETTING_LINEAR(0, 75.3, 196, 670); // Configuration du port série par défaut (8N1, sans RTS/CTS) xSerialIos settings = SERIAL_SETTINGS (BAUDRATE); // Ouverture du port série en sortie FILE * serial_port = xFileOpen (PORT, O_WRONLY, &settings); stdout = serial_port; // le port série est la sortie standard vLedInit(); // la LED1 est basculée à mesure vAdcInit(); // Init de l'ADC vAdcSetRef (eAdcVcc); // Tension de référence AVcc (5V pour Arduino UNO) /* * Le capteur est branché sur la voie 0 (ADC0) * Moyennage sur 32 mesures */ vAdcSensorInit (&xSensor, &xSetting, ADC_SENSOR_LINEAR, 0, 32); printf ("ADC0,Humidite\n"); for (;;) { /* * Lecture de la valeur brute en sortie de l'ADC : * Si on n'a pas besoin de usAdc, on peut utiliser dAdcSensorGetValue() * à la place de usAdcSensorGetRaw() et dAdcSensorRawToValue() */ usAdc = usAdcSensorGetRaw (&xSensor); // Conversion de la valeur brute en grandeur mesurée. dValue = dAdcSensorRawToValue (&xSensor, usAdc); // Affichage des valeurs printf ("%u,%.02f\n", usAdc, dValue); vLedToggle (LED_LED1); // Bascule LED1 après chaque mesure delay_ms (500); } return 0; }
/* main ===================================================================== */ int main (void) { eTwiStatus eError; uint8_t ucWaitTime = 10; // Temps d'attente en secondes vLedInit (); vSerialInit (TEST_BAUDRATE / 100, SERIAL_DEFAULT + SERIAL_RW); stdout = &xSerialPort; stdin = &xSerialPort; printf_P (PSTR("\n\nTest unitaire RTC DS1339\n")); vTwiInit (); eError = eTwiSetSpeed (100); vAssert (eError == TWI_SUCCESS); vAssert (iRtcInit (TEST_DS1339) == 0); printf_P(PSTR("Date courante: ")); prvvPrintRtc(); printf_P(PSTR("Modification Date ? (y/n) ")); while (ucWaitTime--) { uint8_t ucCount = 10; while ((ucCount--) && (usSerialHit() == 0)) { // Boucle en attente appui d'une touche delay_ms(100); } if (usSerialHit() != 0) { char cKey; cKey = getchar(); if ((cKey == 'y') || (cKey == 'Y')) { prvvSetRtc(); } break; } putchar('.'); } putchar('\n'); for (;;) { if (usSerialHit() != 0) { (void) getchar(); // flush last char prvvSetRtc(); } prvvPrintRtc(); vLedToggle (LED_LED1); delay_ms (1000); } return 0; }
/* main ===================================================================== */ int main (void) { uint16_t usAdc; // pour valeur ADC double dValue; // pour la valeur de la pression xAdcSensor xSensor; /* * Repère d'étalonnage utilisé pour le test * * Le capteur est un modèle MPX4115AP de Freescale, sa tension de sortie est: * Vout = Vcc*(.009*P-.095) avec P pression en kPa * il s'agit bien d'un capteur linéaire. * Le capteur mesure entre 150 hPa (15 kPa) et 1150 hPa (115 kPa). * Pour Vcc=Vref=5V, le quantum de l'ADC vaut LSB=5/1024=4.88mV, ce qui donne: * Vout(15) = 200mV = 41 LSB * Vout(115) = 4700mV = 963 LSB * Ce qui donne le repère xSetting = (150, 1150, 41, 963) */ xAdcSensorSetting xSetting = ADC_SENSOR_SETTING_LINEAR(150, 1150, 41, 963); // Configuration du port série par défaut (8N1, sans RTS/CTS) xSerialIos settings = SERIAL_SETTINGS (BAUDRATE); // Ouverture du port série en sortie FILE * serial_port = xFileOpen (PORT, O_WRONLY, &settings); stdout = serial_port; // le port série est la sortie standard vLedInit(); // la LED1 est basculée à mesure vAdcInit(); // Init de l'ADC vAdcSetRef (eAdcVcc); // Tension de référence AVcc (5V pour Arduino UNO) /* * Capteur branché sur la voie 0 (ADC0) * Moyennage sur 32 mesures */ vAdcSensorInit (&xSensor, &xSetting, ADC_SENSOR_LINEAR, 0, 32); printf ("ADC0,Pression\n"); for (;;) { /* * Lecture de la valeur brute en sortie de l'ADC : * Si on n'a pas besoin de usAdc, on peut utiliser dAdcSensorGetValue() * à la place de usAdcSensorGetRaw() et dAdcSensorRawToValue() */ usAdc = usAdcSensorGetRaw (&xSensor); // Conversion de la valeur brute en grandeur mesurée. dValue = dAdcSensorRawToValue (&xSensor, usAdc); // Affichage des valeurs printf ("%u,%.02f\n", usAdc, dValue); vLedToggle (LED_LED1); // Bascule LED1 après chaque mesure delay_ms (500); } return 0; }
void cdc_setup(void) { vLedToggle(); unsigned char *packet; size_t reply_len; packet = bdp->BDADDR; switch (packet[USB_bmRequestType] & (USB_bmRequestType_TypeMask | USB_bmRequestType_RecipientMask)) { case (USB_bmRequestType_Class | USB_bmRequestType_Interface): switch (packet[USB_bRequest]) { //JTR This is just a dummy, nothing defined to do for CDC ACM case CDC_SEND_ENCAPSULATED_COMMAND: // usb_ack_dat1(rbdp, 0); break; //JTR This is just a dummy, nothing defined to do for CDC ACM case CDC_GET_ENCAPSULATED_RESPONSE: usb_ack_dat1(rbdp, 0); break; case CDC_SET_COMM_FEATURE: // Optional case CDC_GET_COMM_FEATURE: // Optional case CDC_CLEAR_COMM_FEATURE: // Optional usb_RequestError(); // Not advertised in ACM functional descriptor break; case CDC_SET_LINE_CODING: // Optional, strongly recomended usb_set_out_handler(0, cdc_set_line_coding_data); // Register out handler function break; case CDC_GET_LINE_CODING: // Optional, strongly recomended reply_len = *((unsigned int *) &packet[USB_wLength]); if (sizeof (struct cdc_LineCodeing) < reply_len) { reply_len = sizeof (struct cdc_LineCodeing); } memcpy(rbdp->BDADDR, (const void *) &linecodeing, reply_len); usb_ack_dat1(rbdp, reply_len); // JTR common addition for STD and CLASS ACK //usb_set_in_handler(0, cdc_get_line_coding); // JTR why bother? There is nothing more to do. break; case CDC_SET_CONTROL_LINE_STATE: // Optional cls = *((struct _cdc_ControlLineState *) &packet[USB_wValue]); usb_set_in_handler(0, cdc_set_control_line_state_status); // JTR why bother? usb_ack_dat1(rbdp, 0); // JTR common addition for STD and CLASS ACK break; case CDC_SEND_BREAK: // Optional default: usb_RequestError(); } break; default: usb_RequestError(); } }
/* * Fonction exécutée sous interruption */ static void vTaskLed (xTaskHandle xTaskLed) { if (xLedEnabled) { vLedToggle (LED_LED1); /* bascule l'état de la LED */ } else { vLedClear (LED_LED1); /* éteint la LED */ } vTaskStart (xTaskLed); /* redémarre le compteur pour 50 ms */ }
/* * LEd Task, Performed under interrupt */ static void vTaskLed (xTaskHandle xTaskLed) { if (bTaskEnabled) { vLedToggle (LED_LED1); /* Toggle the status of the LED */ } else { vLedClear (LED_LED1); /* LED off */ } vTaskStart (xTaskLed); /* restart the countdown for 50 ms */ }
/* ----------------------------------------------------------------------------- * Test Pong * Boucle infinie d'attente d'un caractère puis renvoi */ void vTestPong (void) { #ifdef TEST_PONG static int c; for (;;) { c = iSerialSwGetChar (); if (c != _FDEV_EOF) { vSerialSwPutChar (c); vLedToggle (LED_LED1); } } #endif }
/* main ===================================================================== */ int main (void) { uint16_t usAdc; // pour valeur ADC char sep = ','; // caractère de séparation entre valeurs // Configuration du port série par défaut (8N1, sans RTS/CTS) xSerialIos settings = SERIAL_SETTINGS (BAUDRATE); // Ouverture du port série en sortie FILE * serial_port = xFileOpen (PORT, O_WRONLY, &settings); stdout = serial_port; // le port série est la sortie standard vLedInit(); // la LED1 est basculée à série de mesures vAdcInit(); // Init de l'ADC vAdcSetRef (eAdcInternal); // Tension de référence interne (1.1V pour Arduino UNO) // Affiche la ligne d'entête: ADC0,ADC1,... for (int i = 0; i < ADC_CHAN_QUANTITY; i++) { if (i == (ADC_CHAN_QUANTITY - 1)) { // saut de ligne après dernière étiquette sep = '\n'; } printf ("ADC%u%c", i, sep); } for (;;) { sep = ','; // Affiche les valeurs ADC for (int i = 0; i < ADC_CHAN_QUANTITY; i++) { usAdc = usAdcReadAverage (i, 8); // lecture avec moyennage sur 8 valeurs if (i == (ADC_CHAN_QUANTITY - 1)) { // saut de ligne après dernière valeur sep = '\n'; } printf ("%u%c", usAdc, sep); } vLedToggle (LED_LED1); // Bascule LED1 après chaque série de mesure delay_ms (1000); } return 0; }
/* main ===================================================================== */ int main (void) { vLedInit (); // Votre code d'initialisation devrait être ici // Your initialization code should be here for (;;) { // Your main code should be here, // you can delete the two lines below // Votre code principal devrait être ici, // Vous pouvrez supprimer les deux lignes ci-dessous vLedToggle (LED_LED1); delay_ms (1000); } return 0; }
/* ----------------------------------------------------------------------------- * Test Pong, version avec les fonctions stdio getc et putc * Boucle infinie d'attente d'un caractère puis renvoi */ void vTestPongStdIo (void) { #ifdef TEST_PONG_STDIO static int c; for (;;) { c = getc (&xSerialSwPort); vLedAssert (ferror (&xSerialSwPort) == 0); if ( (c != EOF) && (feof (&xSerialSwPort) == 0)) { putc (c, &xSerialSwPort); vLedAssert (ferror (&xSerialSwPort) == 0); vLedToggle (LED_LED1); } } #endif }
/* internal public functions ================================================ */ int main (void) { vLedInit(); for (;;) { vWIfcInit (); GetMid (ucMid); GetPnCode (ucPnCode); vAssert (memcmp_P (ucPnCode, ucPnCodeDef_P, sizeof(ucPnCodeDef_P)) == 0); SetPnCode_P (ucPnCode_P); GetPnCode (ucPnCode); vAssert (memcmp_P (ucPnCode, ucPnCode_P, sizeof(ucPnCode_P)) == 0); SetPnCode (ucPnCode); vLedToggle (LED_LED1); delay_ms (500); } return 0; }
/* main ===================================================================== */ int main (void) { int iError; xHscSensor xSensor; xHscRaw xRaw; xHscValue xValue; vLedInit(); // Configuration du port série par défaut (8N1, sans RTS/CTS) xSerialIos settings = SERIAL_SETTINGS (BAUDRATE); // Ouverture du port série en sortie FILE * serial_port = xFileOpen (PORT, O_WRONLY, &settings); stdout = serial_port; // le port série est la sortie standard stderr = serial_port; sei(); printf ("\nTest unitaire HSC I2C\n"); vTwiInit (); iError = eTwiSetSpeed (100); assert (iError == 0); iError = iHscInitTwiSensor (&xSensor, 0, 1600, HSC_DEFAULT_TWIADDR); assert (iError == 0); for (;;) { iError = iHscGetRaw (&xSensor, &xRaw); if (iError) { printf ("Sensor Error: %d\n", iError); } else { vHscRawToValue (&xSensor, &xRaw, &xValue); printf ("Press %.02f Temp %.02f\n", xValue.dPress, xValue.dTemp); } vLedToggle (LED_LED1); delay_ms (500); } return 0; }
/* ----------------------------------------------------------------------------- * Test Stdio * Attente d'un caractère puis renvoi */ void vTestStdio (void) { #ifdef TEST_STDIO int xChar; puts_P (PSTR ("\nTest5 Stdio\n-\tprintf()\n")); for (xChar = 0; xChar < 8; xChar++) { printf_P (PSTR ("\tStatus 0x%02X\r"), xChar); } puts_P (PSTR ("-\tgetchar(): Tapez quelque chose au clavier (ENTER pour quitter)\n")); do { xChar = getchar (); putchar (xChar); vLedToggle (LED_LED1); } while (xChar != '\r'); /* Return pour terminer */ putchar ('\n'); #endif }
/* main ===================================================================== */ int main (void) { uint16_t usPulse = DEFAULT_PULSE; vLedInit (); vButInit (); vServoInit (); // Toutes les voies sont validées // Règlage des largeurs d'impulsion par défaut vLedSet (LED_LED1); for (uint8_t ucServo = 0; ucServo < ucServoChannels(); ucServo++) { vServoSetPulse (ucServo, DEFAULT_PULSE); } for (;;) { if (xButGet (BUTTON_BUTTON1)) { // BP1 appuyé while (xButGet (BUTTON_BUTTON1)) ; // Attente relâchement BP1 usPulse += STEP_PULSE; // Augmente la largeur d'un pas // Si la largeur est trop grande, on revient au min if (usPulse > MAX_PULSE) { usPulse = MIN_PULSE; } // On envoie le nouveau réglage aux servos for (uint8_t ucServo = 0; ucServo < ucServoChannels(); ucServo++) { vServoSetPulse (ucServo, usPulse); } // On bascule l'état de la LED1 vLedToggle (LED_LED1); } } return 0; }
/* internal public functions ================================================ */ int main(void) { int i; vLedInit (); // Configuration du port série par défaut (8N1, sans RTS/CTS) xSerialIos settings = SERIAL_SETTINGS (BAUDRATE); // Ouverture du port série en entrée et en sortie FILE * serial_port = xFileOpen (PORT, O_RDWR | O_NONBLOCK, &settings); vTncInit (&tnc, serial_port, serial_port); sei(); for (i = 0; i < TNC_RXBUFSIZE; i++) msg[i] = i; xScheduler = xTaskCreate (xTaskConvertMs (TRANSMIT_PERIOD), vScheduler); vTaskStart (xScheduler); for (;;) { i = iTncPoll (&tnc); vAssert (i >= 0); if (i == TNC_EOT) { for (i = 0; i < tnc.len; i++) vAssert (tnc.rxbuf[i] == i); vLedToggle (LED_LED1); } if (xMutexTryLock(&xMutexTx) == 0) { i = iTncWrite (&tnc, msg, sizeof(msg)); vAssert (i == sizeof(msg)); } } return 0; }
/* internal public functions ================================================ */ int main (void) { uint8_t ucBit; vLedInit (); vButInit (); for (;;) { for (ucBit = 0; ucBit < BUTTON_QUANTITY; ucBit++) { if (xButGet (xButGetMask (ucBit))) { uint8_t ucCount = (ucBit + 1) * 2; while (ucCount--) { // La LED clignote une fois pour le bouton 1, 2 fois pour le 2 .... vLedToggle (LED_LED1); delay_ms (200); } } } } return 0; }
/* main ===================================================================== */ int main (void) { eGifamMode eNewMode = ModeConfort; // Mode de départ eGifamMode eCurrentMode = ModeUnknown; int iTimeOut = 16; // Initialisation des fonctions vLedInit(); vButInit(); vTwiInit (); eTwiSetSpeed (400); // Attente de réponse du tiny45, nécessaire lors d'un démarrage de l'alim. while (iGifamInit () != 0) { if (iTimeOut-- <= 0) { vAssert (0); // bloque et fait clignoter la led 7 } delay_ms (100); } for (;;) { if (eNewMode != eCurrentMode) { while (eNewMode != eCurrentMode) { // Le nouveau mode est différent du courant vGifamSet (eNewMode); // modification du mode eCurrentMode = eGifamGet(); // lecture du mode if (eNewMode != eCurrentMode) { delay_ms (500); vLedToggle (LED_LED1); } } vLedClear (LED_LED1); } // Attente appui BP while (xButGet (BUTTON_BUTTON1) == 0) ; if ( (eNewMode == ModeEco) || (eNewMode == ModeConfortM1)) { // Remets le fil au repos afin de pouvoir mesurer la durée d'activation // des modes étendus vGifamSet (ModeConfort); // Attente appui BP delay_ms (250); while (xButGet (BUTTON_BUTTON1) == 0) { vLedToggle (LED_LED1); delay_ms (50); } } vLedClear (LED_LED1); delay_ms (250); // Passe au mode suivant if (eNewMode < ModeConfortM2) { eNewMode++; } else { eNewMode = ModeConfort; } } return 0; }
// ------------------------------------------------------------------------------ void vActLedToggle (void) { vLedToggle (LED_LED1); }
void vLed2Toggle(void) { vLedToggle(hardLED2_PORT,hardLED2_PIN); }
void vLed1Toggle(void) { vLedToggle(hardLED1_PORT,hardLED1_PIN); }