imob
Dependencies: mbedtls mbed BLE_API nRF51822 AccelSensor
Revision 1:471d502617fe, committed 2021-03-20
- Comitter:
- osilvam
- Date:
- Sat Mar 20 19:09:06 2021 +0000
- Parent:
- 0:5284859bb3e8
- Commit message:
- last version
Changed in this revision
diff -r 5284859bb3e8 -r 471d502617fe AccelSensorService.h --- a/AccelSensorService.h Tue Mar 20 14:31:59 2018 +0000 +++ b/AccelSensorService.h Sat Mar 20 19:09:06 2021 +0000 @@ -6,7 +6,7 @@ #include "ble/Gap.h" #include "AccelSensor/AccelSensor.h" -#define ACCEL_DETECTION_THRESHOLD 85 +#define ACCEL_DETECTION_THRESHOLD 110 class AccelSensorService { public:
diff -r 5284859bb3e8 -r 471d502617fe RELAYService.h --- a/RELAYService.h Tue Mar 20 14:31:59 2018 +0000 +++ b/RELAYService.h Sat Mar 20 19:09:06 2021 +0000 @@ -6,9 +6,14 @@ #include "ble/Gap.h" #include "ImobStateService.h" -#define RELAY_TIME 2000000 // us +#define RELAY_TIME 120000000 // us #define CTR12V_TIME 100000 // us +Ticker waitTicker; +bool activation_in_progress = false; + + + class RELAYService { public: const static uint16_t RELAY_SERVICE_UUID = 0xC000; @@ -44,14 +49,14 @@ void activate() { - Ctr12v = 1; - wait_us(CTR12V_TIME); - updateRelayState(1); - wait_us(RELAY_TIME);//depending of the time switching desired - updateRelayState(0); - wait_us(CTR12V_TIME); - Ctr12v = 0; + if(!activation_in_progress) + { + flipCtr12v(); + waitTicker.attach(callback(this, &RELAYService::internalUpdateRelaystate), CTR12V_TIME/1000000.0); + } } + + protected: @@ -60,7 +65,7 @@ if(authenticated && activated) { activate(); - //ISS->resetAuthenticationValues(); + ISS->resetAuthenticationValues(); } } @@ -74,11 +79,39 @@ if(!activated) ISS->updateActivationValue(1); } - else - updateRelayState(0); + //else + // updateRelayState(0); } private: + + void internalUpdateRelaystate() + { + uint8_t aux_relayState = (relayState) ? 0: 1; + updateRelayState(aux_relayState); + + if(aux_relayState) + { + waitTicker.detach(); + waitTicker.attach(callback(this, &RELAYService::internalUpdateRelaystate), RELAY_TIME/1000000.0); + } + else + { + waitTicker.detach(); + waitTicker.attach(callback(this, &RELAYService::flipCtr12v), CTR12V_TIME/1000000.0); + } + } + + void flipCtr12v() + { + Ctr12v = !Ctr12v; + if(!Ctr12v) + { + waitTicker.detach(); + activation_in_progress = false; + } + else activation_in_progress = true; + } BLEDevice &ble; uint8_t relayState;
diff -r 5284859bb3e8 -r 471d502617fe main.cpp --- a/main.cpp Tue Mar 20 14:31:59 2018 +0000 +++ b/main.cpp Sat Mar 20 19:09:06 2021 +0000 @@ -238,6 +238,7 @@ if ( !initial_activation && !userIsConnected) if (forceActivationCounter > AUTHENTICATION_TIME) { + forceActivationCounter = 0; imobStateServicePtr->updateActivationValue(1); initial_activation = true; }