TEST
Dependencies: max32630fthr Adafruit_FeatherOLED USBDevice
Utilities/WatchInterface.h@3:2fe2ff1ca0dc, 2019-07-29 (annotated)
- Committer:
- Emre.Eken@IST-LT-36262.maxim-ic.internal
- Date:
- Mon Jul 29 10:26:58 2019 +0300
- Revision:
- 3:2fe2ff1ca0dc
- Parent:
- 1:f60eafbf009a
Maxim copy right section is added.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 1 | /******************************************************************************* |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 2 | * Copyright (C) Maxim Integrated Products, Inc., All rights Reserved. |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 3 | * |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 4 | * This software is protected by copyright laws of the United States and |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 5 | * of foreign countries. This material may also be protected by patent laws |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 6 | * and technology transfer regulations of the United States and of foreign |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 7 | * countries. This software is furnished under a license agreement and/or a |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 8 | * nondisclosure agreement and may only be used or reproduced in accordance |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 9 | * with the terms of those agreements. Dissemination of this information to |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 10 | * any party or parties not specified in the license agreement and/or |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 11 | * nondisclosure agreement is expressly prohibited. |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 12 | * |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 13 | * The above copyright notice and this permission notice shall be included |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 14 | * in all copies or substantial portions of the Software. |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 15 | * |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 17 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 19 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 20 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 22 | * OTHER DEALINGS IN THE SOFTWARE. |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 23 | * |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 24 | * Except as contained in this notice, the name of Maxim Integrated |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 25 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 26 | * Products, Inc. Branding Policy. |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 27 | * |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 28 | * The mere transfer of this software does not imply any licenses |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 29 | * of trade secrets, proprietary technology, copyrights, patents, |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 30 | * trademarks, maskwork rights, or any other form of intellectual |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 31 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 32 | * ownership rights. |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 33 | ******************************************************************************* |
Emre.Eken@IST-LT-36262.maxim-ic.internal | 3:2fe2ff1ca0dc | 34 | */ |
gmehmet | 1:f60eafbf009a | 35 | |
gmehmet | 1:f60eafbf009a | 36 | #define BATTERY_GAUGE_COUNT 50 |
gmehmet | 1:f60eafbf009a | 37 | #define BATTERY_CRITICAL_LEVEL 5 |
gmehmet | 1:f60eafbf009a | 38 | |
gmehmet | 1:f60eafbf009a | 39 | |
gmehmet | 1:f60eafbf009a | 40 | |
gmehmet | 1:f60eafbf009a | 41 | |
gmehmet | 1:f60eafbf009a | 42 | #ifndef UTILITIES_WATCHINTERFACE_H_ |
gmehmet | 1:f60eafbf009a | 43 | #define UTILITIES_WATCHINTERFACE_H_ |
gmehmet | 1:f60eafbf009a | 44 | #include "mbed.h" |
gmehmet | 1:f60eafbf009a | 45 | #include "LS013B7DH03.h" |
gmehmet | 1:f60eafbf009a | 46 | #include "version.h" |
gmehmet | 1:f60eafbf009a | 47 | #include "BLE_ICARUS.h" |
gmehmet | 1:f60eafbf009a | 48 | |
gmehmet | 1:f60eafbf009a | 49 | #include "MAX20303.h" |
gmehmet | 1:f60eafbf009a | 50 | |
gmehmet | 1:f60eafbf009a | 51 | |
gmehmet | 1:f60eafbf009a | 52 | #define DISPLAYMODE_TIME 0 |
gmehmet | 1:f60eafbf009a | 53 | #define DISPLAYMODE_PPG 1 |
gmehmet | 1:f60eafbf009a | 54 | #ifdef ENABLE_SPO2 |
gmehmet | 1:f60eafbf009a | 55 | #define DISPLAYMODE_SPO2_ONESHOT 2 |
gmehmet | 1:f60eafbf009a | 56 | #define DISPLAYMODE_SPO2_CONTINUOUS 3 |
gmehmet | 1:f60eafbf009a | 57 | #else |
gmehmet | 1:f60eafbf009a | 58 | #define DISPLAYMODE_TEMP 4 |
gmehmet | 1:f60eafbf009a | 59 | #endif |
gmehmet | 1:f60eafbf009a | 60 | #define DISPLAYMODE_INFO 5 |
gmehmet | 1:f60eafbf009a | 61 | #define DISPLAYMODE_ECG 6 |
gmehmet | 1:f60eafbf009a | 62 | #define DISPLAYMODE_TETHERED 7 |
gmehmet | 1:f60eafbf009a | 63 | #define DISPLAYMODE_TETHERED_USB 8 |
gmehmet | 1:f60eafbf009a | 64 | #define DISPLAYMODE_LOGO 9 |
gmehmet | 1:f60eafbf009a | 65 | #define DISPLAYMODE_RECORDING 10 |
gmehmet | 1:f60eafbf009a | 66 | #define DISPLAYMODE_RECORDING_STOP 11 |
gmehmet | 1:f60eafbf009a | 67 | #define DISPLAYMODE_AFTERBOOT 12 |
gmehmet | 1:f60eafbf009a | 68 | |
gmehmet | 1:f60eafbf009a | 69 | |
gmehmet | 1:f60eafbf009a | 70 | typedef enum { |
gmehmet | 1:f60eafbf009a | 71 | |
gmehmet | 1:f60eafbf009a | 72 | BUTTONEVENT_NONE, |
gmehmet | 1:f60eafbf009a | 73 | BUTTONEVENT_UP_PRE, |
gmehmet | 1:f60eafbf009a | 74 | BUTTONEVENT_DOWN_PRE, |
gmehmet | 1:f60eafbf009a | 75 | BUTTONEVENT_UP, |
gmehmet | 1:f60eafbf009a | 76 | BUTTONEVENT_DOWN |
gmehmet | 1:f60eafbf009a | 77 | |
gmehmet | 1:f60eafbf009a | 78 | } Button_Event; |
gmehmet | 1:f60eafbf009a | 79 | |
gmehmet | 1:f60eafbf009a | 80 | class WatchInterface |
gmehmet | 1:f60eafbf009a | 81 | { |
gmehmet | 1:f60eafbf009a | 82 | public: |
gmehmet | 1:f60eafbf009a | 83 | |
gmehmet | 1:f60eafbf009a | 84 | |
gmehmet | 1:f60eafbf009a | 85 | typedef enum { |
gmehmet | 1:f60eafbf009a | 86 | /** No activity, or very light activity. */ |
gmehmet | 1:f60eafbf009a | 87 | ACTD_REST_ACTIVITY = 0, |
gmehmet | 1:f60eafbf009a | 88 | /** Non-rhythmic activities that cannot be classified in the other categories. */ |
gmehmet | 1:f60eafbf009a | 89 | ACTD_OTHER_ACTIVITY = 1, |
gmehmet | 1:f60eafbf009a | 90 | /** Walking activity. */ |
gmehmet | 1:f60eafbf009a | 91 | ACTD_WALK_ACTIVITY = 2, |
gmehmet | 1:f60eafbf009a | 92 | /** Running activity. */ |
gmehmet | 1:f60eafbf009a | 93 | ACTD_RUN_ACTIVITY = 3, |
gmehmet | 1:f60eafbf009a | 94 | /** Biking activity. */ |
gmehmet | 1:f60eafbf009a | 95 | ACTD_BIKE_ACTIVITY = 4, |
gmehmet | 1:f60eafbf009a | 96 | /** Rhythmic activities that cannot be classified in the other categories. */ |
gmehmet | 1:f60eafbf009a | 97 | ACTD_OTHER_RYTHMIC_ACTIVITY = 5, |
gmehmet | 1:f60eafbf009a | 98 | } actd_ActivityClass_te; |
gmehmet | 1:f60eafbf009a | 99 | |
gmehmet | 1:f60eafbf009a | 100 | |
gmehmet | 1:f60eafbf009a | 101 | typedef enum { |
gmehmet | 1:f60eafbf009a | 102 | BUTTON_PRESSED = 1, |
gmehmet | 1:f60eafbf009a | 103 | BUTTON_RELEASED = 0 |
gmehmet | 1:f60eafbf009a | 104 | |
gmehmet | 1:f60eafbf009a | 105 | } ButtonStatus; |
gmehmet | 1:f60eafbf009a | 106 | |
gmehmet | 1:f60eafbf009a | 107 | |
gmehmet | 1:f60eafbf009a | 108 | typedef enum { |
gmehmet | 1:f60eafbf009a | 109 | BUTTON_POWER = 0, |
gmehmet | 1:f60eafbf009a | 110 | BUTTON_UP = 1, |
gmehmet | 1:f60eafbf009a | 111 | BUTTON_DOWN = 2 |
gmehmet | 1:f60eafbf009a | 112 | |
gmehmet | 1:f60eafbf009a | 113 | } hspButton; |
gmehmet | 1:f60eafbf009a | 114 | |
gmehmet | 1:f60eafbf009a | 115 | |
gmehmet | 1:f60eafbf009a | 116 | /** Create an Watch Interface controller |
gmehmet | 1:f60eafbf009a | 117 | * |
gmehmet | 1:f60eafbf009a | 118 | * @param buttonUp PinName UP button |
gmehmet | 1:f60eafbf009a | 119 | * @param buttonDown PinName DOWN button |
gmehmet | 1:f60eafbf009a | 120 | * @param buttonPower PinName POWER button |
gmehmet | 1:f60eafbf009a | 121 | */ |
gmehmet | 1:f60eafbf009a | 122 | WatchInterface(PinName buttonUp, PinName buttonDown, PinName buttonPower, PinName displayCS, PinName displayEXTCOM, PinName displayDISP, SPI* displaySPI); |
gmehmet | 1:f60eafbf009a | 123 | |
gmehmet | 1:f60eafbf009a | 124 | void updateDisplay(int batteryLevelToBeScaled); |
gmehmet | 1:f60eafbf009a | 125 | void execute(void); |
gmehmet | 1:f60eafbf009a | 126 | void displayOff(bool off); |
gmehmet | 1:f60eafbf009a | 127 | void DisplayStatus(); |
gmehmet | 1:f60eafbf009a | 128 | void DisplayModeUpdated(); |
gmehmet | 1:f60eafbf009a | 129 | |
gmehmet | 1:f60eafbf009a | 130 | static void refreshCallback(void); |
gmehmet | 1:f60eafbf009a | 131 | |
gmehmet | 1:f60eafbf009a | 132 | unsigned char connection_indicator; |
gmehmet | 1:f60eafbf009a | 133 | |
gmehmet | 1:f60eafbf009a | 134 | ButtonStatus getButtonStatus(hspButton button); |
gmehmet | 1:f60eafbf009a | 135 | |
gmehmet | 1:f60eafbf009a | 136 | uint16_t heartRate; |
gmehmet | 1:f60eafbf009a | 137 | uint16_t heartRateConfidence; |
gmehmet | 1:f60eafbf009a | 138 | volatile bool BLE_Interface_Exists, BLE_Interface_Exists_old; |
gmehmet | 1:f60eafbf009a | 139 | volatile bool USB_Interface_Exists, USB_Interface_Exists_old; |
gmehmet | 1:f60eafbf009a | 140 | volatile bool USB_Interface_MSD; |
gmehmet | 1:f60eafbf009a | 141 | volatile bool recording, recording_old; |
gmehmet | 1:f60eafbf009a | 142 | |
gmehmet | 1:f60eafbf009a | 143 | bool recordingStopFlag; |
gmehmet | 1:f60eafbf009a | 144 | |
gmehmet | 1:f60eafbf009a | 145 | volatile bool modeUpdated; |
gmehmet | 1:f60eafbf009a | 146 | |
gmehmet | 1:f60eafbf009a | 147 | unsigned char batteryLevel; |
gmehmet | 1:f60eafbf009a | 148 | |
gmehmet | 1:f60eafbf009a | 149 | volatile Button_Event buttonEvent_down; |
gmehmet | 1:f60eafbf009a | 150 | volatile Button_Event buttonEvent_up; |
gmehmet | 1:f60eafbf009a | 151 | |
gmehmet | 1:f60eafbf009a | 152 | unsigned char displayMode; |
gmehmet | 1:f60eafbf009a | 153 | unsigned char displayMode_old; |
gmehmet | 1:f60eafbf009a | 154 | bool isDisplayOff; |
gmehmet | 1:f60eafbf009a | 155 | |
gmehmet | 1:f60eafbf009a | 156 | volatile bool BLEWasActive; |
gmehmet | 1:f60eafbf009a | 157 | volatile bool USBWasActive; |
gmehmet | 1:f60eafbf009a | 158 | |
gmehmet | 1:f60eafbf009a | 159 | bool ecg_enabled; |
gmehmet | 1:f60eafbf009a | 160 | bool ppg_enabled; |
gmehmet | 1:f60eafbf009a | 161 | |
gmehmet | 1:f60eafbf009a | 162 | bool bootComplete; |
gmehmet | 1:f60eafbf009a | 163 | |
gmehmet | 1:f60eafbf009a | 164 | uint16_t last_good_hr; |
gmehmet | 1:f60eafbf009a | 165 | uint16_t instant_hr; |
gmehmet | 1:f60eafbf009a | 166 | uint16_t instant_hr_conf; |
gmehmet | 1:f60eafbf009a | 167 | uint8_t instant_hr_activityClass; |
gmehmet | 1:f60eafbf009a | 168 | float instant_temp_celsius; |
gmehmet | 1:f60eafbf009a | 169 | |
gmehmet | 1:f60eafbf009a | 170 | char m_mac_addr_[6]; |
gmehmet | 1:f60eafbf009a | 171 | |
gmehmet | 1:f60eafbf009a | 172 | MAX20303* m_max20303_; |
gmehmet | 1:f60eafbf009a | 173 | |
gmehmet | 1:f60eafbf009a | 174 | |
gmehmet | 1:f60eafbf009a | 175 | |
gmehmet | 1:f60eafbf009a | 176 | protected: |
gmehmet | 1:f60eafbf009a | 177 | |
gmehmet | 1:f60eafbf009a | 178 | private: |
gmehmet | 1:f60eafbf009a | 179 | |
gmehmet | 1:f60eafbf009a | 180 | |
gmehmet | 1:f60eafbf009a | 181 | |
gmehmet | 1:f60eafbf009a | 182 | //Ticker m_watchInterface_ticker_; |
gmehmet | 1:f60eafbf009a | 183 | |
gmehmet | 1:f60eafbf009a | 184 | InterruptIn btnUp; |
gmehmet | 1:f60eafbf009a | 185 | InterruptIn btnDown; |
gmehmet | 1:f60eafbf009a | 186 | DigitalIn btnPower; |
gmehmet | 1:f60eafbf009a | 187 | DigitalOut dispCS; |
gmehmet | 1:f60eafbf009a | 188 | PinName dispEXTCOM; |
gmehmet | 1:f60eafbf009a | 189 | DigitalOut dispDISP; |
gmehmet | 1:f60eafbf009a | 190 | |
gmehmet | 1:f60eafbf009a | 191 | PwmOut DisplayPWM; |
gmehmet | 1:f60eafbf009a | 192 | |
gmehmet | 1:f60eafbf009a | 193 | Timer interfaceTimer; |
gmehmet | 1:f60eafbf009a | 194 | |
gmehmet | 1:f60eafbf009a | 195 | volatile int buttonTimer; |
gmehmet | 1:f60eafbf009a | 196 | |
gmehmet | 1:f60eafbf009a | 197 | void isr_buttonup(); |
gmehmet | 1:f60eafbf009a | 198 | void isr_buttondown(); |
gmehmet | 1:f60eafbf009a | 199 | |
gmehmet | 1:f60eafbf009a | 200 | bool display_BLEMode_Active; |
gmehmet | 1:f60eafbf009a | 201 | bool display_USBMode_Active; |
gmehmet | 1:f60eafbf009a | 202 | |
gmehmet | 1:f60eafbf009a | 203 | silabs::LS013B7DH03 display; |
gmehmet | 1:f60eafbf009a | 204 | |
gmehmet | 1:f60eafbf009a | 205 | unsigned char ppg_lcd_count; //a variable used to print "MEASURING" while the ppg settling |
gmehmet | 1:f60eafbf009a | 206 | |
gmehmet | 1:f60eafbf009a | 207 | static bool refreshed; |
gmehmet | 1:f60eafbf009a | 208 | |
gmehmet | 1:f60eafbf009a | 209 | static const uint16_t kHeartRateUpperLimit = 240; |
gmehmet | 1:f60eafbf009a | 210 | static const uint16_t kHeartRateLowerLimit = 40; |
gmehmet | 1:f60eafbf009a | 211 | static const uint16_t ConfThresLevelRest = 50; |
gmehmet | 1:f60eafbf009a | 212 | static const uint16_t ConfThresLevelOther = 10; |
gmehmet | 1:f60eafbf009a | 213 | |
gmehmet | 1:f60eafbf009a | 214 | |
gmehmet | 1:f60eafbf009a | 215 | }; |
gmehmet | 1:f60eafbf009a | 216 | |
gmehmet | 1:f60eafbf009a | 217 | |
gmehmet | 1:f60eafbf009a | 218 | #endif |