Lizzy project

Dependencies:   aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT

Files at this revision

API Documentation at this revision

Comitter:
dbartolovic
Date:
Wed Aug 29 17:08:08 2018 +0000
Branch:
axis_normal
Parent:
15:c0c01188a29b
Child:
23:bf9c1dd2b5cb
Commit message:
Debuged wake on shake. If consumption in sleep is half mA make sure mbed-os version is 5.8

Changed in this revision

aconno_ble/aconno_ble.cpp Show annotated file Show diff for this revision Revisions of this file
aconno_ble/aconno_ble.h Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
source/main.cpp Show annotated file Show diff for this revision Revisions of this file
source/main.h Show annotated file Show diff for this revision Revisions of this file
tasks/tasks.cpp Show annotated file Show diff for this revision Revisions of this file
tasks/tasks.h Show annotated file Show diff for this revision Revisions of this file
--- a/aconno_ble/aconno_ble.cpp	Wed Aug 29 14:48:43 2018 +0000
+++ b/aconno_ble/aconno_ble.cpp	Wed Aug 29 17:08:08 2018 +0000
@@ -21,7 +21,7 @@
 };
 LizzyService *lizzy_service;
 
-
+static bool clientConected = false;
 static EventQueue eventQueue( BLE_EVENT_COUNT * EVENTS_EVENT_SIZE );
 
 
@@ -36,13 +36,19 @@
     return &eventQueue;
 }
 
+bool bleIsClientConnected(void)
+{
+    return clientConected;
+}
+
 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
 {
+    clientConected = false;
     (lizzy_service->get_ble())->gap().startAdvertising();
 }
 
 void onConnectionCallback(const Gap::ConnectionCallbackParams_t *params){   
-    
+    clientConected = true;
 }
 
 void onDataWrittenCallback(const GattWriteCallbackParams *params) 
@@ -104,7 +110,7 @@
     
     lizzy_service = new LizzyService(ble, &init_lizzy);
     ble.gap().onDisconnection(disconnectionCallback);
-    //ble.gap().onConnection(onConnectionCallback);         
+    ble.gap().onConnection(onConnectionCallback);         
     ble.gattServer().onDataWritten(onDataWrittenCallback);
     
     // Setup event handling. This is needed only with services.
@@ -126,7 +132,7 @@
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(uint8_t)*11);
     ble.gap().setAdvertisingInterval(ADV_INTERVAL_MS);
-    ble.gap().startAdvertising();
+    //ble.gap().startAdvertising();
 }
 
 void updatePayload(BLE *ble, advertising_packet *advertisementPacket)
--- a/aconno_ble/aconno_ble.h	Wed Aug 29 14:48:43 2018 +0000
+++ b/aconno_ble/aconno_ble.h	Wed Aug 29 17:08:08 2018 +0000
@@ -44,6 +44,7 @@
 
 /* Function declarations */
 EventQueue *getBLEEventQueue(void);
+bool bleIsClientConnected(void);
 void bleInitComplete(BLE::InitializationCompleteCallbackContext *params);
 void updatePayload(BLE *ble, advertising_packet *advertisementPacket);
 
--- a/mbed-os.lib	Wed Aug 29 14:48:43 2018 +0000
+++ b/mbed-os.lib	Wed Aug 29 17:08:08 2018 +0000
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#5f6572179d66ce4c09d6517b659ac51133cc980d
+https://github.com/ARMmbed/mbed-os/#35fa909641fedcad9bbe0c7300d4ccdf15a2b71a
--- a/source/main.cpp	Wed Aug 29 14:48:43 2018 +0000
+++ b/source/main.cpp	Wed Aug 29 17:08:08 2018 +0000
@@ -11,20 +11,18 @@
 
 
 char memsI2CAddress = I2C_ADDRESS;
-Mutex uartM;
-Thread uartT;
 Thread bleT;
 Thread measureT;
 Thread updateServiceT;
 Thread updateBuzzLedsT;
+Thread servLoopT;
 
-DigitalOut redica(PIN_LED_RED);
 DigitalOut AccVcc(ACC_POWER_PIN);
 InterruptIn INT1(INT_PIN1);
 //InterruptIn INT2(INT_PIN2);
 I2C i2c(I2C_DATA,I2C_CLK);
-Ticker bleTicker;
 
