TEST

Dependencies:   max32630fthr Adafruit_FeatherOLED USBDevice

Committer:
gmehmet
Date:
Wed Apr 10 14:56:25 2019 +0300
Revision:
1:f60eafbf009a
Child:
3:2fe2ff1ca0dc
upload from local

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gmehmet 1:f60eafbf009a 1 /*
gmehmet 1:f60eafbf009a 2 * WatchInterface.h
gmehmet 1:f60eafbf009a 3 *
gmehmet 1:f60eafbf009a 4 * Created on: Aug 28, 2018
gmehmet 1:f60eafbf009a 5 * Author: Gokhan.Bektas
gmehmet 1:f60eafbf009a 6 */
gmehmet 1:f60eafbf009a 7
gmehmet 1:f60eafbf009a 8 #define BATTERY_GAUGE_COUNT 50
gmehmet 1:f60eafbf009a 9 #define BATTERY_CRITICAL_LEVEL 5
gmehmet 1:f60eafbf009a 10
gmehmet 1:f60eafbf009a 11
gmehmet 1:f60eafbf009a 12
gmehmet 1:f60eafbf009a 13
gmehmet 1:f60eafbf009a 14 #ifndef UTILITIES_WATCHINTERFACE_H_
gmehmet 1:f60eafbf009a 15 #define UTILITIES_WATCHINTERFACE_H_
gmehmet 1:f60eafbf009a 16 #include "mbed.h"
gmehmet 1:f60eafbf009a 17 #include "LS013B7DH03.h"
gmehmet 1:f60eafbf009a 18 #include "version.h"
gmehmet 1:f60eafbf009a 19 #include "BLE_ICARUS.h"
gmehmet 1:f60eafbf009a 20
gmehmet 1:f60eafbf009a 21 #include "MAX20303.h"
gmehmet 1:f60eafbf009a 22
gmehmet 1:f60eafbf009a 23
gmehmet 1:f60eafbf009a 24 #define DISPLAYMODE_TIME 0
gmehmet 1:f60eafbf009a 25 #define DISPLAYMODE_PPG 1
gmehmet 1:f60eafbf009a 26 #ifdef ENABLE_SPO2
gmehmet 1:f60eafbf009a 27 #define DISPLAYMODE_SPO2_ONESHOT 2
gmehmet 1:f60eafbf009a 28 #define DISPLAYMODE_SPO2_CONTINUOUS 3
gmehmet 1:f60eafbf009a 29 #else
gmehmet 1:f60eafbf009a 30 #define DISPLAYMODE_TEMP 4
gmehmet 1:f60eafbf009a 31 #endif
gmehmet 1:f60eafbf009a 32 #define DISPLAYMODE_INFO 5
gmehmet 1:f60eafbf009a 33 #define DISPLAYMODE_ECG 6
gmehmet 1:f60eafbf009a 34 #define DISPLAYMODE_TETHERED 7
gmehmet 1:f60eafbf009a 35 #define DISPLAYMODE_TETHERED_USB 8
gmehmet 1:f60eafbf009a 36 #define DISPLAYMODE_LOGO 9
gmehmet 1:f60eafbf009a 37 #define DISPLAYMODE_RECORDING 10
gmehmet 1:f60eafbf009a 38 #define DISPLAYMODE_RECORDING_STOP 11
gmehmet 1:f60eafbf009a 39 #define DISPLAYMODE_AFTERBOOT 12
gmehmet 1:f60eafbf009a 40
gmehmet 1:f60eafbf009a 41
gmehmet 1:f60eafbf009a 42 typedef enum {
gmehmet 1:f60eafbf009a 43
gmehmet 1:f60eafbf009a 44 BUTTONEVENT_NONE,
gmehmet 1:f60eafbf009a 45 BUTTONEVENT_UP_PRE,
gmehmet 1:f60eafbf009a 46 BUTTONEVENT_DOWN_PRE,
gmehmet 1:f60eafbf009a 47 BUTTONEVENT_UP,
gmehmet 1:f60eafbf009a 48 BUTTONEVENT_DOWN
gmehmet 1:f60eafbf009a 49
gmehmet 1:f60eafbf009a 50 } Button_Event;
gmehmet 1:f60eafbf009a 51
gmehmet 1:f60eafbf009a 52 class WatchInterface
gmehmet 1:f60eafbf009a 53 {
gmehmet 1:f60eafbf009a 54 public:
gmehmet 1:f60eafbf009a 55
gmehmet 1:f60eafbf009a 56
gmehmet 1:f60eafbf009a 57 typedef enum {
gmehmet 1:f60eafbf009a 58 /** No activity, or very light activity. */
gmehmet 1:f60eafbf009a 59 ACTD_REST_ACTIVITY = 0,
gmehmet 1:f60eafbf009a 60 /** Non-rhythmic activities that cannot be classified in the other categories. */
gmehmet 1:f60eafbf009a 61 ACTD_OTHER_ACTIVITY = 1,
gmehmet 1:f60eafbf009a 62 /** Walking activity. */
gmehmet 1:f60eafbf009a 63 ACTD_WALK_ACTIVITY = 2,
gmehmet 1:f60eafbf009a 64 /** Running activity. */
gmehmet 1:f60eafbf009a 65 ACTD_RUN_ACTIVITY = 3,
gmehmet 1:f60eafbf009a 66 /** Biking activity. */
gmehmet 1:f60eafbf009a 67 ACTD_BIKE_ACTIVITY = 4,
gmehmet 1:f60eafbf009a 68 /** Rhythmic activities that cannot be classified in the other categories. */
gmehmet 1:f60eafbf009a 69 ACTD_OTHER_RYTHMIC_ACTIVITY = 5,
gmehmet 1:f60eafbf009a 70 } actd_ActivityClass_te;
gmehmet 1:f60eafbf009a 71
gmehmet 1:f60eafbf009a 72
gmehmet 1:f60eafbf009a 73 typedef enum {
gmehmet 1:f60eafbf009a 74 BUTTON_PRESSED = 1,
gmehmet 1:f60eafbf009a 75 BUTTON_RELEASED = 0
gmehmet 1:f60eafbf009a 76
gmehmet 1:f60eafbf009a 77 } ButtonStatus;
gmehmet 1:f60eafbf009a 78
gmehmet 1:f60eafbf009a 79
gmehmet 1:f60eafbf009a 80 typedef enum {
gmehmet 1:f60eafbf009a 81 BUTTON_POWER = 0,
gmehmet 1:f60eafbf009a 82 BUTTON_UP = 1,
gmehmet 1:f60eafbf009a 83 BUTTON_DOWN = 2
gmehmet 1:f60eafbf009a 84
gmehmet 1:f60eafbf009a 85 } hspButton;
gmehmet 1:f60eafbf009a 86
gmehmet 1:f60eafbf009a 87
gmehmet 1:f60eafbf009a 88 /** Create an Watch Interface controller
gmehmet 1:f60eafbf009a 89 *
gmehmet 1:f60eafbf009a 90 * @param buttonUp PinName UP button
gmehmet 1:f60eafbf009a 91 * @param buttonDown PinName DOWN button
gmehmet 1:f60eafbf009a 92 * @param buttonPower PinName POWER button
gmehmet 1:f60eafbf009a 93 */
gmehmet 1:f60eafbf009a 94 WatchInterface(PinName buttonUp, PinName buttonDown, PinName buttonPower, PinName displayCS, PinName displayEXTCOM, PinName displayDISP, SPI* displaySPI);
gmehmet 1:f60eafbf009a 95
gmehmet 1:f60eafbf009a 96 void updateDisplay(int batteryLevelToBeScaled);
gmehmet 1:f60eafbf009a 97 void execute(void);
gmehmet 1:f60eafbf009a 98 void displayOff(bool off);
gmehmet 1:f60eafbf009a 99 void DisplayStatus();
gmehmet 1:f60eafbf009a 100 void DisplayModeUpdated();
gmehmet 1:f60eafbf009a 101
gmehmet 1:f60eafbf009a 102 static void refreshCallback(void);
gmehmet 1:f60eafbf009a 103
gmehmet 1:f60eafbf009a 104 unsigned char connection_indicator;
gmehmet 1:f60eafbf009a 105
gmehmet 1:f60eafbf009a 106 ButtonStatus getButtonStatus(hspButton button);
gmehmet 1:f60eafbf009a 107
gmehmet 1:f60eafbf009a 108 uint16_t heartRate;
gmehmet 1:f60eafbf009a 109 uint16_t heartRateConfidence;
gmehmet 1:f60eafbf009a 110 volatile bool BLE_Interface_Exists, BLE_Interface_Exists_old;
gmehmet 1:f60eafbf009a 111 volatile bool USB_Interface_Exists, USB_Interface_Exists_old;
gmehmet 1:f60eafbf009a 112 volatile bool USB_Interface_MSD;
gmehmet 1:f60eafbf009a 113 volatile bool recording, recording_old;
gmehmet 1:f60eafbf009a 114
gmehmet 1:f60eafbf009a 115 bool recordingStopFlag;
gmehmet 1:f60eafbf009a 116
gmehmet 1:f60eafbf009a 117 volatile bool modeUpdated;
gmehmet 1:f60eafbf009a 118
gmehmet 1:f60eafbf009a 119 unsigned char batteryLevel;
gmehmet 1:f60eafbf009a 120
gmehmet 1:f60eafbf009a 121 volatile Button_Event buttonEvent_down;
gmehmet 1:f60eafbf009a 122 volatile Button_Event buttonEvent_up;
gmehmet 1:f60eafbf009a 123
gmehmet 1:f60eafbf009a 124 unsigned char displayMode;
gmehmet 1:f60eafbf009a 125 unsigned char displayMode_old;
gmehmet 1:f60eafbf009a 126 bool isDisplayOff;
gmehmet 1:f60eafbf009a 127
gmehmet 1:f60eafbf009a 128 volatile bool BLEWasActive;
gmehmet 1:f60eafbf009a 129 volatile bool USBWasActive;
gmehmet 1:f60eafbf009a 130
gmehmet 1:f60eafbf009a 131 bool ecg_enabled;
gmehmet 1:f60eafbf009a 132 bool ppg_enabled;
gmehmet 1:f60eafbf009a 133
gmehmet 1:f60eafbf009a 134 bool bootComplete;
gmehmet 1:f60eafbf009a 135
gmehmet 1:f60eafbf009a 136 uint16_t last_good_hr;
gmehmet 1:f60eafbf009a 137 uint16_t instant_hr;
gmehmet 1:f60eafbf009a 138 uint16_t instant_hr_conf;
gmehmet 1:f60eafbf009a 139 uint8_t instant_hr_activityClass;
gmehmet 1:f60eafbf009a 140 float instant_temp_celsius;
gmehmet 1:f60eafbf009a 141
gmehmet 1:f60eafbf009a 142 char m_mac_addr_[6];
gmehmet 1:f60eafbf009a 143
gmehmet 1:f60eafbf009a 144 MAX20303* m_max20303_;
gmehmet 1:f60eafbf009a 145
gmehmet 1:f60eafbf009a 146
gmehmet 1:f60eafbf009a 147
gmehmet 1:f60eafbf009a 148 protected:
gmehmet 1:f60eafbf009a 149
gmehmet 1:f60eafbf009a 150 private:
gmehmet 1:f60eafbf009a 151
gmehmet 1:f60eafbf009a 152
gmehmet 1:f60eafbf009a 153
gmehmet 1:f60eafbf009a 154 //Ticker m_watchInterface_ticker_;
gmehmet 1:f60eafbf009a 155
gmehmet 1:f60eafbf009a 156 InterruptIn btnUp;
gmehmet 1:f60eafbf009a 157 InterruptIn btnDown;
gmehmet 1:f60eafbf009a 158 DigitalIn btnPower;
gmehmet 1:f60eafbf009a 159 DigitalOut dispCS;
gmehmet 1:f60eafbf009a 160 PinName dispEXTCOM;
gmehmet 1:f60eafbf009a 161 DigitalOut dispDISP;
gmehmet 1:f60eafbf009a 162
gmehmet 1:f60eafbf009a 163 PwmOut DisplayPWM;
gmehmet 1:f60eafbf009a 164
gmehmet 1:f60eafbf009a 165 Timer interfaceTimer;
gmehmet 1:f60eafbf009a 166
gmehmet 1:f60eafbf009a 167 volatile int buttonTimer;
gmehmet 1:f60eafbf009a 168
gmehmet 1:f60eafbf009a 169 void isr_buttonup();
gmehmet 1:f60eafbf009a 170 void isr_buttondown();
gmehmet 1:f60eafbf009a 171
gmehmet 1:f60eafbf009a 172 bool display_BLEMode_Active;
gmehmet 1:f60eafbf009a 173 bool display_USBMode_Active;
gmehmet 1:f60eafbf009a 174
gmehmet 1:f60eafbf009a 175 silabs::LS013B7DH03 display;
gmehmet 1:f60eafbf009a 176
gmehmet 1:f60eafbf009a 177 unsigned char ppg_lcd_count; //a variable used to print "MEASURING" while the ppg settling
gmehmet 1:f60eafbf009a 178
gmehmet 1:f60eafbf009a 179 static bool refreshed;
gmehmet 1:f60eafbf009a 180
gmehmet 1:f60eafbf009a 181 static const uint16_t kHeartRateUpperLimit = 240;
gmehmet 1:f60eafbf009a 182 static const uint16_t kHeartRateLowerLimit = 40;
gmehmet 1:f60eafbf009a 183 static const uint16_t ConfThresLevelRest = 50;
gmehmet 1:f60eafbf009a 184 static const uint16_t ConfThresLevelOther = 10;
gmehmet 1:f60eafbf009a 185
gmehmet 1:f60eafbf009a 186
gmehmet 1:f60eafbf009a 187 };
gmehmet 1:f60eafbf009a 188
gmehmet 1:f60eafbf009a 189
gmehmet 1:f60eafbf009a 190 #endif