Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BLE connection timeout #180

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/Watchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ void Watchy::showUpdateFW() {
}

void Watchy::updateFWBegin() {
int connectionTimeOutSeconds = BLE_WAIT_FOR_CONNECTION_TIMEOUT;
display.setFullWindow();
display.fillScreen(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b);
Expand All @@ -850,16 +851,33 @@ void Watchy::updateFWBegin() {
display.println(" ");
display.println("Waiting for");
display.println("connection...");
display.println(String(connectionTimeOutSeconds) + " seconds timeout");
display.display(false); // full refresh

BLE BT;
BT.begin("Watchy BLE OTA");
int prevStatus = -1;
int currentStatus;
bool checkTimeout = true;
bool proceed = true;
long startTime = millis();
int lastTimeSeconds = 0;

while (1) {
while (proceed) {
currentStatus = BT.updateStatus();
int seconds = (millis() - startTime)/1000;
if(seconds > lastTimeSeconds) {
lastTimeSeconds = seconds;
display.print(".");
display.display(true);
}

if (checkTimeout && lastTimeSeconds > connectionTimeOutSeconds) {
proceed = false;
}

if (prevStatus != currentStatus || prevStatus == 1) {
checkTimeout = false;
if (currentStatus == 0) {
display.setFullWindow();
display.fillScreen(GxEPD_BLACK);
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#define HOUR_12_24 24
// BLE OTA
#define BLE_DEVICE_NAME "Watchy BLE OTA"
#define BLE_WAIT_FOR_CONNECTION_TIMEOUT 60
#define WATCHFACE_NAME "Watchy 7 Segment"
#define SOFTWARE_VERSION_MAJOR 1
#define SOFTWARE_VERSION_MINOR 0
Expand Down