A simple example for analog input and EPD usage.
Dependencies: GDEP015OC1 acn_nrf52_saadc aconno_bsp
Fork of acd52832_Car_battery_ch by
main.cpp@9:eef3ea422bfe, 2017-07-07 (annotated)
- Committer:
- jurica238814
- Date:
- Fri Jul 07 11:50:24 2017 +0000
- Revision:
- 9:eef3ea422bfe
- Parent:
- 8:c9f0aea93832
- Child:
- 10:8a9eb611624e
4 new images added for charged battery. Mbed-os added.
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 | 0:dc96b5c8e3f6 | 12 | |
jurica238814 | 6:e848c82b5248 | 13 | #define DEBUG (0) |
jurica238814 | 6:e848c82b5248 | 14 | #define ADC_MAX_VALUE (4095) |
jurica238814 | 5:6566725c8835 | 15 | #define ADC_REF_VOLTAGE (3.6) |
jurica238814 | 8:c9f0aea93832 | 16 | #define VOLTAGE_DIVIDER_RATION (4.42) |
jurica238814 | 8:c9f0aea93832 | 17 | #define VOLTAGE_LOSS (0.4) |
jurica238814 | 5:6566725c8835 | 18 | #define CURRENT_FACTOR (36.0) |
jurica238814 | 9:eef3ea422bfe | 19 | #define BATTERY_CHARGED_V (13) |
jurica238814 | 8:c9f0aea93832 | 20 | #define BATTERY_MAX_V (12.6) |
jurica238814 | 8:c9f0aea93832 | 21 | #define BATTERY_MIN_V (11.85) |
jurica238814 | 8:c9f0aea93832 | 22 | #define BATTERY_STEP (0.15) |
jurica238814 | 6:e848c82b5248 | 23 | #define QUICK_CURRENT (float)(0.8) |
jurica238814 | 6:e848c82b5248 | 24 | #define LOW_CURRENT (float)(0.4) |
jurica238814 | 6:e848c82b5248 | 25 | #define NO_CURRENT (float)(0.01) |
jurica238814 | 6:e848c82b5248 | 26 | #define NUM_OF_MEASUREMENTS (20) |
jurica238814 | 6:e848c82b5248 | 27 | #define NO_CURRENT_STATE (0) |
jurica238814 | 6:e848c82b5248 | 28 | #define LOW_CURRENT_STATE (1) |
jurica238814 | 6:e848c82b5248 | 29 | #define QUICK_CURRENT_STATE (2) |
jurica238814 | 5:6566725c8835 | 30 | |
jurica238814 | 9:eef3ea422bfe | 31 | #define _CH_4 (9) |
jurica238814 | 9:eef3ea422bfe | 32 | #define _CH_3 (8) |
jurica238814 | 9:eef3ea422bfe | 33 | #define _CH_2 (7) |
jurica238814 | 9:eef3ea422bfe | 34 | #define _CH_1 (6) |
jurica238814 | 6:e848c82b5248 | 35 | #define _BS_5 (5) |
jurica238814 | 6:e848c82b5248 | 36 | #define _BS_4 (4) |
jurica238814 | 6:e848c82b5248 | 37 | #define _BS_3 (3) |
jurica238814 | 6:e848c82b5248 | 38 | #define _BS_2 (2) |
jurica238814 | 6:e848c82b5248 | 39 | #define _BS_1 (1) |
jurica238814 | 6:e848c82b5248 | 40 | #define _BS_E (0) |
jurica238814 | 0:dc96b5c8e3f6 | 41 | |
jurica238814 | 0:dc96b5c8e3f6 | 42 | SPI spi(PIN_EPD_MOSI, NC, PIN_EPD_SCK, NC); |
jurica238814 | 0:dc96b5c8e3f6 | 43 | GDEP015OC1 epd = GDEP015OC1(spi, PIN_EPD_CS, PIN_EPD_DC, PIN_EPD_RST, PIN_EPD_BUSY); |
jurica238814 | 0:dc96b5c8e3f6 | 44 | |
jurica238814 | 0:dc96b5c8e3f6 | 45 | AnalogIn battery (p28); |
jurica238814 | 0:dc96b5c8e3f6 | 46 | AnalogIn usb1 (p29); |
jurica238814 | 0:dc96b5c8e3f6 | 47 | AnalogIn usb2 (p30); |
jurica238814 | 0:dc96b5c8e3f6 | 48 | |
jurica238814 | 6:e848c82b5248 | 49 | uint8_t get_battery_level(float battery_voltage){ |
jurica238814 | 9:eef3ea422bfe | 50 | if (battery_voltage > BATTERY_CHARGED_V * 4){ |
jurica238814 | 9:eef3ea422bfe | 51 | return _CH_4; |
jurica238814 | 9:eef3ea422bfe | 52 | } |
jurica238814 | 9:eef3ea422bfe | 53 | else if ((battery_voltage > BATTERY_CHARGED_V + BATTERY_STEP * 3) && (battery_voltage > BATTERY_CHARGED_V + BATTERY_STEP * 4)){ |
jurica238814 | 9:eef3ea422bfe | 54 | return _CH_3; |
jurica238814 | 9:eef3ea422bfe | 55 | } |
jurica238814 | 9:eef3ea422bfe | 56 | else if ((battery_voltage > BATTERY_CHARGED_V + BATTERY_STEP * 2) && (battery_voltage > BATTERY_CHARGED_V + BATTERY_STEP * 3)){ |
jurica238814 | 9:eef3ea422bfe | 57 | return _CH_2; |
jurica238814 | 9:eef3ea422bfe | 58 | } |
jurica238814 | 9:eef3ea422bfe | 59 | else if ((battery_voltage > BATTERY_CHARGED_V + BATTERY_STEP * 1) && (battery_voltage > BATTERY_CHARGED_V + BATTERY_STEP * 2)){ |
jurica238814 | 9:eef3ea422bfe | 60 | return _CH_1; |
jurica238814 | 9:eef3ea422bfe | 61 | } |
jurica238814 | 9:eef3ea422bfe | 62 | else if((battery_voltage > BATTERY_MAX_V - BATTERY_STEP) && (battery_voltage < BATTERY_CHARGED_V)){ |
jurica238814 | 6:e848c82b5248 | 63 | return _BS_5; |
jurica238814 | 6:e848c82b5248 | 64 | } |
jurica238814 | 6:e848c82b5248 | 65 | else if((battery_voltage > BATTERY_MAX_V - BATTERY_STEP * 2) && (battery_voltage < BATTERY_MAX_V - BATTERY_STEP * 1)){ |
jurica238814 | 6:e848c82b5248 | 66 | return _BS_4; |
jurica238814 | 6:e848c82b5248 | 67 | } |
jurica238814 | 6:e848c82b5248 | 68 | else if((battery_voltage > BATTERY_MAX_V - BATTERY_STEP * 3) && (battery_voltage < BATTERY_MAX_V - BATTERY_STEP * 2)){ |
jurica238814 | 6:e848c82b5248 | 69 | return _BS_3; |
jurica238814 | 6:e848c82b5248 | 70 | } |
jurica238814 | 6:e848c82b5248 | 71 | else if((battery_voltage > BATTERY_MAX_V - BATTERY_STEP * 4) && (battery_voltage < BATTERY_MAX_V - BATTERY_STEP * 3)){ |
jurica238814 | 6:e848c82b5248 | 72 | return _BS_2; |
jurica238814 | 6:e848c82b5248 | 73 | } |
jurica238814 | 6:e848c82b5248 | 74 | else if((battery_voltage > BATTERY_MAX_V - BATTERY_STEP * 5) && (battery_voltage < BATTERY_MAX_V - BATTERY_STEP * 4)){ |
jurica238814 | 6:e848c82b5248 | 75 | return _BS_1; |
jurica238814 | 6:e848c82b5248 | 76 | } |
jurica238814 | 6:e848c82b5248 | 77 | else if(battery_voltage < BATTERY_MAX_V - BATTERY_STEP * 5){ |
jurica238814 | 6:e848c82b5248 | 78 | return _BS_E; |
jurica238814 | 6:e848c82b5248 | 79 | } |
jurica238814 | 6:e848c82b5248 | 80 | return 0; |
jurica238814 | 6:e848c82b5248 | 81 | } |
jurica238814 | 6:e848c82b5248 | 82 | |
jurica238814 | 6:e848c82b5248 | 83 | uint8_t get_current_level(float current_value, uint8_t usb_state){ |
jurica238814 | 6:e848c82b5248 | 84 | if(current_value < NO_CURRENT) |
jurica238814 | 6:e848c82b5248 | 85 | return NO_CURRENT_STATE; |
jurica238814 | 6:e848c82b5248 | 86 | else if(current_value > NO_CURRENT && current_value < LOW_CURRENT) |
jurica238814 | 6:e848c82b5248 | 87 | return LOW_CURRENT_STATE; |
jurica238814 | 6:e848c82b5248 | 88 | else if(current_value > LOW_CURRENT && current_value < QUICK_CURRENT){ |
jurica238814 | 6:e848c82b5248 | 89 | // Determine current charger state depends on previous state |
jurica238814 | 6:e848c82b5248 | 90 | if(usb_state == LOW_CURRENT_STATE) |
jurica238814 | 6:e848c82b5248 | 91 | return LOW_CURRENT_STATE; |
jurica238814 | 6:e848c82b5248 | 92 | else if(usb_state == QUICK_CURRENT_STATE) |
jurica238814 | 6:e848c82b5248 | 93 | return QUICK_CURRENT_STATE; |
jurica238814 | 6:e848c82b5248 | 94 | } |
jurica238814 | 6:e848c82b5248 | 95 | else if(current_value > QUICK_CURRENT) |
jurica238814 | 6:e848c82b5248 | 96 | return QUICK_CURRENT_STATE; |
jurica238814 | 6:e848c82b5248 | 97 | return NO_CURRENT_STATE; |
jurica238814 | 6:e848c82b5248 | 98 | } |
jurica238814 | 6:e848c82b5248 | 99 | |
jurica238814 | 0:dc96b5c8e3f6 | 100 | int main(){ |
jurica238814 | 5:6566725c8835 | 101 | char low_string[25] = "LOW"; |
jurica238814 | 5:6566725c8835 | 102 | char quick_string[25] = "QUICK"; |
jurica238814 | 4:f6f94ef38e6a | 103 | float adc1_mean=0, adc2_mean=0, adc3_mean=0; |
jurica238814 | 5:6566725c8835 | 104 | float battery_voltage = 0; |
jurica238814 | 5:6566725c8835 | 105 | float usb1_current = 0, usb2_current = 0; |
jurica238814 | 4:f6f94ef38e6a | 106 | int count = 0; |
jurica238814 | 6:e848c82b5248 | 107 | uint8_t battery_level = 0; |
jurica238814 | 6:e848c82b5248 | 108 | uint8_t old_battery_level; |
jurica238814 | 6:e848c82b5248 | 109 | uint8_t usb1_current_state = 0, usb2_current_state = 0; |
jurica238814 | 6:e848c82b5248 | 110 | uint8_t usb1_old_state = 0, usb2_old_state = 0; |
jurica238814 | 6:e848c82b5248 | 111 | uint8_t change_flag = 1; |
jurica238814 | 6:e848c82b5248 | 112 | |
jurica238814 | 6:e848c82b5248 | 113 | #if DEBUG |
jurica238814 | 6:e848c82b5248 | 114 | char buffer[25] = {0}; |
jurica238814 | 8:c9f0aea93832 | 115 | float old_battery_voltage = 0; |
jurica238814 | 8:c9f0aea93832 | 116 | float old_usb1_current = 0; |
jurica238814 | 8:c9f0aea93832 | 117 | float old_usb2_current = 0; |
jurica238814 | 6:e848c82b5248 | 118 | #endif |
jurica238814 | 4:f6f94ef38e6a | 119 | |
jurica238814 | 4:f6f94ef38e6a | 120 | NRF_SAADC->RESOLUTION = 0x00000002; // Set 12b resolution |
jurica238814 | 5:6566725c8835 | 121 | |
jurica238814 | 5:6566725c8835 | 122 | epd.empty(); |
jurica238814 | 5:6566725c8835 | 123 | epd.writeFull(); |
jurica238814 | 6:e848c82b5248 | 124 | |
jurica238814 | 0:dc96b5c8e3f6 | 125 | while(true){ |
jurica238814 | 0:dc96b5c8e3f6 | 126 | |
jurica238814 | 4:f6f94ef38e6a | 127 | adc1_mean += battery.read_u16(); |
jurica238814 | 4:f6f94ef38e6a | 128 | adc2_mean += usb1.read_u16(); |
jurica238814 | 4:f6f94ef38e6a | 129 | adc3_mean += usb2.read_u16(); |
jurica238814 | 4:f6f94ef38e6a | 130 | count ++; |
jurica238814 | 8:c9f0aea93832 | 131 | |
jurica238814 | 6:e848c82b5248 | 132 | if (count == NUM_OF_MEASUREMENTS){ |
jurica238814 | 6:e848c82b5248 | 133 | |
jurica238814 | 6:e848c82b5248 | 134 | adc1_mean /= NUM_OF_MEASUREMENTS; |
jurica238814 | 6:e848c82b5248 | 135 | adc2_mean /= NUM_OF_MEASUREMENTS; |
jurica238814 | 6:e848c82b5248 | 136 | adc3_mean /= NUM_OF_MEASUREMENTS; |
jurica238814 | 5:6566725c8835 | 137 | count = 0; |
jurica238814 | 8:c9f0aea93832 | 138 | |
jurica238814 | 8:c9f0aea93832 | 139 | battery_voltage = adc1_mean*(ADC_REF_VOLTAGE/ADC_MAX_VALUE)*VOLTAGE_DIVIDER_RATION + VOLTAGE_LOSS; |
jurica238814 | 8:c9f0aea93832 | 140 | usb1_current = (adc2_mean*(ADC_REF_VOLTAGE/ADC_MAX_VALUE)) * CURRENT_FACTOR; |
jurica238814 | 8:c9f0aea93832 | 141 | usb2_current = (adc3_mean*(ADC_REF_VOLTAGE/ADC_MAX_VALUE)) * CURRENT_FACTOR; |
jurica238814 | 6:e848c82b5248 | 142 | |
jurica238814 | 6:e848c82b5248 | 143 | battery_level = get_battery_level(battery_voltage); |
jurica238814 | 8:c9f0aea93832 | 144 | if(battery_level != old_battery_level || change_flag){ |
jurica238814 | 8:c9f0aea93832 | 145 | |
jurica238814 | 6:e848c82b5248 | 146 | old_battery_level = battery_level; |
jurica238814 | 6:e848c82b5248 | 147 | change_flag = 1; |
jurica238814 | 6:e848c82b5248 | 148 | switch(battery_level){ |
jurica238814 | 6:e848c82b5248 | 149 | case(0):{ |
jurica238814 | 6:e848c82b5248 | 150 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 6:e848c82b5248 | 151 | epd.fill(BS_E[x], x); |
jurica238814 | 6:e848c82b5248 | 152 | break; |
jurica238814 | 6:e848c82b5248 | 153 | } |
jurica238814 | 6:e848c82b5248 | 154 | case(1):{ |
jurica238814 | 6:e848c82b5248 | 155 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 6:e848c82b5248 | 156 | epd.fill(BS_1[x], x); |
jurica238814 | 6:e848c82b5248 | 157 | break; |
jurica238814 | 6:e848c82b5248 | 158 | } |
jurica238814 | 6:e848c82b5248 | 159 | case(2):{ |
jurica238814 | 6:e848c82b5248 | 160 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 6:e848c82b5248 | 161 | epd.fill(BS_2[x], x); |
jurica238814 | 6:e848c82b5248 | 162 | break; |
jurica238814 | 6:e848c82b5248 | 163 | } |
jurica238814 | 6:e848c82b5248 | 164 | case(3):{ |
jurica238814 | 6:e848c82b5248 | 165 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 6:e848c82b5248 | 166 | epd.fill(BS_3[x], x); |
jurica238814 | 6:e848c82b5248 | 167 | break; |
jurica238814 | 6:e848c82b5248 | 168 | } |
jurica238814 | 6:e848c82b5248 | 169 | case(4):{ |
jurica238814 | 6:e848c82b5248 | 170 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 6:e848c82b5248 | 171 | epd.fill(BS_4[x], x); |
jurica238814 | 6:e848c82b5248 | 172 | break; |
jurica238814 | 6:e848c82b5248 | 173 | } |
jurica238814 | 6:e848c82b5248 | 174 | case(5):{ |
jurica238814 | 6:e848c82b5248 | 175 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 6:e848c82b5248 | 176 | epd.fill(BS_5[x], x); |
jurica238814 | 6:e848c82b5248 | 177 | break; |
jurica238814 | 6:e848c82b5248 | 178 | } |
jurica238814 | 9:eef3ea422bfe | 179 | case(6):{ |
jurica238814 | 9:eef3ea422bfe | 180 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 9:eef3ea422bfe | 181 | epd.fill(charged_1[x], x); |
jurica238814 | 9:eef3ea422bfe | 182 | break; |
jurica238814 | 9:eef3ea422bfe | 183 | } |
jurica238814 | 9:eef3ea422bfe | 184 | case(7):{ |
jurica238814 | 9:eef3ea422bfe | 185 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 9:eef3ea422bfe | 186 | epd.fill(charged_2[x], x); |
jurica238814 | 9:eef3ea422bfe | 187 | break; |
jurica238814 | 9:eef3ea422bfe | 188 | } |
jurica238814 | 9:eef3ea422bfe | 189 | case(8):{ |
jurica238814 | 9:eef3ea422bfe | 190 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 9:eef3ea422bfe | 191 | epd.fill(charged_3[x], x); |
jurica238814 | 9:eef3ea422bfe | 192 | break; |
jurica238814 | 9:eef3ea422bfe | 193 | } |
jurica238814 | 9:eef3ea422bfe | 194 | case(9):{ |
jurica238814 | 9:eef3ea422bfe | 195 | for(uint16_t x=0;x<5000;x++) |
jurica238814 | 9:eef3ea422bfe | 196 | epd.fill(charged_4[x], x); |
jurica238814 | 9:eef3ea422bfe | 197 | break; |
jurica238814 | 9:eef3ea422bfe | 198 | } |
jurica238814 | 6:e848c82b5248 | 199 | default: break; |
jurica238814 | 6:e848c82b5248 | 200 | } |
jurica238814 | 5:6566725c8835 | 201 | epd.write(); |
jurica238814 | 5:6566725c8835 | 202 | } |
jurica238814 | 5:6566725c8835 | 203 | |
jurica238814 | 6:e848c82b5248 | 204 | usb1_current_state = get_current_level(usb1_current, usb1_old_state); |
jurica238814 | 6:e848c82b5248 | 205 | usb2_current_state = get_current_level(usb2_current, usb2_old_state); |
jurica238814 | 6:e848c82b5248 | 206 | |
jurica238814 | 6:e848c82b5248 | 207 | if((usb1_old_state != usb1_current_state) || change_flag){ |
jurica238814 | 6:e848c82b5248 | 208 | usb1_old_state = usb1_current_state; |
jurica238814 | 6:e848c82b5248 | 209 | switch(usb1_current_state){ |
jurica238814 | 6:e848c82b5248 | 210 | case(NO_CURRENT_STATE):{ |
jurica238814 | 6:e848c82b5248 | 211 | epd.writeString(quick_string, 25, 180, 1); // Delete the old state |
jurica238814 | 6:e848c82b5248 | 212 | epd.writeString(low_string, 25, 180, 1); |
jurica238814 | 6:e848c82b5248 | 213 | break; |
jurica238814 | 6:e848c82b5248 | 214 | } |
jurica238814 | 6:e848c82b5248 | 215 | case(LOW_CURRENT_STATE):{ |
jurica238814 | 6:e848c82b5248 | 216 | epd.writeString(quick_string, 25, 180, 1); // Delete the old state |
jurica238814 | 6:e848c82b5248 | 217 | epd.writeString(low_string, 25, 180, 0); |
jurica238814 | 6:e848c82b5248 | 218 | break; |
jurica238814 | 6:e848c82b5248 | 219 | } |
jurica238814 | 6:e848c82b5248 | 220 | case(QUICK_CURRENT_STATE):{ |
jurica238814 | 6:e848c82b5248 | 221 | epd.writeString(low_string, 25, 180, 1); // Delete the old state |
jurica238814 | 6:e848c82b5248 | 222 | epd.writeString(quick_string, 25, 180, 0); |
jurica238814 | 6:e848c82b5248 | 223 | break; |
jurica238814 | 6:e848c82b5248 | 224 | } |
jurica238814 | 6:e848c82b5248 | 225 | default: break; |
jurica238814 | 6:e848c82b5248 | 226 | } |
jurica238814 | 6:e848c82b5248 | 227 | epd.write(); // Write string to the EPD |
jurica238814 | 5:6566725c8835 | 228 | } |
jurica238814 | 5:6566725c8835 | 229 | |
jurica238814 | 6:e848c82b5248 | 230 | if((usb2_old_state != usb2_current_state) || change_flag){ |
jurica238814 | 6:e848c82b5248 | 231 | usb2_old_state = usb2_current_state; |
jurica238814 | 6:e848c82b5248 | 232 | switch(usb2_current_state){ |
jurica238814 | 6:e848c82b5248 | 233 | case(NO_CURRENT_STATE):{ |
jurica238814 | 6:e848c82b5248 | 234 | epd.writeString(low_string, 135, 180, 1); // Delete the old state |
jurica238814 | 6:e848c82b5248 | 235 | epd.writeString(quick_string, 135, 180, 1); // Delete the old state |
jurica238814 | 6:e848c82b5248 | 236 | break; |
jurica238814 | 6:e848c82b5248 | 237 | } |
jurica238814 | 6:e848c82b5248 | 238 | case(LOW_CURRENT_STATE):{ |
jurica238814 | 6:e848c82b5248 | 239 | epd.writeString(quick_string, 135, 180, 1); // Delete the old state |
jurica238814 | 6:e848c82b5248 | 240 | epd.writeString(low_string, 135, 180, 0); |
jurica238814 | 6:e848c82b5248 | 241 | break; |
jurica238814 | 6:e848c82b5248 | 242 | } |
jurica238814 | 6:e848c82b5248 | 243 | case(QUICK_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, 0); |
jurica238814 | 6:e848c82b5248 | 246 | break; |
jurica238814 | 6:e848c82b5248 | 247 | } |
jurica238814 | 6:e848c82b5248 | 248 | default: break; |
jurica238814 | 6:e848c82b5248 | 249 | } |
jurica238814 | 6:e848c82b5248 | 250 | epd.write(); // Write string to the EPD |
jurica238814 | 6:e848c82b5248 | 251 | change_flag = 0; |
jurica238814 | 5:6566725c8835 | 252 | } |
jurica238814 | 6:e848c82b5248 | 253 | |
jurica238814 | 4:f6f94ef38e6a | 254 | |
jurica238814 | 8:c9f0aea93832 | 255 | #if DEBUG |
jurica238814 | 5:6566725c8835 | 256 | // Print voltage and current values in debug mode |
jurica238814 | 8:c9f0aea93832 | 257 | sprintf(buffer, "Battery: %5.5fV", old_battery_voltage); // Create a string |
jurica238814 | 8:c9f0aea93832 | 258 | epd.writeString(buffer,25,95,1); // Write new data to the buffer |
jurica238814 | 8:c9f0aea93832 | 259 | epd.write(); // Write string to the EPD |
jurica238814 | 8:c9f0aea93832 | 260 | old_battery_voltage = battery_voltage; |
jurica238814 | 8:c9f0aea93832 | 261 | |
jurica238814 | 8:c9f0aea93832 | 262 | sprintf(buffer, "Battery: %5.5fV", battery_voltage); // Create a string |
jurica238814 | 5:6566725c8835 | 263 | epd.writeString(buffer,25,95,0); // Write new data to the buffer |
jurica238814 | 8:c9f0aea93832 | 264 | |
jurica238814 | 8:c9f0aea93832 | 265 | sprintf(buffer, "USB1: %5.5f", old_usb1_current); // Create a string |
jurica238814 | 8:c9f0aea93832 | 266 | epd.writeString(buffer,5,190,1); // Write new data to the buffer |
jurica238814 | 8:c9f0aea93832 | 267 | old_usb1_current = usb1_current; |
jurica238814 | 8:c9f0aea93832 | 268 | sprintf(buffer, "USB1: %5.5f", usb1_current); // Create a string |
jurica238814 | 5:6566725c8835 | 269 | epd.writeString(buffer,5,190,0); // Write new data to the buffer |
jurica238814 | 6:e848c82b5248 | 270 | |
jurica238814 | 8:c9f0aea93832 | 271 | sprintf(buffer, "USB2: %5.5fA", old_usb2_current); // Create a string |
jurica238814 | 8:c9f0aea93832 | 272 | epd.writeString(buffer,105,190,1); // Write new data to the buffer |
jurica238814 | 8:c9f0aea93832 | 273 | old_usb2_current = usb2_current; |
jurica238814 | 8:c9f0aea93832 | 274 | sprintf(buffer, "USB2: %5.5fA", usb2_current); // Create a string |
jurica238814 | 5:6566725c8835 | 275 | epd.writeString(buffer,105,190,0); // Write new data to the buffer |
jurica238814 | 8:c9f0aea93832 | 276 | |
jurica238814 | 6:e848c82b5248 | 277 | epd.write(); |
jurica238814 | 5:6566725c8835 | 278 | #endif |
jurica238814 | 4:f6f94ef38e6a | 279 | |
jurica238814 | 4:f6f94ef38e6a | 280 | adc1_mean = 0; |
jurica238814 | 4:f6f94ef38e6a | 281 | adc2_mean = 0; |
jurica238814 | 4:f6f94ef38e6a | 282 | adc3_mean = 0; |
jurica238814 | 4:f6f94ef38e6a | 283 | } |
jurica238814 | 0:dc96b5c8e3f6 | 284 | } |
jurica238814 | 0:dc96b5c8e3f6 | 285 | } |