diff --git a/p8-firmware/bluetooth.cpp b/p8-firmware/bluetooth.cpp index 8b2c5ec..1e44a83 100644 --- a/p8-firmware/bluetooth.cpp +++ b/p8-firmware/bluetooth.cpp @@ -11,9 +11,9 @@ BLECharacteristic RXchar = BLECharacteristic("0001", BLEWriteWithoutResponse, 20 for power draw debugging. No work has been done on the bluetooth stack yet */ void initBluetooth() { - blePeripheral.setLocalName("P8Watch1"); + blePeripheral.setLocalName("P8Watch"); blePeripheral.setAdvertisingInterval(500); - blePeripheral.setDeviceName("P8Watch1"); + blePeripheral.setDeviceName("P8Watch"); blePeripheral.setAdvertisedServiceUuid(bleService.uuid()); blePeripheral.addAttribute(bleService); blePeripheral.addAttribute(TXchar); diff --git a/p8-firmware/p8-firmware.ino b/p8-firmware/p8-firmware.ino index b99891b..6024942 100644 --- a/p8-firmware/p8-firmware.ino +++ b/p8-firmware/p8-firmware.ino @@ -55,16 +55,27 @@ void loop() { addToCumulativeBatReading(); //Battery readings are taken over a period and the mean is taken periodically to get a more accurate reading + /* + Interrupts will wake the device and cause the interrupt handler to run. + The device then starts running thread mode code (normal code) from where it last slept + That means that if the interrupt didn't cause getPowerMode to be awake, then the device will + go back to sleep + If the type of interrupt is one where the device wakes up (eg button press), then + the THREAD MODE interrupt handler (not the NVIC interrupt handler) will set the device wakeup state (as well as enabling hardware), + meaning that the screenControllerLoop is run and the device is awake + */ if (getPowerMode() == POWER_ON) { screenControllerLoop(); //This will run the main loop of the current screen } else { sleepWait(); //This puts the MCU into its sleep mode, only waking on an interrupt } - /* If any interrupts were detected, this function will dispatch any events, and - reset the interrupt flag. This is not the NVIC interrupt handler, but a function called - in the main loop. This means that the interrupt handlers can just be simple flag-sets, and we - can guarantee the atomic execution of interrupt handling (ie making sure that the interrupt handler - doesn't read i2c whilst another part of the program was). */ + /* + If any interrupts were detected, this function will dispatch any events, and + reset the interrupt flag. This is not the NVIC interrupt handler, but a function called + in the main loop. This means that the interrupt handlers can just be simple flag-sets, and we + can guarantee the atomic execution of actual interrupt handling (ie making sure that the interrupt handler + doesn't read i2c whilst another part of the program was). + */ handleInterrupts(); } diff --git a/p8-firmware/screenController.cpp b/p8-firmware/screenController.cpp index 18a21ca..f34c105 100644 --- a/p8-firmware/screenController.cpp +++ b/p8-firmware/screenController.cpp @@ -25,6 +25,7 @@ WatchScreenBase* currentScreen = homeScreens[currentHomeScreenIndex]; /* This is called whenever a new screen is loaded + It will setup the screen and draw the indicator and update the screen refresh time */ void initScreen() { currentScreen->screenSetup(); //Call screenSetup() on the current screen @@ -61,6 +62,7 @@ void handleRightSwipe() { */ void prevScreen() { if (currentHomeScreenIndex != 0) { + currentScreen->screenDestroy(); //Call 'destructor' for current screen currentHomeScreenIndex--; currentScreen = homeScreens[currentHomeScreenIndex]; initScreen(); @@ -72,6 +74,7 @@ void prevScreen() { */ void nextScreen() { if (currentHomeScreenIndex != NUM_SCREENS - 1) { + currentScreen->screenDestroy(); //Call 'destructor' for current screen currentHomeScreenIndex++; currentScreen = homeScreens[currentHomeScreenIndex]; initScreen(); @@ -109,9 +112,9 @@ void handleButtonPress() { The parameters are the x and y coords of the tap */ void handleTap(uint8_t x, uint8_t y) { - if (y < 212) { + if (y < 212) { //If the tap is on the main application currentScreen->screenTap(x, y); - } else { + } else { //Else we are pressing in the app drawer buttons, so go to the prev or next screen if (x < 100) { prevScreen(); } else if (x > 160) { @@ -121,9 +124,10 @@ void handleTap(uint8_t x, uint8_t y) { } /* - Sleep when we receive a long tap */ + Sleep when we receive a long tap +*/ void handleLongTap(uint8_t x, uint8_t y) { - if (currentScreen->doesImplementLongTap() == true) { + if (currentScreen->doesImplementLongTap() == true) { //Make sure the current screen doesn't implement the long tap currentScreen->screenLongTap(x, y); } else { enterSleep(); @@ -137,7 +141,7 @@ void handleLongTap(uint8_t x, uint8_t y) { */ void screenControllerLoop() { if (millis() - lastScreenUpdate > screenUpdateMS) { - //Update the screen every 20 ms + //The refresh time is variable depending on the current screen currentScreen->screenLoop(); lastScreenUpdate = millis(); }