+Lis2dh12 mems(&i2c, memsI2CAddress);
 
 void disableI2C(){
     NRF_TWI0->ENABLE = 0;
@@ -45,18 +43,19 @@
 
 extern int untilSleep;
 void int1Handler(void)
-{   
+{
+    __disable_irq();
+    
+    mems.clearIntFlag();
+    
     untilSleep = ACTIVE_PERIOD / MEASURE_INTERVAL_MS;
     
-    redica = !redica;
+    measureT.signal_set(START_MEAS);
     
-    measureT.signal_set(START_MEAS);
+    __enable_irq();
 }
 
 int main(){
-    Lis2dh12 mems(&i2c, memsI2CAddress);
-    
-    redica = 1;
     
     tasks_init();
     
@@ -68,16 +67,18 @@
     NRF_UICR->NFCPINS = 0xFFFFFFFE;     // Change NFC to GPIO function
     
     AccVcc = 1;
-    wait_ms(POWER_UP_DELAY_MS);
+    //wait_ms(POWER_UP_DELAY_MS);
+    Thread::wait(POWER_UP_DELAY_MS);
 
     
+    //measureT.signal_set(START_MEAS);
     INT1.rise(int1Handler);
     NRF_GPIO->PIN_CNF[INT_PIN1] &= 0xFFFFFFF3;  // NO PullUps
     
     
     BLE &ble = BLE::Instance();
     ble.init(bleInitComplete);
-    
+
     mems.setMode(LOW_POWER);
     //mems.setMode(HIGH_RES);
     mems.enableAxes(X_axis);
@@ -85,23 +86,23 @@
     mems.enableAxes(Z_axis);    
     mems.setODR(ODR_50Hz);
     //mems.setScale(_16g);
-    mems.setScale(_2g);
+    mems.setScale(_8g);
     mems.int1Setup(0x40);       // IntActivity 1 driven to INT1 pad
     mems.int1Latch(0x01);       // Enable int1 latch
     mems.int1Threshold(INT1_THRESHOLD); 
     mems.int1Duration(INT1_DUR);            
     mems.int1Config(0x2A);      // Enable XHigh, YHigh and ZHigh
-    
+
     bleT.start(callback(bleF, &ble));   // Start bleT
     measureT.start(callback(measureF, &mems));
     updateServiceT.start(updateServiceF);
     updateBuzzLedsT.start(updateBuzzLedsF);
+    servLoopT.start(servLoopC);
     
     
     while(1){
         //disableI2C();
         //ble.waitForEvent();
-        getBLEEventQueue()->dispatch_forever();
         Thread::wait(0xFFFFFFFF);
     }
 }
--- a/source/main.h	Wed Aug 29 14:48:43 2018 +0000
+++ b/source/main.h	Wed Aug 29 17:08:08 2018 +0000
@@ -33,20 +33,12 @@
     #define printf(...)
 #endif
 
-#define INT1_THRESHOLD      (20u)
-#define INT1_DUR            (0x00)
+#define INT1_THRESHOLD      (30)
+#define INT1_DUR            (12)
     
 #define ACC_INT_SIG         (0x00001020)    // Acc interrupt signal
 #define DISABLE_BLE_SIG     (0x00001030)
 
-#if DEBUG
-    NRF52_UART uart(p12, p14, Baud9600);
-    char buffer[255];
-    #define SEND(...) {uint8_t len = sprintf(buffer, __VA_ARGS__); uartM.lock(); uart.send(buffer, len); uartM.unlock();}
-#else
-    #define SEND(...)
-#endif
-
 
 extern Thread bleT;
 extern Thread measureT;
--- a/tasks/tasks.cpp	Wed Aug 29 14:48:43 2018 +0000
+++ b/tasks/tasks.cpp	Wed Aug 29 17:08:08 2018 +0000
@@ -122,10 +122,11 @@
             updateServiceT.signal_set(MEAS_DONE);
             bleT.signal_set(MEAS_DONE);
             
-            wait_ms(MEASURE_INTERVAL_MS);
+            //wait_ms(MEASURE_INTERVAL_MS);
+            Thread::wait(MEASURE_INTERVAL_MS);
             untilSleep--;
             
-            if(untilSleep <= 0)
+            if( (untilSleep <= 0) && !bleIsClientConnected() )
             {
                 BLE::Instance().stopAdvertising();
                 break;
@@ -226,4 +227,13 @@
         */
         //wait_ms(100);
     }
+}
+
+void servLoopC(void)
+{
+    while(1)
+    {
+        getBLEEventQueue()->dispatch_forever();
+        Thread::wait(0xFFFFFFFF);
+    }
 }
\ No newline at end of file
--- a/tasks/tasks.h	Wed Aug 29 14:48:43 2018 +0000
+++ b/tasks/tasks.h	Wed Aug 29 17:08:08 2018 +0000
@@ -23,5 +23,6 @@
 void updateServiceF();
 void updateBuzzLedsF();
 void bleF(BLE *ble);
+void servLoopC(void);
 
 #endif//__TASKS_H__
\ No newline at end of file