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