
embedded software for tortuga bike
Dependencies: BLE_API BikeControl DataLogging X_NUCLEO_IDB0XA1 _24LCXXX mbed
Revision 1:ffdec767aa55, committed 2016-07-18
- Comitter:
- ptuytsch
- Date:
- Mon Jul 18 09:33:08 2016 +0000
- Parent:
- 0:0803cdf04c32
- Child:
- 2:7eb0bb74a8b6
- Commit message:
- At working stage with eeprom and BLE combined, adding a start to the bikeControl library.
Changed in this revision
--- a/BLE_API.lib Fri Jul 15 12:49:59 2016 +0000 +++ b/BLE_API.lib Mon Jul 18 09:33:08 2016 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/ptuytsch/code/BLE_API/#8afbec0520f5 +https://developer.mbed.org/teams/The-Opportunity-Factory/code/BLE_API/#da7745688342
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BikeControl.lib Mon Jul 18 09:33:08 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/The-Opportunity-Factory/code/BikeControl/#792a8f167ac0
--- a/DataLogging.lib Fri Jul 15 12:49:59 2016 +0000 +++ b/DataLogging.lib Mon Jul 18 09:33:08 2016 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/ptuytsch/code/DataLogging/#f91f45d52f9b +https://developer.mbed.org/teams/The-Opportunity-Factory/code/DataLogging/#fad416fb6979
--- a/_24LCXXX.lib Fri Jul 15 12:49:59 2016 +0000 +++ b/_24LCXXX.lib Mon Jul 18 09:33:08 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/bant62/code/_24LCXXX/#f70a5bfaf16b +https://developer.mbed.org/teams/The-Opportunity-Factory/code/_24LCXXX/#f70a5bfaf16b
--- a/main.cpp Fri Jul 15 12:49:59 2016 +0000 +++ b/main.cpp Mon Jul 18 09:33:08 2016 +0000 @@ -14,11 +14,18 @@ ****************************************************************************/ +//LIGHT +DigitalOut lightFront(PB_14); +DigitalOut lightBack(PA_11); +DigitalOut lightLeft(PC_6); +DigitalOut lightRight(PC_8); + + //3 battery states -BatteryState *trailerBattery = new BatteryState(trailerBatteryPin,BatteryState::Battery48V); -BatteryState *bikeBattery = new BatteryState(bikeBatteryPin,BatteryState::Battery48V); -BatteryState *auxiliaryBattery = new BatteryState(auxiliaryBatteryPin,BatteryState::Battery48V); +static BatteryState *trailerBattery; +static BatteryState *bikeBattery; +static BatteryState *auxiliaryBattery; //BLE VARIABLES static char DEVICE_NAME[] = "TORTUGA"; //Define default name of the BLE device @@ -37,6 +44,29 @@ static bool update = false; static bool updateHalf = false; +/*************************************************************************** + CONTROL FUNCTIONS +****************************************************************************/ +void runTestLight() +{ + printf("front\n"); + lightFront =1; + wait(1); + lightFront = 0; + printf("back\n"); + lightBack = 1; + wait(1); + lightBack = 0; + printf("left\n"); + lightLeft = 1; + wait(1); + lightLeft = 0; + printf("right\n"); + lightRight = 1; + wait(1); + lightRight = 0; + wait(1); +} /*************************************************************************** BLE FUNCTIONS @@ -86,8 +116,12 @@ /* Setup primary services */ //DISptr = new DeviceInformationService(ble, "The Opportunity Factory", "1.0", "PJTMN06", "1.0", "0.9", "0.9"); - batSerPtr = new BatteryService(ble); bikeServicePtr = new BikeService(ble,bd); + batSerPtr = new BatteryService(ble, + trailerBattery->getBatteryPercentage(), + bikeBattery->getBatteryPercentage(), + auxiliaryBattery->getBatteryPercentage()); + printf("Services set\n"); /* setup advertising */ @@ -113,11 +147,19 @@ printf("BikeData object created\n"); + trailerBattery = new BatteryState(trailerBatteryPin,BatteryState::Battery48V); + bikeBattery = new BatteryState(bikeBatteryPin,BatteryState::Battery48V); + auxiliaryBattery = new BatteryState(auxiliaryBatteryPin,BatteryState::Battery48V); + + + printf("run TestLight \n"); + runTestLight(); + uint8_t size = bd->getBikeNameSize(); printf("name length: %i\n", size); if (size == 0){ printf("Setting Name First Time\n"); - static char testName[] = "TortugaPJT06"; + static char testName[] = "Tortuga"; bd -> setBikeName((char *)testName,sizeof(testName)); printf("SetFistTimeName\n"); //printf( "size: %i\n",bd -> getBikeNameSize()); @@ -142,16 +184,21 @@ while(true) { if (update){ + printf("--------------\n"); + float distance = (bd->getDataSet(BikeData::OVERALL))->getDistance(); + printf("main distance: %f\n", distance); float speed = bd->getSpeed(); - printf("speed: %f\n", speed); + printf("main speed: %f\n", speed); //printf("update bikeService\n"); bikeServicePtr->update(); //update the bikeserice - //printf("update battery1\n"); + //printf("update battery1: %i\n", trailerBattery->getBatteryPercentage()); + //batSerPtr->updateBatteryLevel1((++batLevel)%=101); + //printf("battery level: %i\n", batLevel); batSerPtr->updateBatteryLevel1(trailerBattery->getBatteryPercentage()); - //printf("update battery2\n"); + //printf("update battery2: %i\n", bikeBattery->getBatteryPercentage()); batSerPtr->updateBatteryLevel2(bikeBattery->getBatteryPercentage()); - //printf("update battery3\n"); + //printf("update battery3: %i\n", auxiliaryBattery->getBatteryPercentage()); batSerPtr->updateBatteryLevel3(auxiliaryBattery->getBatteryPercentage()); update = false; } @@ -159,95 +206,4 @@ } - - /*printf("\n======================"); - printf("\n\n"); - - Ticker t1; - t1.attach(periodicCallback,1); - - for(uint64_t i = 0 ; i <0xFFFFF;i++);*/ - //uint32_t dummy = 0x0002; - /*I2C i2c(PB_9, PB_8); - Serial pc(SERIAL_TX, SERIAL_RX); - _24LCXXX mem(&i2c); - - printf("\nsizeof dummy: %i\n", sizeof(dummy)); - printf("Writing: %#x\n", dummy); - mem.nbyte_write(0,&dummy,4); - dummy+=0x1111; - printf("Writing: %#x\n", dummy); - mem.nbyte_write(4,&dummy,sizeof(dummy)); - dummy+=0x1111; - printf("Writing: %#x\n", dummy); - mem.nbyte_write(8,&dummy,sizeof(dummy)); - dummy+=0x1111; - printf("Writing: %#x\n", dummy); - mem.nbyte_write(12,&dummy,sizeof(dummy)); - dummy+=0x1111; - printf("Writing: %#x\n", dummy); - mem.nbyte_write(16,&dummy,sizeof(dummy)); - printf("Done Writing\n"); - - for (uint64_t i = 0 ; i<0xFFFFF ; i++); // waiting between reading en writing - - dummy = 0x0000; - printf("reading\n"); - mem.nbyte_read(0,&dummy,sizeof(dummy)); - printf(" res: %#x\n",dummy); - dummy = 0x0000; - printf("reading\n"); - mem.nbyte_read(4,&dummy,sizeof(dummy)); - printf(" res: %#x\n",dummy); - dummy = 0x0000; - printf("reading\n"); - mem.nbyte_read(8,&dummy,sizeof(dummy)); - printf(" res: %#x\n",dummy); - dummy = 0x0000; - printf("reading\n"); - mem.nbyte_read(12,&dummy,sizeof(dummy)); - printf(" res: %#x\n",dummy); - dummy = 0x0000; - printf("reading\n"); - mem.nbyte_read(16,&dummy,sizeof(dummy)); - printf(" res: %#x\n",dummy); - printf("Done reading\n");*/ - - - - /*printf("updating distance in eeprom\n"); - float d = 1000.2; - if(!mem.nbyte_write(0,&d,sizeof(float))){ - printf("eeprom writing error distance\n"); - } // update the eeprom values - printf("updating time in eeprom\n"); - uint32_t t = 0x10101010; - if(!mem.nbyte_write(4,&t,sizeof(uint32_t))){ - printf("eeprom writing error time\n"); - } - - - - - bd = new BikeData(PC_0); - - for (int i = 9 ; i<16 ; i++){ - char dummy; - mem.nbyte_read(i,&dummy,sizeof(dummy)); - printf("char: %c\n", dummy); - } - - - while(1){ - - - - if (update){ - //printf("u"); - //printf("update\n"); - float distance = bd->getDataSet(BikeData::OVERALL)->getDistance(); - printf("bikedata overall distance: %f\n",distance); - update = false; - } - } */ }