Andriy Makukha
/
football_project_wo_output
football_project_wo_output
Fork of football_project by
Diff: main.cpp
- Revision:
- 21:32f022efcc09
- Parent:
- 20:d6c6099b60be
- Child:
- 22:f58d4b441aba
--- a/main.cpp Fri Dec 04 09:46:49 2015 +0000 +++ b/main.cpp Fri Dec 04 14:02:05 2015 +0000 @@ -101,6 +101,14 @@ void pin_mode( PinName, PinMode ); } +#if BLENANO +#define ADC_IN_BATT P0_6 +#else +#define ADC_IN_BATT P0_4 +DigitalIn notcharge( P0_2, PullUp ); +#endif +AnalogIn batt( ADC_IN_BATT ); + // DigitalOut rts( RTS_PIN_NUMBER ); DigitalIn cts( CTS_PIN_NUMBER, PullDown ); // We'll use as a mode switch for serial data source. TODO @@ -162,7 +170,7 @@ // Buffer for holding data from the phone // to the device -#define PHTODEV_BUF_LEN 200 /**/ +#define PHTODEV_BUF_LEN 30 /**/ /// static char phoneToDev[200] = {0}; static char phoneToDev[PHTODEV_BUF_LEN] = {0}; @@ -498,9 +506,20 @@ void updateBatt( uint8_t pct ) { static uint8_t prev; + static bool wasCharging; - if( pct > 100 ) pct = 100; - if( abs( (int)prev -(int)pct ) < 3 ) return; // Don't register change of less than 3%. + if( notcharge ) + { + if( pct > 100 ) pct = 100; + if( !wasCharging && (abs( (int)prev -(int)pct ) < 3) ) return; // Don't register change of less than 3%. + prev = pct; + wasCharging = false; + + } else + { + pct = 101; // Show 101% if charging. + wasCharging = true; // Force show when done charging. + } batt_and_id[2] = pct; ble.clearAdvertisingPayload(); @@ -508,8 +527,11 @@ ble.setAdvertisingPayload(); if( NULL != battServiceP ) battServiceP->updateBatteryLevel( pct ); +} - prev = pct; +uint8_t getBattLevel() +{ + return (uint8_t)(batt * 125.f); } void periodicCallback( void ) @@ -524,8 +546,8 @@ // buzz = (foo & 2)>>1; // rts = !rts; - // Temp dummy battery level data. TODO - if( 8 == (foo & 15) ) updateBatt( (uint8_t)foo & 0x7f ); + // Check battery level every 30s. + if( 0 == (foo % 60) ) updateBatt( getBattLevel() ); } /* @@ -599,12 +621,10 @@ } */ - ble.setAdvertisingInterval( Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS( 132 ) ); - ble.startAdvertising(); - DeviceInformationService deviceInfo( ble, "TRX", "TrueAgility", "SN0001", "hw-rev1", "fw-rev1" ); BatteryService battService( ble ); battServiceP = &battService; + updateBatt( getBattLevel() ); /* Enable over-the-air firmware updates. Instantiating DFUService introduces a * control characteristic which can be used to trigger the application to @@ -614,6 +634,9 @@ UARTService uartService( ble ); uartServicePtr = &uartService; + ble.setAdvertisingInterval( Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS( 132 ) ); + ble.startAdvertising(); + PhoneAppIO *phone = new PhoneAppIO( ble, uartServicePtr->getRXCharacteristicHandle(), uartServicePtr->getTXCharacteristicHandle() );