Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: pixy2.cpp
- Revision:
- 10:ea759846c2d5
- Parent:
- 6:e9e3aa6f1a55
- Child:
- 11:68ef9f85e40e
--- a/pixy2.cpp Tue Mar 12 10:49:53 2019 +0000
+++ b/pixy2.cpp Tue Mar 12 14:06:53 2019 +0000
@@ -66,7 +66,7 @@
}
Pixy2ErrorCode PIXY2::pixy2_sndGetVersion (void){
- T_pixy2sendBuffer msg;
+ T_pixy2SendBuffer msg;
int i = 0, dataSize = 0;
msg.frame.header.pixSync = PIXY2_SYNC;
msg.frame.header.pixType = PIXY2_ASK_VERS;
@@ -80,7 +80,7 @@
}
Pixy2ErrorCode PIXY2::pixy2_sndGetResolution (void){
- T_pixy2sendBuffer msg;
+ T_pixy2SendBuffer msg;
int i = 0, dataSize = 1;
msg.frame.header.pixSync = PIXY2_SYNC;
msg.frame.header.pixType = PIXY2_ASK_RESOL;
@@ -95,7 +95,7 @@
}
Pixy2ErrorCode PIXY2::pixy2_sndSetCameraBrightness (Byte brightness){
- T_pixy2sendBuffer msg;
+ T_pixy2SendBuffer msg;
int i = 0, dataSize = 1;
msg.frame.header.pixSync = PIXY2_SYNC;
msg.frame.header.pixType = PIXY2_SET_BRIGHT;
@@ -110,7 +110,7 @@
}
Pixy2ErrorCode PIXY2::pixy2_sndSetServo (Word s0, Word s1){
- T_pixy2sendBuffer msg;
+ T_pixy2SendBuffer msg;
int i = 0, dataSize = 4;
T_Word tmp;
msg.frame.header.pixSync = PIXY2_SYNC;
@@ -131,7 +131,7 @@
}
Pixy2ErrorCode PIXY2::pixy2_sndSetLED (Byte red, Byte green, Byte blue){
- T_pixy2sendBuffer msg;
+ T_pixy2SendBuffer msg;
int i = 0, dataSize = 3;
msg.frame.header.pixSync = PIXY2_SYNC;
msg.frame.header.pixType = PIXY2_SET_LED;
@@ -148,7 +148,7 @@
}
Pixy2ErrorCode PIXY2::pixy2_sndSetLamp (Byte upper, Byte lower){
- T_pixy2sendBuffer msg;
+ T_pixy2SendBuffer msg;
int i = 0, dataSize = 2;
msg.frame.header.pixSync = PIXY2_SYNC;
msg.frame.header.pixType = PIXY2_SET_LED;
@@ -164,7 +164,7 @@
}
Pixy2ErrorCode PIXY2::pixy2_sndGetFPS (void){
- T_pixy2sendBuffer msg;
+ T_pixy2SendBuffer msg;
int i = 0, dataSize = 0;
msg.frame.header.pixSync = PIXY2_SYNC;
msg.frame.header.pixType = PIXY2_ASK_FPS;
@@ -178,7 +178,7 @@
}
Pixy2ErrorCode PIXY2::pixy2_sndGetBlocks (Byte sigmap, Byte maxBloc){
- T_pixy2sendBuffer msg;
+ T_pixy2SendBuffer msg;
int i = 0, dataSize = 2;
msg.frame.header.pixSync = PIXY2_SYNC;
msg.frame.header.pixType = PIXY2_ASK_BLOC;
@@ -194,7 +194,7 @@
}
Pixy2ErrorCode PIXY2::pixy2_sndGetMainFeature (Byte type, Byte feature){
- T_pixy2sendBuffer msg;
+ T_pixy2SendBuffer msg;
int i = 0, dataSize = 2;
msg.frame.header.pixSync = PIXY2_SYNC;
msg.frame.header.pixType = PIXY2_ASK_LINE;
@@ -210,7 +210,7 @@
}
Pixy2ErrorCode PIXY2::pixy2_sndSetMode (Byte mode){
- T_pixy2sendBuffer msg;
+ T_pixy2SendBuffer msg;
int i = 0, dataSize = 1;
msg.frame.header.pixSync = PIXY2_SYNC;
msg.frame.header.pixType = PIXY2_SET_MODE;
@@ -225,7 +225,7 @@
}
Pixy2ErrorCode PIXY2::pixy2_sndSetNexTurn (Word angle){
- T_pixy2sendBuffer msg;
+ T_pixy2SendBuffer msg;
int i = 0, dataSize = 2;
T_Word tmp;
tmp.mot = angle;
@@ -244,7 +244,7 @@
}
Pixy2ErrorCode PIXY2::pixy2_sndSetDefaultTurn (Word angle){
- T_pixy2sendBuffer msg;
+ T_pixy2SendBuffer msg;
int i = 0, dataSize = 2;
T_Word tmp;
tmp.mot = angle;
@@ -263,7 +263,7 @@
}
Pixy2ErrorCode PIXY2::pixy2_sndSetVector (Byte vectorIndex){
- T_pixy2sendBuffer msg;
+ T_pixy2SendBuffer msg;
int i = 0, dataSize = 1;
msg.frame.header.pixSync = PIXY2_SYNC;
msg.frame.header.pixType = PIXY2_SET_VECTOR;
@@ -278,7 +278,7 @@
}
Pixy2ErrorCode PIXY2::pixy2_sndReverseVector (void){
- T_pixy2sendBuffer msg;
+ T_pixy2SendBuffer msg;
int i = 0, dataSize = 0;
msg.frame.header.pixSync = PIXY2_SYNC;
msg.frame.header.pixType = PIXY2_SET_REVERSE;
@@ -292,7 +292,7 @@
}
Pixy2ErrorCode PIXY2::pixy2_sndGetRGB (Word x, Word y, Byte saturate){
- T_pixy2sendBuffer msg;
+ T_pixy2SendBuffer msg;
int i = 0, dataSize = 3;
msg.frame.header.pixSync = PIXY2_SYNC;
msg.frame.header.pixType = PIXY2_ASK_VIDEO;
@@ -314,7 +314,7 @@
Pixy2ErrorCode PIXY2::pixy2_getVersion (T_Pixy2Version *version){
T_pixy2RcvHeader *msg = (T_pixy2RcvHeader*) &Pixy2_buffer[rPointer];
- Pixy2ErrorCode cr = PIXY2_OK;
+ Pixy2ErrorCode cr = PIXY2_OK;
switch (etat) {
case idle : // Si la caméra est inactive
@@ -329,16 +329,26 @@
if ( pixy2_validateChecksum (&Pixy2_buffer[rPointer]) ) { // On lance la validation du checksum
if (msg->pixType == PIXY2_REP_VERS) { // On vérifie que la trame est du type convenable
version = (T_Pixy2Version*) &Pixy2_buffer[rPointer + PIXY2_CSHEADERSIZE];
- // Si le checksum et le type sont bon, on mappe le pointeur de résultat sur la FIFO (ligne précédente)
+ // On mappe le pointeur de version sur la donnée stockée dans la FIFO (ligne précédente)
etat = idle; // Et on annoce que la pixy est libre
- } else cr = PIXY2_TYPE_ERROR; // Si le type ne correspond pas on signale une erreur
+ } else {
+ if (msg->pixType == PIXY2_ERROR) { // Si on reçoit une trame d'erreur
+ cr = *(Pixy2ErrorCode*) &Pixy2_buffer[rPointer + PIXY2_CSHEADERSIZE];
+ // On mappe le résultat sur la donnée stockée dans la FIFO (ligne précédente)
+ }else cr = PIXY2_TYPE_ERROR; // Si le type ne correspond à rien de normal on signale une erreur
+ }
} else cr = PIXY2_BAD_CHECKSUM; // Si le checksum est faux on retourne une erreur aussi !
} else { // S'il n'y a pas de checksum (pas normal mais on ne sait jamais)
if (msg->pixType == PIXY2_REP_VERS) { // On vérifie que la trame est du type convenable
version = (T_Pixy2Version*) &Pixy2_buffer[rPointer + PIXY2_NCSHEADERSIZE];
// Si le checksum et le type sont bon, on mappe le pointeur de résultat sur la FIFO (ligne précédente)
etat = idle; // Et on annoce que la pixy est libre
- } else cr = PIXY2_TYPE_ERROR; // Si le type ne correspond pas on signale une erreur
+ } else {
+ if (msg->pixType == PIXY2_ERROR) { // Si on reçoit une trame d'erreur
+ cr = *(Pixy2ErrorCode*) &Pixy2_buffer[rPointer + PIXY2_NCSHEADERSIZE];
+ // On mappe le résultat sur la donnée stockée dans la FIFO (ligne précédente)
+ }else cr = PIXY2_TYPE_ERROR; // Si le type ne correspond à rien de normal on signale une erreur
+ }
}
break;
@@ -352,7 +362,7 @@
Pixy2ErrorCode PIXY2::pixy2_getResolution (T_Pixy2Resolution *resolution){
T_pixy2RcvHeader *msg = (T_pixy2RcvHeader*) &Pixy2_buffer[rPointer];
- Pixy2ErrorCode cr = PIXY2_OK;
+ Pixy2ErrorCode cr = PIXY2_OK;
switch (etat) {
case idle : // Si la caméra est inactive
@@ -369,14 +379,24 @@
resolution = (T_Pixy2Resolution*) &Pixy2_buffer[rPointer + PIXY2_CSHEADERSIZE];
// Si le checksum et le type sont bon, on mappe le pointeur de résultat sur la FIFO (ligne précédente)
etat = idle; // Et on annoce que la pixy est libre
- } else cr = PIXY2_TYPE_ERROR; // Si le type ne correspond pas on signale une erreur
+ } else {
+ if (msg->pixType == PIXY2_ERROR) { // Si on reçoit une trame d'erreur
+ cr = *(Pixy2ErrorCode*) &Pixy2_buffer[rPointer + PIXY2_CSHEADERSIZE];
+ // On mappe le résultat sur la donnée stockée dans la FIFO (ligne précédente)
+ }else cr = PIXY2_TYPE_ERROR; // Si le type ne correspond à rien de normal on signale une erreur
+ }
} else cr = PIXY2_BAD_CHECKSUM; // Si le checksum est faux on retourne une erreur aussi !
} else { // S'il n'y a pas de checksum (pas normal mais on ne sait jamais)
if (msg->pixType == PIXY2_REP_RESOL) { // On vérifie que la trame est du type convenable
resolution = (T_Pixy2Resolution*) &Pixy2_buffer[rPointer + PIXY2_NCSHEADERSIZE];
// Si le checksum et le type sont bon, on mappe le pointeur de résultat sur la FIFO (ligne précédente)
etat = idle; // Et on annoce que la pixy est libre
- } else cr = PIXY2_TYPE_ERROR; // Si le type ne correspond pas on signale une erreur
+ } else {
+ if (msg->pixType == PIXY2_ERROR) { // Si on reçoit une trame d'erreur
+ cr = *(Pixy2ErrorCode*) &Pixy2_buffer[rPointer + PIXY2_NCSHEADERSIZE];
+ // On mappe le résultat sur la donnée stockée dans la FIFO (ligne précédente)
+ }else cr = PIXY2_TYPE_ERROR; // Si le type ne correspond à rien de normal on signale une erreur
+ }
}
break;
@@ -392,9 +412,9 @@
Pixy2ErrorCode PIXY2::pixy2_setServos (Word s0, Word s1){return 0;}
Pixy2ErrorCode PIXY2::pixy2_setLED (Byte red, Byte green, Byte blue){return 0;}
Pixy2ErrorCode PIXY2::pixy2_setLamp (Byte upper, Byte lower){return 0;}
-Pixy2ErrorCode PIXY2::pixy2_getFPS (T_pixy2returnCode *framerate){return 0;}
+Pixy2ErrorCode PIXY2::pixy2_getFPS (T_pixy2ReturnCode *framerate){return 0;}
Pixy2ErrorCode PIXY2::pixy2_getBlocks (Byte sigmap, Byte maxBloc){return 0;}
-Pixy2ErrorCode PIXY2::pixy2_getMainFeature (Byte type, Byte features){return 0;}
+Pixy2ErrorCode PIXY2::pixy2_getMainFeature (Byte features){return 0;}
Pixy2ErrorCode PIXY2::pixy2_getAllFeature (Byte features){return 0;}
Pixy2ErrorCode PIXY2::pixy2_setMode (Byte mode){return 0;}
Pixy2ErrorCode PIXY2::pixy2_setNexTurn (Word angle){return 0;}