Changes done in ECG and BT
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of merged_code2_20sept_2017_4th_oct_2017 by
battery.cpp@45:067673dae242, 2017-09-12 (annotated)
- Committer:
- nikitateggi
- Date:
- Tue Sep 12 10:08:04 2017 +0000
- Revision:
- 45:067673dae242
- Parent:
- 37:92fcbf22bf91
added bluetooth ack timeout, batterymonitoring and pid tracking in sd card
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nikitateggi | 22:ffa88619551d | 1 | #include "mbed.h" |
nikitateggi | 22:ffa88619551d | 2 | #include "battery.h" |
avp2417 | 37:92fcbf22bf91 | 3 | #include "display_modules.h" |
nikitateggi | 45:067673dae242 | 4 | |
nikitateggi | 45:067673dae242 | 5 | #define BATTERY_PIN PTB1 // Battery Pin |
nikitateggi | 45:067673dae242 | 6 | #define BATTERY_MAX_OPERATING_VOLTAGE (float)3.3 // Battery Max Operating Voltage |
nikitateggi | 45:067673dae242 | 7 | #define BATTERY_INTERMEDIATE_HIGH_VOLTAGE (float)3.64 // Battery Full Voltage |
nikitateggi | 45:067673dae242 | 8 | #define BATTERY_MEDIUM_VOLTAGE (float)3.57 // battery Medium Voltage |
nikitateggi | 45:067673dae242 | 9 | #define BATTERY_LOW_VOLTAGE (float)3.53 // Battery LOW Voltage |
nikitateggi | 45:067673dae242 | 10 | |
nikitateggi | 45:067673dae242 | 11 | #define BATTERY_SCREEN_CHARGE_CONDITION 0 |
nikitateggi | 45:067673dae242 | 12 | #define BATTERY_LOW_CHARGE_CONDITION 1 |
nikitateggi | 45:067673dae242 | 13 | #define BATTERY_CRITICALLY_LOW_CHARGE_CONDITION 2 |
nikitateggi | 45:067673dae242 | 14 | #define BATTERY_SCREEN_NO_CHARGE_CONDITION 3 |
nikitateggi | 45:067673dae242 | 15 | |
nikitateggi | 45:067673dae242 | 16 | static uint8_t battery_voltage_condition = 0; |
nikitateggi | 45:067673dae242 | 17 | |
nikitateggi | 45:067673dae242 | 18 | |
nikitateggi | 45:067673dae242 | 19 | AnalogIn A(BATTERY_PIN); |
nikitateggi | 45:067673dae242 | 20 | Serial battery(USBTX, USBRX); |
nikitateggi | 45:067673dae242 | 21 | |
nikitateggi | 45:067673dae242 | 22 | /* Function : To Monitor Battery Voltage |
nikitateggi | 45:067673dae242 | 23 | returns : void |
nikitateggi | 22:ffa88619551d | 24 | |
nikitateggi | 45:067673dae242 | 25 | */ |
nikitateggi | 45:067673dae242 | 26 | |
nikitateggi | 45:067673dae242 | 27 | //uint8_t battery_condition=0; |
nikitateggi | 45:067673dae242 | 28 | void battery_monitor() |
nikitateggi | 45:067673dae242 | 29 | { |
nikitateggi | 45:067673dae242 | 30 | |
nikitateggi | 45:067673dae242 | 31 | float b_voltage; |
nikitateggi | 45:067673dae242 | 32 | b_voltage = A.read_u16()*(BATTERY_MAX_OPERATING_VOLTAGE/65535)*2; |
nikitateggi | 45:067673dae242 | 33 | wait(0.001f); |
nikitateggi | 45:067673dae242 | 34 | battery.printf("voltage=%f",b_voltage); |
nikitateggi | 45:067673dae242 | 35 | |
nikitateggi | 45:067673dae242 | 36 | if (b_voltage >= BATTERY_INTERMEDIATE_HIGH_VOLTAGE ) |
nikitateggi | 45:067673dae242 | 37 | battery_voltage_condition = BATTERY_SCREEN_CHARGE_CONDITION; |
nikitateggi | 45:067673dae242 | 38 | |
nikitateggi | 45:067673dae242 | 39 | else if ((b_voltage < BATTERY_INTERMEDIATE_HIGH_VOLTAGE ) && (b_voltage > BATTERY_MEDIUM_VOLTAGE)) // 15% to 10% Battery voltage |
nikitateggi | 45:067673dae242 | 40 | battery_voltage_condition = BATTERY_LOW_CHARGE_CONDITION ; |
nikitateggi | 45:067673dae242 | 41 | |
nikitateggi | 45:067673dae242 | 42 | else if ((b_voltage < BATTERY_MEDIUM_VOLTAGE) && (b_voltage > BATTERY_LOW_VOLTAGE)) // 10% to 5% battery volage |
nikitateggi | 45:067673dae242 | 43 | battery_voltage_condition = BATTERY_CRITICALLY_LOW_CHARGE_CONDITION; |
nikitateggi | 45:067673dae242 | 44 | |
nikitateggi | 45:067673dae242 | 45 | else if (b_voltage < BATTERY_LOW_VOLTAGE) |
nikitateggi | 45:067673dae242 | 46 | battery_voltage_condition = BATTERY_SCREEN_NO_CHARGE_CONDITION ; |
nikitateggi | 45:067673dae242 | 47 | |
nikitateggi | 45:067673dae242 | 48 | |
nikitateggi | 45:067673dae242 | 49 | |
nikitateggi | 45:067673dae242 | 50 | |
nikitateggi | 45:067673dae242 | 51 | } |
nikitateggi | 45:067673dae242 | 52 | |
nikitateggi | 45:067673dae242 | 53 | /* Function: To Display Battery Status |
nikitateggi | 45:067673dae242 | 54 | returns : void |
nikitateggi | 45:067673dae242 | 55 | */ |
nikitateggi | 45:067673dae242 | 56 | |
nikitateggi | 45:067673dae242 | 57 | void battery_status_display() |
nikitateggi | 45:067673dae242 | 58 | { |
nikitateggi | 45:067673dae242 | 59 | if (battery_voltage_condition == BATTERY_SCREEN_CHARGE_CONDITION) |
nikitateggi | 45:067673dae242 | 60 | battery_screen_charge(); |
nikitateggi | 45:067673dae242 | 61 | |
nikitateggi | 45:067673dae242 | 62 | else if (battery_voltage_condition == BATTERY_LOW_CHARGE_CONDITION) |
nikitateggi | 45:067673dae242 | 63 | battery_low_charge(); |
avp2417 | 37:92fcbf22bf91 | 64 | |
nikitateggi | 45:067673dae242 | 65 | else if (battery_voltage_condition == BATTERY_CRITICALLY_LOW_CHARGE_CONDITION) |
nikitateggi | 45:067673dae242 | 66 | battery_critically_low_charge(); |
nikitateggi | 45:067673dae242 | 67 | |
nikitateggi | 45:067673dae242 | 68 | else if (battery_voltage_condition == BATTERY_SCREEN_NO_CHARGE_CONDITION) { |
nikitateggi | 45:067673dae242 | 69 | do |
nikitateggi | 45:067673dae242 | 70 | { |
nikitateggi | 45:067673dae242 | 71 | battery_screen_nocharge(); |
nikitateggi | 45:067673dae242 | 72 | wait_ms(500); |
nikitateggi | 45:067673dae242 | 73 | } while(battery_voltage_condition == BATTERY_SCREEN_NO_CHARGE_CONDITION ); |
nikitateggi | 45:067673dae242 | 74 | |
nikitateggi | 45:067673dae242 | 75 | } |
nikitateggi | 45:067673dae242 | 76 | } |
nikitateggi | 45:067673dae242 | 77 | |
nikitateggi | 45:067673dae242 | 78 | /* Function : To get battery status depending battery voltage |
nikitateggi | 45:067673dae242 | 79 | returns : battery_voltage_condition |
nikitateggi | 45:067673dae242 | 80 | |
nikitateggi | 45:067673dae242 | 81 | */ |
nikitateggi | 45:067673dae242 | 82 | |
nikitateggi | 45:067673dae242 | 83 | uint8_t get_battery_status() |
nikitateggi | 45:067673dae242 | 84 | { |
nikitateggi | 45:067673dae242 | 85 | |
nikitateggi | 45:067673dae242 | 86 | return battery_voltage_condition; |
nikitateggi | 22:ffa88619551d | 87 | } |