
A simple example for analog input and EPD usage.
Dependencies: GDEP015OC1 acn_nrf52_saadc aconno_bsp
Fork of acd52832_3_Analog_In by
main.cpp@11:6c6bebdfff06, 2017-10-09 (annotated)
- Committer:
- jurica238814
- Date:
- Mon Oct 09 11:15:18 2017 +0000
- Revision:
- 11:6c6bebdfff06
- Parent:
- 10:8a9eb611624e
Diff inputs adc works ok.; Problem with this version: to high input voltage on single input (>3V3). Has to be sold in hardware.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jurica238814 | 11:6c6bebdfff06 | 1 | /* |
jurica238814 | 11:6c6bebdfff06 | 2 | * Copyright (c) 2017 Aconno. All Rights Reserved. |
jurica238814 | 0:dc96b5c8e3f6 | 3 | * |
jurica238814 | 0:dc96b5c8e3f6 | 4 | * Licensees are granted free, non-transferable use of the information. NO |
jurica238814 | 0:dc96b5c8e3f6 | 5 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
jurica238814 | 0:dc96b5c8e3f6 | 6 | * the file. |
jurica238814 | 0:dc96b5c8e3f6 | 7 | */ |
jurica238814 | 0:dc96b5c8e3f6 | 8 | |
jurica238814 | 0:dc96b5c8e3f6 | 9 | #include "mbed.h" |
jurica238814 | 0:dc96b5c8e3f6 | 10 | #include "acd52832_bsp.h" |
jurica238814 | 0:dc96b5c8e3f6 | 11 | #include "GDEP015OC1.h" |
jurica238814 | 5:6566725c8835 | 12 | #include "pictures.h" |
jurica238814 | 10:8a9eb611624e | 13 | #include "acd_nrf52_saadc.h" |
jurica238814 | 0:dc96b5c8e3f6 | 14 | |
jurica238814 | 10:8a9eb611624e | 15 | #define DEBUG (1) |
jurica238814 | 10:8a9eb611624e | 16 | #define ADC_MAX_VALUE (8192) |
jurica238814 | 10:8a9eb611624e | 17 | #define ADC_REF_VOLTAGE (3.3f) |
jurica238814 | 10:8a9eb611624e | 18 | #define VOLTAGE_DIVIDER_RATION (7.0606) |
jurica238814 | 8:c9f0aea93832 | 19 | #define VOLTAGE_LOSS (0.4) |
jurica238814 | 5:6566725c8835 | 20 | #define CURRENT_FACTOR (36.0) |
jurica238814 | 9:eef3ea422bfe | 21 | #define BATTERY_CHARGED_V (13) |
jurica238814 | 8:c9f0aea93832 | 22 | #define BATTERY_MAX_V (12.6) |
jurica238814 | 8:c9f0aea93832 | 23 | #define BATTERY_MIN_V (11.85) |
jurica238814 | 8:c9f0aea93832 | 24 | #define BATTERY_STEP (0.15) |
jurica238814 | 6:e848c82b5248 | 25 | #define QUICK_CURRENT (float)(0.8) |
jurica238814 | 6:e848c82b5248 | 26 | #define LOW_CURRENT (float)(0.4) |
jurica238814 | 6:e848c82b5248 | 27 | #define NO_CURRENT (float)(0.01) |
jurica238814 | 10:8a9eb611624e | 28 | #define NUM_OF_MEASUREMENTS (1) |
jurica238814 | 6:e848c82b5248 | 29 | #define NO_CURRENT_STATE (0) |
jurica238814 | 6:e848c82b5248 | 30 | #define LOW_CURRENT_STATE (1) |
jurica238814 | 6:e848c82b5248 | 31 | #define QUICK_CURRENT_STATE (2) |
jurica238814 | 5:6566725c8835 | 32 | |
jurica238814 | 9:eef3ea422bfe | 33 | #define _CH_4 (9) |
jurica238814 | 9:eef3ea422bfe | 34 | #define _CH_3 (8) |
jurica238814 | 9:eef3ea422bfe | 35 | #define _CH_2 (7) |
jurica238814 | 9:eef3ea422bfe | 36 | #define _CH_1 (6) |
jurica238814 | 6:e848c82b5248 | 37 | #define _BS_5 (5) |
jurica238814 | 6:e848c82b5248 | 38 | #define _BS_4 (4) |
jurica238814 | 6:e848c82b5248 | 39 | #define _BS_3 (3) |
jurica238814 | 6:e848c82b5248 | 40 | #define _BS_2 (2) |
jurica238814 | 6:e848c82b5248 | 41 | #define _BS_1 (1) |
jurica238814 | 6:e848c82b5248 | 42 | #define _BS_E (0) |
jurica238814 | 0:dc96b5c8e3f6 | 43 | |
jurica238814 | 10:8a9eb611624e | 44 | #define ANALOG_PIN_P (4) |
jurica238814 | 10:8a9eb611624e | 45 | #define ANALOG_PIN_N (5) |
jurica238814 | 10:8a9eb611624e | 46 | #define NUM_OF_DIFF_ADCs (1) |
jurica238814 | 0:dc96b5c8e3f6 | 47 | |
jurica238814 | 10:8a9eb611624e | 48 | SPI spi(PIN_EPD_MOSI, NC, PIN_EPD_SCK, NC); |
jurica238814 | 10:8a9eb611624e | 49 | GDEP015OC1 epd = GDEP015OC1(spi, PIN_EPD_CS, PIN_EPD_DC, PIN_EPD_RST, PIN_EPD_BUSY); |
jurica238814 | 0:dc96b5c8e3f6 | 50 | |
jurica238814 | 6:e848c82b5248 | 51 | uint8_t get_battery_level(float battery_voltage){ |
jurica238814 | 9:eef3ea422bfe | 52 | if (battery_voltage > BATTERY_CHARGED_V * 4){ |
jurica238814 | 9:eef3ea422bfe | 53 | return _CH_4; |
jurica238814 | 9:eef3ea422bfe | 54 | } |
jurica238814 | 9:eef3ea422bfe | 55 | else if ((battery_voltage > BATTERY_CHARGED_V + BATTERY_STEP * 3) && (battery_voltage > BATTERY_CHARGED_V + BATTERY_STEP * 4)){ |
jurica238814 | 9:eef3ea422bfe | 56 | return _CH_3; |
jurica238814 | 9:eef3ea422bfe | 57 | } |
jurica238814 | 9:eef3ea422bfe | 58 | else if ((battery_voltage > BATTERY_CHARGED_V + BATTERY_STEP * 2) && (battery_voltage > BATTERY_CHARGED_V + BATTERY_STEP * 3)){ |
jurica238814 | 9:eef3ea422bfe | 59 | return _CH_2; |
jurica238814 | 9:eef3ea422bfe | 60 | } |
jurica238814 | 9:eef3ea422bfe | 61 | else if ((battery_voltage > BATTERY_CHARGED_V + BATTERY_STEP * 1) && (battery_voltage > BATTERY_CHARGED_V + BATTERY_STEP * 2)){ |
jurica238814 | 9:eef3ea422bfe | 62 | return _CH_1; |
jurica238814 | 9:eef3ea422bfe | 63 | } |
jurica238814 | 9:eef3ea422bfe | 64 | else if((battery_voltage > BATTERY_MAX_V - BATTERY_STEP) && (battery_voltage < BATTERY_CHARGED_V)){ |
jurica238814 | 6:e848c82b5248 | 65 | return _BS_5; |
jurica238814 | 6:e848c82b5248 | 66 | } |
jurica238814 | 6:e848c82b5248 | 67 | else if((battery_voltage > BATTERY_MAX_V - BATTERY_STEP * 2) && (battery_voltage < BATTERY_MAX_V - BATTERY_STEP * 1)){ |
jurica238814 | 6:e848c82b5248 | 68 | return _BS_4; |
jurica238814 | 6:e848c82b5248 | 69 | } |
jurica238814 | 6:e848c82b5248 | 70 | else if((battery_voltage > BATTERY_MAX_V - BATTERY_STEP * 3) && (battery_voltage < BATTERY_MAX_V - BATTERY_STEP * 2)){ |
jurica238814 | 6:e848c82b5248 | 71 | return _BS_3; |
jurica238814 | 6:e848c82b5248 | 72 | } |
jurica238814 | 6:e848c82b5248 | 73 | else if((battery_voltage > BATTERY_MAX_V - BATTERY_STEP * 4) && (battery_voltage < BATTERY_MAX_V - BATTERY_STEP * 3)){ |
jurica238814 | 6:e848c82b5248 | 74 | return _BS_2; |
jurica238814 | 6:e848c82b5248 | 75 | } |
jurica238814 | 6:e848c82b5248 | 76 | else if((battery_voltage > BATTERY_MAX_V - BATTERY_STEP * 5) && (battery_voltage < BATTERY_MAX_V - BATTERY_STEP * 4)){ |
jurica238814 | 6:e848c82b5248 | 77 | return _BS_1; |
jurica238814 | 6:e848c82b5248 | 78 | } |
jurica238814 | 6:e848c82b5248 | 79 | else if(battery_voltage < BATTERY_MAX_V - BATTERY_STEP * 5){ |
jurica238814 | 6:e848c82b5248 | 80 | return _BS_E; |
jurica238814 | 6:e848c82b5248 | 81 | } |
jurica238814 | 6:e848c82b5248 | 82 | return 0; |
jurica238814 | 6:e848c82b5248 | 83 | } |
jurica238814 | 6:e848c82b5248 | 84 | |
jurica238814 | 6:e848c82b5248 | 85 | uint8_t get_current_level(float current_value, uint8_t usb_state){ |
jurica238814 | 6:e848c82b5248 | 86 | if(current_value < NO_CURRENT) |
jurica238814 | 6:e848c82b5248 | 87 | return NO_CURRENT_STATE; |
jurica238814 | 6:e848c82b5248 | 88 | else if(current_value > NO_CURRENT && current_value < LOW_CURRENT) |
jurica238814 | 6:e848c82b5248 | 89 | return LOW_CURRENT_STATE; |
jurica238814 | 6:e848c82b5248 | 90 | else if(current_value > LOW_CURRENT && current_value < QUICK_CURRENT){ |
jurica238814 | 6:e848c82b5248 | 91 | // Determine current charger state depends on previous state |
jurica238814 | 6:e848c82b5248 | 92 | if(usb_state == LOW_CURRENT_STATE) |
jurica238814 | 6:e848c82b5248 | 93 | return LOW_CURRENT_STATE; |
jurica238814 | 6:e848c82b5248 | 94 | else if(usb_state == QUICK_CURRENT_STATE) |
jurica238814 | 6:e848c82b5248 | 95 | return QUICK_CURRENT_STATE; |
jurica238814 | 6:e848c82b5248 | 96 | } |
jurica238814 | 6:e848c82b5248 | 97 | else if(current_value > QUICK_CURRENT) |
jurica238814 | 6:e848c82b5248 | 98 | return QUICK_CURRENT_STATE; |
jurica238814 | 6:e848c82b5248 | 99 | return NO_CURRENT_STATE; |
jurica238814 | 6:e848c82b5248 | 100 | } |
jurica238814 | 6:e848c82b5248 | 101 | |
jurica238814 | 0:dc96b5c8e3f6 | 102 | int main(){ |
jurica238814 | 10:8a9eb611624e | 103 | NRF52_SAADC *diffADCs[NUM_OF_DIFF_ADCs]; |
jurica238814 | 10:8a9eb611624e | 104 | /* Declare your ADCs here */ |
jurica238814 | 10:8a9eb611624e | 105 | /* Change NUM_OF_DIFF_ADCs in the header */ |
jurica238814 | 10:8a9eb611624e | 106 | diffADCs[0] = new NRF52_SAADC(ANALOG_PIN_P, ANALOG_PIN_N); |
jurica238814 | 10:8a9eb611624e | 107 | |
jurica238814 | 11:6c6bebdfff06 | 108 | //NRF52_SAADC usb1(7); // P29, AIN5 |
jurica238814 | 11:6c6bebdfff06 | 109 | //NRF52_SAADC usb2(6); // p30, AIN6 |
jurica238814 | 10:8a9eb611624e | 110 | |
jurica238814 | 5:6566725c8835 | 111 | char low_string[25] = "LOW"; |
jurica238814 | 5:6566725c8835 | 112 | char quick_string[25] = "QUICK"; |
jurica238814 | 4:f6f94ef38e6a | 113 | float adc1_mean=0, adc2_mean=0, adc3_mean=0; |
jurica238814 | 5:6566725c8835 | 114 | float battery_voltage = 0; |
jurica238814 | 5:6566725c8835 | 115 | float usb1_current = 0, usb2_current = 0; |
jurica238814 | 4:f6f94ef38e6a | 116 | int count = 0; |
jurica238814 | 6:e848c82b5248 | 117 | uint8_t battery_level = 0; |
jurica238814 | 6:e848c82b5248 | 118 | uint8_t old_battery_level; |
jurica238814 | 6:e848c82b5248 | 119 | uint8_t usb1_current_state = 0, usb2_current_state = 0; |
jurica238814 | 6:e848c82b5248 | 120 | uint8_t usb1_old_state = 0, usb2_old_state = 0; |
jurica238814 | 6:e848c82b5248 | 121 | uint8_t change_flag = 1; |
jurica238814 | 6:e848c82b5248 | 122 | |
jurica238814 | 6:e848c82b5248 | 123 | #if DEBUG |
jurica238814 | 6:e848c82b5248 | 124 | char buffer[25] = {0}; |
jurica238814 | 8:c9f0aea93832 | 125 | float old_battery_voltage = 0; |
jurica238814 | 8:c9f0aea93832 | 126 | float old_usb1_current = 0; |
jurica238814 | 8:c9f0aea93832 | 127 | float old_usb2_current = 0; |
jurica238814 | 6:e848c82b5248 | 128 | #endif |
jurica238814 | 10:8a9eb611624e | 129 | |
jurica238814 | 5:6566725c8835 | 130 | epd.empty(); |
jurica238814 | 5:6566725c8835 | 131 | epd.writeFull(); |
jurica238814 | 6:e848c82b5248 | 132 | |
jurica238814 | 0:dc96b5c8e3f6 | 133 | while(true){ |
jurica238814 | 0:dc96b5c8e3f6 | 134 | |
jurica238814 | 10:8a9eb611624e | 135 | adc1_mean += diffADCs[0]->read(); |
jurica238814 | 11:6c6bebdfff06 | 136 | adc2_mean += 1; //usb1.read(); |
jurica238814 | 11:6c6bebdfff06 | 137 | adc3_mean += 1; //usb2.read(); |
jurica238814 | 4:f6f94ef38e6a | 138 | count ++; |
jurica238814 | 8:c9f0aea93832 | 139 | |
jurica238814 | 6:e848c82b5248 | 140 | if (count == NUM_OF_MEASUREMENTS){ |
jurica238814 | 6:e848c82b5248 | 141 | |
jurica238814 | 6:e848c82b5248 | 142 | adc1_mean /= NUM_OF_MEASUREMENTS; |
jurica238814 | 6:e848c82b5248 | 143 | adc2_mean /= NUM_OF_MEASUREMENTS; |
jurica238814 | 6:e848c82b5248 | 144 | adc3_mean /= NUM_OF_MEASUREMENTS; |
jurica238814 | 5:6566725c8835 | 145 | count = 0; |
jurica238814 | 8:c9f0aea93832 | 146 | |
jurica238814 | 10:8a9eb611624e | 147 | //voltage[i] = ((float)(diffADCs[i]->read()))*(3.3f/8192.0); // Convert raw data into voltage |
jurica238814 | 10:8a9eb611624e | 148 | battery_voltage = ((float)(diffADCs[0]->read()*(3.3f/8192.0))); |
jurica238814 | 11:6c6bebdfff06 | 149 | //battery_voltage = ((float)(diffADCs[0]->read()*(3.3f/8192.0))); |
jurica238814 | 10:8a9eb611624e | 150 | //battery_voltage = adc1_mean*(ADC_REF_VOLTAGE/ADC_MAX_VALUE); |
jurica238814 | 10:8a9eb611624e | 151 | usb1_current = (adc2_mean*(ADC_REF_VOLTAGE/(ADC_MAX_VALUE*2))) * CURRENT_FACTOR; |
jurica238814 | 10:8a9eb611624e | 152 | usb2_current = (adc3_mean*(ADC_REF_VOLTAGE/(ADC_MAX_VALUE*2))) * CURRENT_FACTOR; |
jurica238814 | 6:e848c82b5248 | 153 | |
jurica238814 | 6:e848c82b5248 | 154 | battery_level = get_battery_level(battery_voltage); |
jurica238814 | 8:c9f0aea93832 | 155 | if(battery_level != old_battery_level || change_flag){ |
jurica238814 | 8:c9f0aea93832 | 156 | |
jurica238814 | 6:e848c82b5248 | 157 | old_battery_level = battery_level; |
jurica238814 | 6:e848c82b5248 | 158 | change_flag = 1; |
jurica238814 | 6:e848c82b5248 | 159 | switch(battery_level){ |
jurica238814 | 6:e848c82b5248 | 160 | case(0):{ |
jurica238814 | 6:e848c82b5248 | 161 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 6:e848c82b5248 | 162 | epd.fill(BS_E[x], x); |
jurica238814 | 6:e848c82b5248 | 163 | break; |
jurica238814 | 6:e848c82b5248 | 164 | } |
jurica238814 | 6:e848c82b5248 | 165 | case(1):{ |
jurica238814 | 6:e848c82b5248 | 166 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 6:e848c82b5248 | 167 | epd.fill(BS_1[x], x); |
jurica238814 | 6:e848c82b5248 | 168 | break; |
jurica238814 | 6:e848c82b5248 | 169 | } |
jurica238814 | 6:e848c82b5248 | 170 | case(2):{ |
jurica238814 | 6:e848c82b5248 | 171 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 6:e848c82b5248 | 172 | epd.fill(BS_2[x], x); |
jurica238814 | 6:e848c82b5248 | 173 | break; |
jurica238814 | 6:e848c82b5248 | 174 | } |
jurica238814 | 6:e848c82b5248 | 175 | case(3):{ |
jurica238814 | 6:e848c82b5248 | 176 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 6:e848c82b5248 | 177 | epd.fill(BS_3[x], x); |
jurica238814 | 6:e848c82b5248 | 178 | break; |
jurica238814 | 6:e848c82b5248 | 179 | } |
jurica238814 | 6:e848c82b5248 | 180 | case(4):{ |
jurica238814 | 6:e848c82b5248 | 181 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 6:e848c82b5248 | 182 | epd.fill(BS_4[x], x); |
jurica238814 | 6:e848c82b5248 | 183 | break; |
jurica238814 | 6:e848c82b5248 | 184 | } |
jurica238814 | 6:e848c82b5248 | 185 | case(5):{ |
jurica238814 | 6:e848c82b5248 | 186 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 6:e848c82b5248 | 187 | epd.fill(BS_5[x], x); |
jurica238814 | 6:e848c82b5248 | 188 | break; |
jurica238814 | 6:e848c82b5248 | 189 | } |
jurica238814 | 9:eef3ea422bfe | 190 | case(6):{ |
jurica238814 | 9:eef3ea422bfe | 191 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 9:eef3ea422bfe | 192 | epd.fill(charged_1[x], x); |
jurica238814 | 9:eef3ea422bfe | 193 | break; |
jurica238814 | 9:eef3ea422bfe | 194 | } |
jurica238814 | 9:eef3ea422bfe | 195 | case(7):{ |
jurica238814 | 9:eef3ea422bfe | 196 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 9:eef3ea422bfe | 197 | epd.fill(charged_2[x], x); |
jurica238814 | 9:eef3ea422bfe | 198 | break; |
jurica238814 | 9:eef3ea422bfe | 199 | } |
jurica238814 | 9:eef3ea422bfe | 200 | case(8):{ |
jurica238814 | 9:eef3ea422bfe | 201 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 9:eef3ea422bfe | 202 | epd.fill(charged_3[x], x); |
jurica238814 | 9:eef3ea422bfe | 203 | break; |
jurica238814 | 9:eef3ea422bfe | 204 | } |
jurica238814 | 9:eef3ea422bfe | 205 | case(9):{ |
jurica238814 | 9:eef3ea422bfe | 206 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 9:eef3ea422bfe | 207 | epd.fill(charged_4[x], x); |
jurica238814 | 9:eef3ea422bfe | 208 | break; |
jurica238814 | 9:eef3ea422bfe | 209 | } |
jurica238814 | 6:e848c82b5248 | 210 | default: break; |
jurica238814 | 6:e848c82b5248 | 211 | } |
jurica238814 | 5:6566725c8835 | 212 | epd.write(); |
jurica238814 | 5:6566725c8835 | 213 | } |
jurica238814 | 5:6566725c8835 | 214 | |
jurica238814 | 6:e848c82b5248 | 215 | usb1_current_state = get_current_level(usb1_current, usb1_old_state); |
jurica238814 | 6:e848c82b5248 | 216 | usb2_current_state = get_current_level(usb2_current, usb2_old_state); |
jurica238814 | 6:e848c82b5248 | 217 | |
jurica238814 | 6:e848c82b5248 | 218 | if((usb1_old_state != usb1_current_state) || change_flag){ |
jurica238814 | 6:e848c82b5248 | 219 | usb1_old_state = usb1_current_state; |
jurica238814 | 6:e848c82b5248 | 220 | switch(usb1_current_state){ |
jurica238814 | 6:e848c82b5248 | 221 | case(NO_CURRENT_STATE):{ |
jurica238814 | 6:e848c82b5248 | 222 | epd.writeString(quick_string, 25, 180, 1); // Delete the old state |
jurica238814 | 6:e848c82b5248 | 223 | epd.writeString(low_string, 25, 180, 1); |
jurica238814 | 6:e848c82b5248 | 224 | break; |
jurica238814 | 6:e848c82b5248 | 225 | } |
jurica238814 | 6:e848c82b5248 | 226 | case(LOW_CURRENT_STATE):{ |
jurica238814 | 6:e848c82b5248 | 227 | epd.writeString(quick_string, 25, 180, 1); // Delete the old state |
jurica238814 | 6:e848c82b5248 | 228 | epd.writeString(low_string, 25, 180, 0); |
jurica238814 | 6:e848c82b5248 | 229 | break; |
jurica238814 | 6:e848c82b5248 | 230 | } |
jurica238814 | 6:e848c82b5248 | 231 | case(QUICK_CURRENT_STATE):{ |
jurica238814 | 6:e848c82b5248 | 232 | epd.writeString(low_string, 25, 180, 1); // Delete the old state |
jurica238814 | 6:e848c82b5248 | 233 | epd.writeString(quick_string, 25, 180, 0); |
jurica238814 | 6:e848c82b5248 | 234 | break; |
jurica238814 | 6:e848c82b5248 | 235 | } |
jurica238814 | 6:e848c82b5248 | 236 | default: break; |
jurica238814 | 6:e848c82b5248 | 237 | } |
jurica238814 | 6:e848c82b5248 | 238 | epd.write(); // Write string to the EPD |
jurica238814 | 5:6566725c8835 | 239 | } |
jurica238814 | 5:6566725c8835 | 240 | |
jurica238814 | 6:e848c82b5248 | 241 | if((usb2_old_state != usb2_current_state) || change_flag){ |
jurica238814 | 6:e848c82b5248 | 242 | usb2_old_state = usb2_current_state; |
jurica238814 | 6:e848c82b5248 | 243 | switch(usb2_current_state){ |
jurica238814 | 6:e848c82b5248 | 244 | case(NO_CURRENT_STATE):{ |
jurica238814 | 6:e848c82b5248 | 245 | epd.writeString(low_string, 135, 180, 1); // Delete the old state |
jurica238814 | 6:e848c82b5248 | 246 | epd.writeString(quick_string, 135, 180, 1); // Delete the old state |
jurica238814 | 6:e848c82b5248 | 247 | break; |
jurica238814 | 6:e848c82b5248 | 248 | } |
jurica238814 | 6:e848c82b5248 | 249 | case(LOW_CURRENT_STATE):{ |
jurica238814 | 6:e848c82b5248 | 250 | epd.writeString(quick_string, 135, 180, 1); // Delete the old state |
jurica238814 | 6:e848c82b5248 | 251 | epd.writeString(low_string, 135, 180, 0); |
jurica238814 | 6:e848c82b5248 | 252 | break; |
jurica238814 | 6:e848c82b5248 | 253 | } |
jurica238814 | 6:e848c82b5248 | 254 | case(QUICK_CURRENT_STATE):{ |
jurica238814 | 6:e848c82b5248 | 255 | epd.writeString(low_string, 135, 180, 1); // Delete the old state |
jurica238814 | 6:e848c82b5248 | 256 | epd.writeString(quick_string, 135, 180, 0); |
jurica238814 | 6:e848c82b5248 | 257 | break; |
jurica238814 | 6:e848c82b5248 | 258 | } |
jurica238814 | 6:e848c82b5248 | 259 | default: break; |
jurica238814 | 6:e848c82b5248 | 260 | } |
jurica238814 | 6:e848c82b5248 | 261 | epd.write(); // Write string to the EPD |
jurica238814 | 6:e848c82b5248 | 262 | change_flag = 0; |
jurica238814 | 5:6566725c8835 | 263 | } |
jurica238814 | 6:e848c82b5248 | 264 | |
jurica238814 | 4:f6f94ef38e6a | 265 | |
jurica238814 | 8:c9f0aea93832 | 266 | #if DEBUG |
jurica238814 | 5:6566725c8835 | 267 | // Print voltage and current values in debug mode |
jurica238814 | 8:c9f0aea93832 | 268 | sprintf(buffer, "Battery: %5.5fV", old_battery_voltage); // Create a string |
jurica238814 | 8:c9f0aea93832 | 269 | epd.writeString(buffer,25,95,1); // Write new data to the buffer |
jurica238814 | 8:c9f0aea93832 | 270 | epd.write(); // Write string to the EPD |
jurica238814 | 8:c9f0aea93832 | 271 | old_battery_voltage = battery_voltage; |
jurica238814 | 8:c9f0aea93832 | 272 | |
jurica238814 | 8:c9f0aea93832 | 273 | sprintf(buffer, "Battery: %5.5fV", battery_voltage); // Create a string |
jurica238814 | 5:6566725c8835 | 274 | epd.writeString(buffer,25,95,0); // Write new data to the buffer |
jurica238814 | 8:c9f0aea93832 | 275 | |
jurica238814 | 8:c9f0aea93832 | 276 | sprintf(buffer, "USB1: %5.5f", old_usb1_current); // Create a string |
jurica238814 | 8:c9f0aea93832 | 277 | epd.writeString(buffer,5,190,1); // Write new data to the buffer |
jurica238814 | 8:c9f0aea93832 | 278 | old_usb1_current = usb1_current; |
jurica238814 | 8:c9f0aea93832 | 279 | sprintf(buffer, "USB1: %5.5f", usb1_current); // Create a string |
jurica238814 | 5:6566725c8835 | 280 | epd.writeString(buffer,5,190,0); // Write new data to the buffer |
jurica238814 | 6:e848c82b5248 | 281 | |
jurica238814 | 8:c9f0aea93832 | 282 | sprintf(buffer, "USB2: %5.5fA", old_usb2_current); // Create a string |
jurica238814 | 8:c9f0aea93832 | 283 | epd.writeString(buffer,105,190,1); // Write new data to the buffer |
jurica238814 | 8:c9f0aea93832 | 284 | old_usb2_current = usb2_current; |
jurica238814 | 8:c9f0aea93832 | 285 | sprintf(buffer, "USB2: %5.5fA", usb2_current); // Create a string |
jurica238814 | 5:6566725c8835 | 286 | epd.writeString(buffer,105,190,0); // Write new data to the buffer |
jurica238814 | 8:c9f0aea93832 | 287 | |
jurica238814 | 6:e848c82b5248 | 288 | epd.write(); |
jurica238814 | 5:6566725c8835 | 289 | #endif |
jurica238814 | 4:f6f94ef38e6a | 290 | |
jurica238814 | 4:f6f94ef38e6a | 291 | adc1_mean = 0; |
jurica238814 | 4:f6f94ef38e6a | 292 | adc2_mean = 0; |
jurica238814 | 4:f6f94ef38e6a | 293 | adc3_mean = 0; |
jurica238814 | 4:f6f94ef38e6a | 294 | } |
jurica238814 | 0:dc96b5c8e3f6 | 295 | } |
jurica238814 | 0:dc96b5c8e3f6 | 296 | } |