Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: max32630fthr Adafruit_FeatherOLED USBDevice
WatchInterface.cpp
00001 /******************************************************************************* 00002 * Copyright (C) Maxim Integrated Products, Inc., All rights Reserved. 00003 * 00004 * This software is protected by copyright laws of the United States and 00005 * of foreign countries. This material may also be protected by patent laws 00006 * and technology transfer regulations of the United States and of foreign 00007 * countries. This software is furnished under a license agreement and/or a 00008 * nondisclosure agreement and may only be used or reproduced in accordance 00009 * with the terms of those agreements. Dissemination of this information to 00010 * any party or parties not specified in the license agreement and/or 00011 * nondisclosure agreement is expressly prohibited. 00012 * 00013 * The above copyright notice and this permission notice shall be included 00014 * in all copies or substantial portions of the Software. 00015 * 00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00017 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00018 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00019 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00020 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00021 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00022 * OTHER DEALINGS IN THE SOFTWARE. 00023 * 00024 * Except as contained in this notice, the name of Maxim Integrated 00025 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00026 * Products, Inc. Branding Policy. 00027 * 00028 * The mere transfer of this software does not imply any licenses 00029 * of trade secrets, proprietary technology, copyrights, patents, 00030 * trademarks, maskwork rights, or any other form of intellectual 00031 * property whatsoever. Maxim Integrated Products, Inc. retains all 00032 * ownership rights. 00033 ******************************************************************************* 00034 */ 00035 00036 #include "WatchInterface.h" 00037 #include "Peripherals.h" 00038 #include "LS013B7DH03.h" 00039 #include "mbed_logo.h" 00040 00041 #include "UbuntuCondensed38x47.h" 00042 #include "ubuntucondensed20x26.h" 00043 #include "ubuntucondensed16x21.h" 00044 #include "Arial10x10.h" 00045 #include "Neu44x36.h" 00046 #include "mxm_assert.h" 00047 #include "utils.h" 00048 #include "../version.h" 00049 00050 //Non-const static members must be both declared in the class definition and defined with global scope to properly give the linker something to reference. 00051 bool WatchInterface::refreshed = true; 00052 00053 00054 WatchInterface::WatchInterface(PinName buttonUp, PinName buttonDown, PinName buttonPower, PinName displayCS, PinName displayEXTCOM, PinName displayDISP, SPI* displaySPI): 00055 btnUp(buttonUp), btnDown(buttonDown), btnPower(buttonPower), dispCS(displayCS), dispEXTCOM(displayEXTCOM), dispDISP(displayDISP), display(displaySPI, &dispCS), DisplayPWM(displayEXTCOM) 00056 { 00057 dispDISP = 0; 00058 00059 00060 buttonEvent_up = BUTTONEVENT_NONE; 00061 buttonEvent_down = BUTTONEVENT_NONE; 00062 00063 00064 btnUp.fall(callback(this, &WatchInterface::isr_buttonup)); 00065 btnUp.mode(PullUp); 00066 btnUp.enable_irq(); 00067 00068 btnDown.fall(callback(this, &WatchInterface::isr_buttondown)); 00069 btnDown.mode(PullUp); 00070 btnDown.enable_irq(); 00071 00072 displaySPI->frequency(1000000); 00073 00074 DisplayPWM.period_ms(16); 00075 DisplayPWM.pulsewidth_ms(8); 00076 00077 //updateDisplay(4); 00078 00079 recording_old = false; 00080 recording = false; 00081 recordingStopFlag = false; 00082 isDisplayOff = false; 00083 00084 interfaceTimer.start(); 00085 00086 displayMode_old = DISPLAYMODE_AFTERBOOT; 00087 displayMode = DISPLAYMODE_TIME; 00088 00089 00090 00091 } 00092 00093 void WatchInterface::isr_buttonup() 00094 { 00095 if (buttonEvent_up == BUTTONEVENT_NONE) { 00096 buttonEvent_up = BUTTONEVENT_UP_PRE; 00097 } 00098 } 00099 00100 void WatchInterface::isr_buttondown() 00101 { 00102 if (buttonEvent_down == BUTTONEVENT_NONE) { 00103 buttonEvent_down = BUTTONEVENT_DOWN_PRE; 00104 } 00105 } 00106 00107 WatchInterface::ButtonStatus WatchInterface::getButtonStatus(WatchInterface::hspButton button) 00108 { 00109 00110 switch (button) { 00111 00112 // TODO: fill button power status 00113 case WatchInterface::BUTTON_POWER : 00114 return (BUTTON_RELEASED); 00115 break; 00116 case WatchInterface::BUTTON_UP: 00117 if (btnUp.read()) { 00118 return (WatchInterface::BUTTON_PRESSED); 00119 } else { 00120 return (WatchInterface::BUTTON_RELEASED); 00121 } 00122 break; 00123 00124 case WatchInterface::BUTTON_DOWN: 00125 if (btnDown.read()) { 00126 return (WatchInterface::BUTTON_PRESSED); 00127 } else { 00128 return (WatchInterface::BUTTON_RELEASED); 00129 } 00130 break; 00131 00132 } 00133 00134 } 00135 00136 00137 void WatchInterface::refreshCallback(void) 00138 { 00139 refreshed = true; 00140 } 00141 00142 00143 00144 void WatchInterface::execute(void) 00145 { 00146 unsigned int current_timer; 00147 static int tickCount; 00148 static char tickCount_battery; 00149 static int firstDetect_up; 00150 static int firstDetect_down; 00151 00152 00153 // Display is OFF in ECG Mode 00154 if (ecg_enabled) { 00155 if (recording & (buttonEvent_down == BUTTONEVENT_DOWN_PRE)) { 00156 dispDISP = 1; 00157 if (isDisplayOff) { 00158 displayOff(false); 00159 } 00160 displayMode = DISPLAYMODE_RECORDING_STOP; 00161 } else { 00162 displayOff(true); 00163 } 00164 } else { 00165 dispDISP = 1; 00166 if (isDisplayOff) { 00167 displayOff(false); 00168 displayMode = DISPLAYMODE_RECORDING_STOP; 00169 } 00170 } 00171 00172 00173 if (isDisplayOff != true) { 00174 display.executeOnceLCD(); 00175 00176 if (USB_Interface_MSD) { 00177 return; 00178 } 00179 00180 current_timer = interfaceTimer.read_ms(); 00181 00182 // Button Debouncing 00183 if (current_timer > 50) { 00184 00185 interfaceTimer.reset(); 00186 interfaceTimer.start(); 00187 00188 // Increase tick counter in every 50ms 00189 tickCount++; 00190 00191 // tick counter reset will occur in every 15x50 = 750ms. This is used for display updates 00192 if (tickCount == 15) { 00193 tickCount = 0; 00194 } 00195 00196 if (buttonEvent_up == BUTTONEVENT_UP_PRE) { 00197 00198 if (firstDetect_up < 2) { 00199 firstDetect_up++; 00200 } else { 00201 firstDetect_up = 0; 00202 if (btnUp.read() == 0) { 00203 buttonEvent_up = BUTTONEVENT_UP; 00204 } else { 00205 buttonEvent_up = BUTTONEVENT_NONE; 00206 } 00207 } 00208 00209 } else { 00210 firstDetect_up = 0; 00211 } 00212 00213 if (buttonEvent_down == BUTTONEVENT_DOWN_PRE) { 00214 00215 if (firstDetect_down < 2) { 00216 firstDetect_down++; 00217 } else { 00218 00219 firstDetect_down = 0; 00220 00221 if (btnDown.read() == 0) { 00222 buttonEvent_down = BUTTONEVENT_DOWN; 00223 00224 } else { 00225 buttonEvent_down = BUTTONEVENT_NONE; 00226 } 00227 } 00228 00229 } else { 00230 firstDetect_down = 0; 00231 } 00232 00233 } 00234 00235 00236 switch (displayMode) { 00237 00238 00239 case DISPLAYMODE_TIME: 00240 00241 // Detect BLE Connected Event 00242 if (BLE_Interface_Exists) { 00243 00244 BLE_Interface_Exists_old = true; 00245 display_BLEMode_Active = false; 00246 displayMode = DISPLAYMODE_TETHERED; 00247 00248 tickCount = 8; 00249 00250 } else 00251 // Detect USB Connected Event 00252 if (USB_Interface_Exists) { 00253 00254 USB_Interface_Exists_old = true; 00255 display_USBMode_Active = false; 00256 displayMode = DISPLAYMODE_TETHERED_USB; 00257 00258 tickCount = 8; 00259 00260 } else 00261 // Next menu item 00262 if (buttonEvent_up == BUTTONEVENT_UP) { 00263 00264 buttonEvent_up = BUTTONEVENT_NONE; 00265 displayMode = DISPLAYMODE_PPG; 00266 modeUpdated = true; 00267 tickCount = 8; 00268 00269 } else 00270 // Next menu item 00271 if (buttonEvent_down == BUTTONEVENT_DOWN) { 00272 00273 buttonEvent_down = BUTTONEVENT_NONE; 00274 displayMode = DISPLAYMODE_INFO; 00275 modeUpdated = true; 00276 tickCount = 8; 00277 00278 } else { 00279 00280 00281 } 00282 break; 00283 00284 #ifdef ENABLE_SPO2 00285 case DISPLAYMODE_PPG: // Handle both PPG and ECG 00286 case DISPLAYMODE_ECG: 00287 00288 // Detect BLE Connected Event 00289 if (BLE_Interface_Exists) { 00290 00291 BLE_Interface_Exists_old = true; 00292 display_BLEMode_Active = false; 00293 displayMode = DISPLAYMODE_TETHERED; 00294 00295 tickCount = 8; 00296 00297 } else 00298 // Detect USB Connected Event 00299 if (USB_Interface_Exists) { 00300 00301 USB_Interface_Exists_old = true; 00302 display_USBMode_Active = false; 00303 displayMode = DISPLAYMODE_TETHERED_USB; 00304 00305 tickCount = 8; 00306 00307 } else 00308 // Next menu item 00309 if (buttonEvent_up == BUTTONEVENT_UP) { 00310 00311 buttonEvent_up = BUTTONEVENT_NONE; 00312 displayMode = DISPLAYMODE_SPO2_ONESHOT; 00313 modeUpdated = true; 00314 tickCount = 8; 00315 00316 } else 00317 // Next menu item 00318 if (buttonEvent_down == BUTTONEVENT_DOWN) { 00319 00320 buttonEvent_down = BUTTONEVENT_NONE; 00321 displayMode = DISPLAYMODE_TIME; 00322 modeUpdated = true; 00323 tickCount = 8; 00324 00325 } 00326 break; 00327 00328 case DISPLAYMODE_SPO2_ONESHOT: 00329 00330 // Detect BLE Connected Event 00331 if (BLE_Interface_Exists) { 00332 00333 BLE_Interface_Exists_old = true; 00334 display_BLEMode_Active = false; 00335 displayMode = DISPLAYMODE_TETHERED; 00336 00337 tickCount = 8; 00338 00339 } else 00340 // Detect USB Connected Event 00341 if (USB_Interface_Exists) { 00342 00343 USB_Interface_Exists_old = true; 00344 display_USBMode_Active = false; 00345 displayMode = DISPLAYMODE_TETHERED_USB; 00346 00347 tickCount = 8; 00348 00349 } else 00350 // Next menu item 00351 if (buttonEvent_up == BUTTONEVENT_UP) { 00352 00353 buttonEvent_up = BUTTONEVENT_NONE; 00354 displayMode = DISPLAYMODE_SPO2_CONTINUOUS; 00355 modeUpdated = true; 00356 tickCount = 8; 00357 00358 } else 00359 // Next menu item 00360 if (buttonEvent_down == BUTTONEVENT_DOWN) { 00361 00362 buttonEvent_down = BUTTONEVENT_NONE; 00363 displayMode = DISPLAYMODE_PPG; 00364 modeUpdated = true; 00365 tickCount = 8; 00366 00367 } 00368 00369 break; 00370 00371 case DISPLAYMODE_SPO2_CONTINUOUS: 00372 00373 // Detect BLE Connected Event 00374 if (BLE_Interface_Exists) { 00375 00376 BLE_Interface_Exists_old = true; 00377 display_BLEMode_Active = false; 00378 displayMode = DISPLAYMODE_TETHERED; 00379 00380 tickCount = 8; 00381 00382 } else 00383 // Detect USB Connected Event 00384 if (USB_Interface_Exists) { 00385 00386 USB_Interface_Exists_old = true; 00387 display_USBMode_Active = false; 00388 displayMode = DISPLAYMODE_TETHERED_USB; 00389 00390 tickCount = 8; 00391 00392 } else 00393 // Next menu item 00394 if (buttonEvent_up == BUTTONEVENT_UP) { 00395 00396 buttonEvent_up = BUTTONEVENT_NONE; 00397 displayMode = DISPLAYMODE_INFO; 00398 modeUpdated = true; 00399 tickCount = 8; 00400 00401 } else 00402 // Next menu item 00403 if (buttonEvent_down == BUTTONEVENT_DOWN) { 00404 00405 buttonEvent_down = BUTTONEVENT_NONE; 00406 displayMode = DISPLAYMODE_SPO2_ONESHOT; 00407 modeUpdated = true; 00408 tickCount = 8; 00409 00410 } 00411 00412 break; 00413 #else 00414 case DISPLAYMODE_PPG: // Handle both PPG and ECG 00415 case DISPLAYMODE_ECG: 00416 00417 // Detect BLE Connected Event 00418 if (BLE_Interface_Exists) { 00419 00420 BLE_Interface_Exists_old = true; 00421 display_BLEMode_Active = false; 00422 displayMode = DISPLAYMODE_TETHERED; 00423 00424 tickCount = 8; 00425 00426 } else 00427 // Detect USB Connected Event 00428 if (USB_Interface_Exists) { 00429 00430 USB_Interface_Exists_old = true; 00431 display_USBMode_Active = false; 00432 displayMode = DISPLAYMODE_TETHERED_USB; 00433 00434 tickCount = 8; 00435 00436 } else 00437 // Next menu item 00438 if (buttonEvent_up == BUTTONEVENT_UP) { 00439 00440 buttonEvent_up = BUTTONEVENT_NONE; 00441 displayMode = DISPLAYMODE_TEMP; 00442 modeUpdated = true; 00443 tickCount = 8; 00444 00445 } else 00446 // Next menu item 00447 if (buttonEvent_down == BUTTONEVENT_DOWN) { 00448 00449 buttonEvent_down = BUTTONEVENT_NONE; 00450 displayMode = DISPLAYMODE_TIME; 00451 modeUpdated = true; 00452 tickCount = 8; 00453 00454 } 00455 break; 00456 00457 case DISPLAYMODE_TEMP: 00458 00459 // Detect BLE Connected Event 00460 if (BLE_Interface_Exists) { 00461 00462 BLE_Interface_Exists_old = true; 00463 display_BLEMode_Active = false; 00464 displayMode = DISPLAYMODE_TETHERED; 00465 00466 tickCount = 8; 00467 00468 } else 00469 // Detect USB Connected Event 00470 if (USB_Interface_Exists) { 00471 00472 USB_Interface_Exists_old = true; 00473 display_USBMode_Active = false; 00474 displayMode = DISPLAYMODE_TETHERED_USB; 00475 00476 tickCount = 8; 00477 00478 } else 00479 // Next menu item 00480 if (buttonEvent_up == BUTTONEVENT_UP) { 00481 00482 buttonEvent_up = BUTTONEVENT_NONE; 00483 displayMode = DISPLAYMODE_INFO; 00484 modeUpdated = true; 00485 tickCount = 8; 00486 00487 } else 00488 // Next menu item 00489 if (buttonEvent_down == BUTTONEVENT_DOWN) { 00490 00491 buttonEvent_down = BUTTONEVENT_NONE; 00492 displayMode = DISPLAYMODE_PPG; 00493 modeUpdated = true; 00494 tickCount = 8; 00495 00496 } 00497 break; 00498 #endif 00499 case DISPLAYMODE_INFO: 00500 00501 // Detect BLE Connected Event 00502 if (BLE_Interface_Exists) { 00503 00504 BLE_Interface_Exists_old = true; 00505 display_BLEMode_Active = false; 00506 displayMode = DISPLAYMODE_TETHERED; 00507 00508 tickCount = 8; 00509 00510 } else 00511 // Detect USB Connected Event 00512 if (USB_Interface_Exists) { 00513 00514 USB_Interface_Exists_old = true; 00515 display_USBMode_Active = false; 00516 displayMode = DISPLAYMODE_TETHERED_USB; 00517 00518 tickCount = 8; 00519 00520 } else 00521 // Next menu item 00522 if (buttonEvent_up == BUTTONEVENT_UP) { 00523 00524 buttonEvent_up = BUTTONEVENT_NONE; 00525 displayMode = DISPLAYMODE_TIME; 00526 modeUpdated = true; 00527 tickCount = 8; 00528 00529 } else 00530 // Next menu item 00531 if (buttonEvent_down == BUTTONEVENT_DOWN) { 00532 00533 buttonEvent_down = BUTTONEVENT_NONE; 00534 #ifdef ENABLE_SPO2 00535 displayMode = DISPLAYMODE_SPO2_CONTINUOUS; 00536 #else 00537 displayMode = DISPLAYMODE_TEMP; 00538 #endif 00539 modeUpdated = true; 00540 tickCount = 8; 00541 00542 } 00543 break; 00544 case DISPLAYMODE_TETHERED: 00545 00546 // Detect Recording start event 00547 if ((recording) && (!recording_old)) { 00548 00549 recording_old = true; 00550 displayMode = DISPLAYMODE_RECORDING; 00551 00552 tickCount = 8; 00553 00554 } else 00555 // Detect BLE Disconnected Event 00556 if (!BLE_Interface_Exists) { 00557 00558 BLE_Interface_Exists_old = false; 00559 display_BLEMode_Active = false; 00560 displayMode = DISPLAYMODE_TIME; 00561 00562 tickCount = 8; 00563 00564 } 00565 00566 break; 00567 00568 case DISPLAYMODE_TETHERED_USB: 00569 00570 // Detect Recording start event 00571 if ((recording) && (!recording_old)) { 00572 00573 printf("START EVENT"); 00574 recording_old = recording; 00575 displayMode = DISPLAYMODE_RECORDING; 00576 00577 tickCount = 8; 00578 00579 } else 00580 // Detect USB Disconnected Event 00581 if (!USB_Interface_Exists) { 00582 00583 USB_Interface_Exists_old = false; 00584 display_USBMode_Active = false; 00585 displayMode = DISPLAYMODE_TIME; 00586 00587 tickCount = 8; 00588 00589 } 00590 00591 00592 break; 00593 00594 case DISPLAYMODE_RECORDING: { 00595 // Detect stop recording 00596 if ((!recording) && (recording_old)) { 00597 printf("STOP EVENT"); 00598 recording_old = recording; 00599 displayMode = DISPLAYMODE_TIME; 00600 tickCount = 8; 00601 } else { 00602 if (buttonEvent_down == BUTTONEVENT_DOWN) { 00603 buttonEvent_down = BUTTONEVENT_NONE; 00604 displayMode = DISPLAYMODE_RECORDING_STOP; 00605 tickCount = 8; 00606 } 00607 } 00608 } 00609 break; 00610 00611 case DISPLAYMODE_RECORDING_STOP: { 00612 recordingStopFlag = true; 00613 recording = false; 00614 recording_old = false; 00615 displayMode = DISPLAYMODE_TIME; 00616 } 00617 break; 00618 } 00619 00620 00621 00622 /* 00623 if ( recording ) { 00624 00625 if ( ( buttonEvent_down == BUTTONEVENT_DOWN ) && ( !BLE_Interface_Exists ) && ( !USB_Interface_Exists ) ) { 00626 00627 00628 buttonEvent_down = BUTTONEVENT_NONE; 00629 00630 if ( displayMode == DISPLAYMODE_RECORDING ) 00631 displayMode = DISPLAYMODE_RECORDING_STOP; 00632 00633 tickCount = 8; 00634 } 00635 } 00636 else { 00637 00638 // Handle Up/Down Button press Events 00639 00640 // Process DOWN Button Press Event 00641 if ( ( buttonEvent_down == BUTTONEVENT_DOWN ) && ( !BLE_Interface_Exists ) && ( !USB_Interface_Exists ) ) { 00642 00643 00644 buttonEvent_down = BUTTONEVENT_NONE; 00645 00646 if ( displayMode > 0) 00647 displayMode--; 00648 else 00649 displayMode = 3; 00650 00651 tickCount = 8; 00652 } 00653 else 00654 // Process UP Button Press Event 00655 if ( ( buttonEvent_up == BUTTONEVENT_UP ) && ( !BLE_Interface_Exists ) && ( !USB_Interface_Exists ) ) { 00656 00657 if ( displayMode < 3) 00658 displayMode++; 00659 else 00660 displayMode = 0; 00661 00662 buttonEvent_up = BUTTONEVENT_NONE; 00663 00664 tickCount = 8; 00665 } 00666 00667 00668 00669 00670 00671 // Detect BLE Connected Event 00672 if ( ( BLEWasActive == false ) && ( BLE_Interface_Exists ) ) { 00673 00674 BLEWasActive = true; 00675 display_BLEMode_Active = false; 00676 displayMode = DISPLAYMODE_TETHERED; 00677 modeUpdated = true; 00678 00679 tickCount = 8; 00680 00681 } 00682 else 00683 // Detect BLE Disconnected Event 00684 if ( ( BLEWasActive == true ) && ( !BLE_Interface_Exists ) ) { 00685 00686 BLEWasActive = false; 00687 display_BLEMode_Active = false; 00688 displayMode = DISPLAYMODE_TIME; 00689 //should_stop = true; 00690 modeUpdated = true; 00691 00692 tickCount = 8; 00693 00694 } 00695 else 00696 // Detect USB Connected Event 00697 if ( ( USBWasActive == false ) && ( USB_Interface_Exists ) ) { 00698 00699 USBWasActive = true; 00700 display_USBMode_Active = false; 00701 displayMode = DISPLAYMODE_TETHERED_USB; 00702 modeUpdated = true; 00703 00704 tickCount = 8; 00705 00706 } 00707 else 00708 // Detect USB Disconnected Event 00709 if ( ( USBWasActive == true ) && ( !USB_Interface_Exists ) ) { 00710 00711 USBWasActive = false; 00712 display_USBMode_Active = false; 00713 displayMode = DISPLAYMODE_TIME; 00714 //should_stop = true; 00715 modeUpdated = true; 00716 00717 tickCount = 8; 00718 00719 } 00720 00721 } 00722 */ 00723 00724 // Update the display in every 500ms (if necessary) 00725 if (tickCount == 0) { 00726 00727 tickCount = 1; 00728 00729 if (displayMode_old != displayMode) { 00730 00731 modeUpdated = true; 00732 #ifdef ENABLE_SPO2 00733 if((displayMode == DISPLAYMODE_SPO2_ONESHOT) || (displayMode == DISPLAYMODE_SPO2_CONTINUOUS)) 00734 { 00735 instant_spo2_percentage=0; 00736 } 00737 #endif 00738 } 00739 00740 //if ( (!display_BLEMode_Active) && (!display_USBMode_Active) ) { 00741 btnDown.disable_irq(); 00742 btnUp.disable_irq(); // Disable Interrupts 00743 00744 00745 if (tickCount_battery <= 0) { 00746 m_max20303_->Max20303_BatteryGauge(&batteryLevel); 00747 tickCount_battery = BATTERY_GAUGE_COUNT; 00748 } 00749 tickCount_battery--; 00750 00751 updateDisplay(batteryLevel); 00752 00753 btnDown.enable_irq(); 00754 btnUp.enable_irq(); // Enable Interrupts 00755 //} 00756 00757 displayMode_old = displayMode; 00758 } 00759 00760 } 00761 } 00762 00763 void WatchInterface::displayOff(bool off) 00764 { 00765 if (off) { 00766 // Display Turned Off 00767 DisplayPWM.pulsewidth_ms(0); 00768 dispDISP = 0; 00769 isDisplayOff = true; 00770 } else { 00771 // Display Turned on 00772 DisplayPWM.pulsewidth_ms(8); 00773 dispDISP = 1; 00774 isDisplayOff = false; 00775 } 00776 } 00777 00778 void WatchInterface::DisplayModeUpdated(){ 00779 ppg_lcd_count = 0; 00780 } 00781 00782 void WatchInterface::updateDisplay(int batteryLevelToBeScaled) { 00783 char buffer[32]; 00784 time_t seconds; 00785 int hrDisplay_confidenceThreshold; 00786 static int hr_timeout; 00787 00788 // Clear Entire Screen 00789 display.cls(); 00790 display.fill(0, 0, 128, 128, Black); 00791 00792 // Draw Maxim Integrated Logo 00793 display.showBMP((uint8_t*)maxim128Bitmaps, 120, 36, 8, 90); 00794 00795 if (!bootComplete) { 00796 return; 00797 } 00798 00799 // Show BLE logo if it is connected 00800 00801 00802 if (displayMode != DISPLAYMODE_TETHERED_USB) { 00803 // Draw battery outline 00804 display.fillrect(94, 6, 27, 12, White); 00805 display.fillrect(97, 9, 21, 6, Black); 00806 display.fillrect(122, 9, 2, 6, White); 00807 00808 if (batteryLevelToBeScaled < 10) { 00809 batteryLevelToBeScaled = 0; 00810 } else if (batteryLevelToBeScaled <= 25) { 00811 batteryLevelToBeScaled = 1; 00812 } else if (batteryLevelToBeScaled <= 50) { 00813 batteryLevelToBeScaled = 2; 00814 } else if (batteryLevelToBeScaled <= 75) { 00815 batteryLevelToBeScaled = 3; 00816 } else { 00817 batteryLevelToBeScaled = 4; 00818 } 00819 00820 // Draw battery level ticks 00821 for (int i = 0 ; i < batteryLevelToBeScaled ; i++) { 00822 display.fillrect(99 + (i * 5), 10, 3, 4, White); 00823 } 00824 } 00825 00826 // Show BLE logo if it is connected 00827 if (BLE_Interface_Exists) { 00828 display.showBMP((uint8_t*)BLELogoBitmap, 16, 15, 72, 13); 00829 //displayMode = DISPLAYMODE_TETHERED; 00830 //BLEWasActive = true; 00831 } else { 00832 // Show USB logo if it is connected 00833 if (USB_Interface_Exists) { 00834 display.showBMP((uint8_t*)USBLogoBitmap, 16, 15, 72, 13); 00835 //displayMode = DISPLAYMODE_TETHERED_USB; 00836 //USBWasActive = true; 00837 } 00838 } 00839 00840 display.set_font(UbuntuCondensed20x26); 00841 display.locate(3, 10); 00842 display.foreground((uint16_t)Black); 00843 display.background((uint16_t)White); 00844 00845 switch (displayMode) { 00846 00847 case DISPLAYMODE_RECORDING: 00848 00849 display.fillrect(8, 46, 27, 23, White); 00850 display.fillrect(9, 45, 25, 25, White); 00851 display.fillrect(10, 44, 23, 27, White); 00852 00853 if (ppg_lcd_count == 0) { 00854 display.fillellipse(21, 57, 8, 8, (uint16_t) Black); 00855 } 00856 00857 snprintf(buffer, 32, "REC"); 00858 display.set_font(UbuntuCondensed38x47); 00859 display.locate(40, 36); 00860 display.foreground((uint16_t)Black); 00861 display.background((uint16_t)White); 00862 display.printf(buffer); 00863 00864 00865 ppg_lcd_count++; 00866 if (ppg_lcd_count > 1) { 00867 ppg_lcd_count = 0; 00868 } 00869 00870 break; 00871 00872 00873 case DISPLAYMODE_RECORDING_STOP: 00874 display.printf("CONFIRM"); 00875 snprintf(buffer, 32, "STOP"); 00876 display.set_font(UbuntuCondensed38x47); 00877 display.locate(5, 36); 00878 display.foreground((uint16_t)Black); 00879 display.background((uint16_t)White); 00880 display.printf(buffer); 00881 00882 break; 00883 00884 case DISPLAYMODE_INFO: 00885 display.printf("INFO"); 00886 00887 00888 display.set_font(Arial10x10); 00889 00890 display.foreground((uint16_t)Black); 00891 display.background((uint16_t)White); 00892 snprintf(buffer, 32, "BLE MAC:"); 00893 display.locate(4, 40); 00894 display.printf(buffer); 00895 snprintf(buffer, 32, "%02X:%02X:%02X:%02X:%02X:%02X", m_mac_addr_[0], m_mac_addr_[1], m_mac_addr_[2], m_mac_addr_[3], m_mac_addr_[4], m_mac_addr_[5]); 00896 display.locate(4, 50); 00897 display.printf(buffer); 00898 00899 snprintf(buffer, 32, "FW Version:"); 00900 display.locate(4, 66); 00901 display.printf(buffer); 00902 00903 snprintf(buffer, 32, "%s", FIRMWARE_VERSION); 00904 display.locate(4, 76); 00905 display.printf(buffer); 00906 00907 break; 00908 00909 case DISPLAYMODE_TIME: 00910 display.printf("TIME"); 00911 seconds = time(NULL); 00912 strftime(buffer, 32, "%I:%M", localtime(&seconds)); 00913 display.set_font(UbuntuCondensed38x47); 00914 display.locate(6, 40); 00915 display.foreground((uint16_t)Black); 00916 display.background((uint16_t)White); 00917 display.printf(buffer); 00918 snprintf(buffer, 32, "MAC:%02X:%02X", m_mac_addr_[4], m_mac_addr_[5]); 00919 display.set_font(Arial10x10); 00920 display.locate(60, 20); 00921 display.foreground((uint16_t)Black); 00922 display.background((uint16_t)White); 00923 display.printf(buffer); 00924 00925 while (1) { 00926 if (seconds >= 86400) { 00927 seconds = seconds % 86400; 00928 } else { 00929 break; 00930 } 00931 } 00932 00933 if (seconds < 43200) { 00934 display.showBMP((uint8_t*)AM_Bitmap, 16, 9, 104, 45); 00935 } else { 00936 display.showBMP((uint8_t*)PM_Bitmap, 16, 9, 104, 45); 00937 } 00938 00939 00940 break; 00941 00942 case DISPLAYMODE_PPG: 00943 display.printf("PPG"); 00944 00945 //Blink "MEASURING" for the first 13 seconds (settling time of ppg) 00946 00947 display.set_font(UbuntuCondensed16x21); 00948 display.locate(12, 52); 00949 display.foreground((uint16_t)Black); 00950 display.background((uint16_t)White); 00951 00952 if(ppg_lcd_count<25) 00953 { 00954 if(ppg_lcd_count & 0x01) 00955 { 00956 display.printf(" "); 00957 } 00958 else 00959 { 00960 display.printf("MEASURING"); 00961 } 00962 } 00963 00964 //print the heart rate (it is settled now) 00965 else { 00966 if (ppg_lcd_count > 80) { 00967 ppg_lcd_count = 70; 00968 } 00969 00970 display.set_font(UbuntuCondensed38x47); 00971 display.locate(8, 40); 00972 display.foreground((uint16_t)Black); 00973 display.background((uint16_t)White); 00974 00975 if (instant_hr_activityClass == ACTD_REST_ACTIVITY) { 00976 hrDisplay_confidenceThreshold = ConfThresLevelRest; 00977 } else { 00978 hrDisplay_confidenceThreshold = ConfThresLevelOther; 00979 } 00980 if ((instant_hr_conf > hrDisplay_confidenceThreshold) && (instant_hr > kHeartRateLowerLimit) && (instant_hr < kHeartRateUpperLimit)) { 00981 display.printf("%d", instant_hr); 00982 last_good_hr = instant_hr; 00983 hr_timeout = 0; 00984 } else { 00985 if (hr_timeout < 200) { 00986 hr_timeout++; 00987 } 00988 if (hr_timeout < 12) { 00989 display.printf("%d", last_good_hr); 00990 } else { 00991 display.printf("--"); 00992 } 00993 00994 } 00995 00996 display.set_font(UbuntuCondensed20x26); 00997 display.locate(72, 57); 00998 display.foreground((uint16_t)Black); 00999 display.background((uint16_t)White); 01000 display.printf("BPM"); 01001 } 01002 01003 ppg_lcd_count++; 01004 01005 break; 01006 #ifdef ENABLE_SPO2 01007 case DISPLAYMODE_SPO2_ONESHOT: 01008 01009 display.printf("SPO2"); 01010 display.set_font(Arial10x10); 01011 display.locate(60,23); 01012 display.printf("ONE-SHOT"); 01013 display.set_font(UbuntuCondensed16x21); 01014 display.locate(12,52); 01015 display.foreground(Black); 01016 display.background(White); 01017 if (instant_spo2_percentage != 100 ) { 01018 if(ppg_lcd_count & 0x01) { 01019 display.printf(" "); 01020 } else { 01021 if(instant_lowSignalQualityFlag) 01022 display.printf("LOWSIGNAL"); 01023 else 01024 display.printf("MEASURING"); 01025 } 01026 } else { 01027 if(instant_lowSignalQualityFlag){ 01028 display.printf("LOWSIGNAL"); 01029 } else { 01030 display.set_font(UbuntuCondensed38x47); 01031 display.locate(8,40); 01032 display.foreground(Black); 01033 display.background(White); 01034 display.printf("%d", instant_spo2); 01035 display.set_font(UbuntuCondensed20x26); 01036 display.locate(72,57); 01037 display.foreground(Black); 01038 display.background(White); 01039 display.printf("%%"); 01040 } 01041 } 01042 ppg_lcd_count++; 01043 01044 break; 01045 case DISPLAYMODE_SPO2_CONTINUOUS: 01046 01047 display.printf("SPO2"); 01048 display.set_font(Arial10x10); 01049 display.locate(60,23); 01050 display.printf("NON-STOP"); 01051 display.set_font(UbuntuCondensed16x21); 01052 display.locate(12,52); 01053 display.foreground(Black); 01054 display.background(White); 01055 if (instant_spo2 == 0 ) { 01056 if(ppg_lcd_count & 0x01) { 01057 display.printf(" "); 01058 } else { 01059 if(instant_lowSignalQualityFlag) 01060 display.printf("LOWSIGNAL"); 01061 else 01062 display.printf("MEASURING"); 01063 } 01064 } else { 01065 if(instant_lowSignalQualityFlag){ 01066 display.printf("LOWSIGNAL"); 01067 } else { 01068 display.set_font(UbuntuCondensed38x47); 01069 display.locate(8,40); 01070 display.foreground(Black); 01071 display.background(White); 01072 display.printf("%d", instant_spo2); 01073 display.set_font(UbuntuCondensed20x26); 01074 display.locate(72,57); 01075 display.foreground(Black); 01076 display.background(White); 01077 display.printf("%%"); 01078 } 01079 } 01080 ppg_lcd_count++; 01081 01082 break; 01083 #endif 01084 case DISPLAYMODE_ECG: 01085 display.printf("ECG"); 01086 display.set_font(UbuntuCondensed38x47); 01087 display.locate(8, 40); 01088 display.foreground((uint16_t)Black); 01089 display.background((uint16_t)White); 01090 display.printf("%d", 70); 01091 01092 display.set_font(UbuntuCondensed20x26); 01093 display.locate(72, 57); 01094 display.foreground((uint16_t)Black); 01095 display.background((uint16_t)White); 01096 display.printf("BPM"); 01097 01098 break; 01099 #ifndef ENABLE_SPO2 01100 case DISPLAYMODE_TEMP: 01101 display.printf("TEMP"); 01102 display.set_font(UbuntuCondensed38x47); 01103 display.locate(8, 40); 01104 display.foreground((uint16_t)Black); 01105 display.background((uint16_t)White); 01106 display.printf("%2.1f", instant_temp_celsius); 01107 01108 display.set_font(UbuntuCondensed20x26); 01109 display.locate(92, 55); 01110 display.foreground((uint16_t)Black); 01111 display.background((uint16_t)White); 01112 display.printf("%cC", 127); 01113 01114 01115 break; 01116 #endif 01117 case DISPLAYMODE_TETHERED: 01118 display.printf("CONN"); 01119 display.set_font(UbuntuCondensed38x47); 01120 display.locate(30, 40); 01121 display.foreground((uint16_t)Black); 01122 display.background((uint16_t)White); 01123 display.printf("BLE", 24); 01124 01125 display_BLEMode_Active = true; 01126 01127 break; 01128 01129 case DISPLAYMODE_TETHERED_USB: 01130 if (USB_Interface_MSD) { 01131 display.printf("MSD"); 01132 } else { 01133 display.printf("CONN"); 01134 } 01135 display.set_font(UbuntuCondensed38x47); 01136 display.locate(30, 40); 01137 display.foreground((uint16_t)Black); 01138 display.background((uint16_t)White); 01139 display.printf("USB", 24); 01140 01141 display_USBMode_Active = true; 01142 01143 break; 01144 01145 } 01146 01147 01148 display.showBMP((uint8_t*)maxim128Bitmaps, 120, 36, 8, 90); 01149 01150 01151 if (refreshed) { 01152 refreshed = false; 01153 display.update(this->refreshCallback); 01154 } 01155 01156 01157 } 01158 01159
Generated on Tue Jul 12 2022 20:09:29 by
