Andriy Makukha
/
football_project_wo_output
football_project_wo_output
Fork of football_project by
Diff: main.cpp
- Revision:
- 46:28c29ef61276
- Parent:
- 44:4ad6133987ed
- Parent:
- 45:1eb335c00cb2
- Child:
- 48:4c9551c826e9
--- a/main.cpp Sat Jan 09 21:46:34 2016 +0000 +++ b/main.cpp Mon Jan 11 16:34:46 2016 +0000 @@ -71,6 +71,12 @@ #define DEBUG(...) /* nothing */ #endif /* #if NEED_CONSOLE_OUTPUT */ +#ifdef MASTER +static bool is_master = true; +#else +static bool is_master = false; +#endif + void loop(); void setup(); void getRadioInput(char *ibuffer, int size); @@ -205,8 +211,7 @@ // Buffer for holding data from the phone // to the device -#define PHTODEV_BUF_LEN 30 /**/ -static char phoneToDev[PHTODEV_BUF_LEN] = {0}; +static char phoneToDev[MAX_LEN] = {0}; extern TA ta; @@ -222,11 +227,7 @@ // Get MAC addr so we can create a device name using it. ble.getAddress( pAdType, macAddr ); -#ifdef MASTER - sprintf( deviceName, "T%02X%02X", macAddr[1], macAddr[0] ); -#else - sprintf( deviceName, "S%02X%02X", macAddr[1], macAddr[0] ); -#endif + sprintf( deviceName, "%c%02X%02X", (is_master?'T':'S'), macAddr[1], macAddr[0] ); ble.accumulateAdvertisingPayload( GapAdvertisingData::COMPLETE_LOCAL_NAME, (const uint8_t *)deviceName, strlen(deviceName) ); @@ -258,7 +259,7 @@ if( wasCharging ) { pct = 102; // Show 102% at charger unplug. - tickTock = 25; // Cause another normal update in 5 seconds. + tickTock = /* 25 */ 50; // Cause another normal update in 5s (10 half s). } else { @@ -323,9 +324,9 @@ // DEBUG( "Disconnected!\n\r" ); // DEBUG( "Restarting the advertising process\n\r" ); -// #ifdef MASTER + ble.startAdvertising(); -// #endif + ta.post_color(0); } @@ -569,7 +570,7 @@ void periodicCallback( void ) { static int callCnt; - if( (callCnt++ % 5) != 0 ) return; + if( (callCnt++ % /* 5 */ 4 ) != 0 ) return; callCnt = 1; #if BLENANO @@ -580,7 +581,7 @@ // rts = !rts; // Check battery level every 30s. - if( 0 == (tickTock % 30) ) updateBatt( getBattLevel() ); + if( 0 == (tickTock % /* 30 */ 60 ) ) updateBatt( getBattLevel() ); tickTock++; } @@ -601,7 +602,7 @@ int main( void ) { Ticker ticker; - ticker.attach( periodicCallback, 0.2 /** 0.5 **/ /* 1 */ ); + ticker.attach( periodicCallback, 0.125 /** 0.2 **/ /** 0.5 **/ /* 1 */ ); /* // Thread thread( led_thread ); @@ -681,10 +682,9 @@ UARTService uartService( ble ); uartServicePtr = &uartService; - ble.setAdvertisingInterval( Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS( 132 ) ); -// #ifdef MASTER + ble.setAdvertisingInterval( Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS( is_master ? 132 : 5000 ) ); + ble.startAdvertising(); -// #endif PhoneAppIO *phone = new PhoneAppIO( ble, uartServicePtr->getRXCharacteristicHandle(), @@ -715,11 +715,11 @@ app_sched_execute(); // Attempt to get pstorage enqueued cmd callbacks. */ -/**/ int bytes = MIN( PHTODEV_BUF_LEN, phoneP->readable() ); -/**/ -#ifdef MASTER - getRadioInput( phoneToDev, phoneP->read( phoneToDev, bytes, 1 ) ); +#ifdef MASTER +/**/ int bytes = MIN( MAX_LEN, phoneP->readable() ); + getRadioInput( phoneToDev, phoneP->read( phoneToDev, bytes, 1 ) ); #endif + loop(); radio_loop(mac_addr); }