-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoneDetect.cpp
More file actions
38 lines (30 loc) · 1.32 KB
/
PhoneDetect.cpp
File metadata and controls
38 lines (30 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "PhoneDetect.h"
boolean phone_state; //boolean storing the current state of the phone
uint64_t phone_state_chk_ctr; //storing the last time that the phone existence has been checked
boolean last_check_state; //storing the last state when checked
void phoneInit(){
pinMode(RED_LED, INPUT); //set inputs
pinMode(BLUE_LED, INPUT); //set inputs
phone_state = false;
phone_state_chk_ctr = esp_timer_get_time();
}
void phoneDetect(){
if (esp_timer_get_time() - phone_state_chk_ctr > CHK_INTERVAL){ //if it has passed 1s since last checking
boolean state_current = (digitalRead(RED_LED) && digitalRead(BLUE_LED));
//Serial.print("state: ");
//Serial.println(state_current);
if (state_current == last_check_state){
if(state_current != phone_state){ //if state changed
phone_state = state_current; //assign the new state to the phoneState
if(state_current){ //if phone connected
bluetoothSendConnected(); //notify Android
}else{ //if phone disconnected
bluetoothSendDisconnected();
}
lightStateChg(); //call change light state
}
}
last_check_state = state_current;
phone_state_chk_ctr = esp_timer_get_time(); //reassign the time of checking
}
}