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.
Fork of Code_APP3_R by
main.cpp
00001 #include "xbee.h" 00002 #include "Accelerometer.h" 00003 #include "IO_p15.h" 00004 #include "config.h" 00005 00006 //#define __DEBUG__ 00007 #ifdef __DEBUG__ 00008 Serial pc(USBTX, USBRX, 9600); 00009 #endif 00010 PwmOut led1(LED1); 00011 //--------------------------------------------------------------// 00012 // APP stuff : tableau de pointeur de fonctions 00013 //--------------------------------------------------------------// 00014 #define NB_FUNCTIONS 2 00015 void func_accel(CArray*); 00016 void func_button(CArray*); 00017 void (*functions[NB_FUNCTIONS])(CArray*) = {func_accel, func_button}; 00018 //--------------------------------------------------------------// 00019 00020 int main() { 00021 DigitalOut RESET(p8); 00022 Serial XBee(p13, p14, 9600); 00023 00024 // Selon le lab, reset le Xbee 00025 RESET = 0; 00026 wait_ms(400); 00027 RESET = 1; 00028 00029 #ifdef __DEBUG__ 00030 pc.format(8, SerialBase::None, 1); 00031 #endif 00032 XBee.format(8, SerialBase::None, 1); 00033 00034 CArray DATA_TO_SEND; 00035 00036 // Addresse spéciale pour le coordinateur 00037 for (int j = 0; j < 8; j++) 00038 DATA_TO_SEND._64bit.bit[j] = 0; 00039 DATA_TO_SEND._16bit.bit[0] = 0xFF; 00040 DATA_TO_SEND._16bit.bit[1] = 0xFE; 00041 00042 DATA_TO_SEND._FrameType = 0x10; // Transmit Request 00043 00044 // options pour l'envoie au coordinateur 00045 DATA_TO_SEND.options = new char[2]; 00046 DATA_TO_SEND.options[0] = 0; // broadcast 00047 DATA_TO_SEND.options[1] = 0; // other options 00048 DATA_TO_SEND.opt_size = 2; 00049 00050 bool IsInitialized = false; 00051 char InitBytes = 0; 00052 00053 while(1) 00054 { 00055 if (IsInitialized) 00056 { 00057 for (char i = 0; i < NB_FUNCTIONS; i++) 00058 { 00059 DATA_TO_SEND._ptr = NULL; 00060 00061 (*functions[i])(&DATA_TO_SEND); 00062 00063 if (DATA_TO_SEND._ptr != NULL) 00064 { 00065 led1 = !led1; 00066 send(&XBee, &DATA_TO_SEND); 00067 #ifdef __DEBUG__ 00068 send(&pc, &DATA_TO_SEND); // debug only 00069 #endif 00070 delete DATA_TO_SEND._ptr; 00071 } 00072 } 00073 wait_ms( 1000 / SENSOR_FREQUENCY_HZ); 00074 } 00075 if (XBee.readable()) 00076 { 00077 #ifdef __DEBUG__ 00078 pc.putc(XBee.getc()); 00079 #endif 00080 InitBytes++; 00081 if (InitBytes == 6) 00082 { 00083 IsInitialized = true; 00084 setPAN(&XBee, PAN_ID); 00085 #ifdef __DEBUG__ 00086 setPAN(&pc, PAN_ID); 00087 #endif 00088 } 00089 } 00090 00091 #ifdef __DEBUG__ 00092 if (pc.readable()) 00093 { 00094 XBee.putc(pc.getc()); 00095 } 00096 #endif 00097 } 00098 }
Generated on Mon Jul 18 2022 14:56:15 by
