Changes done in ECG and BT
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of merged_code2_20sept_2017_4th_oct_2017 by
Diff: battery.cpp
- Revision:
- 45:067673dae242
- Parent:
- 37:92fcbf22bf91
diff -r 05dbea558c9a -r 067673dae242 battery.cpp --- a/battery.cpp Tue Sep 12 04:16:41 2017 +0000 +++ b/battery.cpp Tue Sep 12 10:08:04 2017 +0000 @@ -1,34 +1,87 @@ #include "mbed.h" #include "battery.h" #include "display_modules.h" -AnalogIn A(PTB1); + +#define BATTERY_PIN PTB1 // Battery Pin +#define BATTERY_MAX_OPERATING_VOLTAGE (float)3.3 // Battery Max Operating Voltage +#define BATTERY_INTERMEDIATE_HIGH_VOLTAGE (float)3.64 // Battery Full Voltage +#define BATTERY_MEDIUM_VOLTAGE (float)3.57 // battery Medium Voltage +#define BATTERY_LOW_VOLTAGE (float)3.53 // Battery LOW Voltage + +#define BATTERY_SCREEN_CHARGE_CONDITION 0 +#define BATTERY_LOW_CHARGE_CONDITION 1 +#define BATTERY_CRITICALLY_LOW_CHARGE_CONDITION 2 +#define BATTERY_SCREEN_NO_CHARGE_CONDITION 3 + +static uint8_t battery_voltage_condition = 0; + + +AnalogIn A(BATTERY_PIN); +Serial battery(USBTX, USBRX); + +/* Function : To Monitor Battery Voltage + returns : void -uint8_t battery_voltage() { -float b_voltage; -uint8_t battery_condition=0; - b_voltage = A.read_u16()*(3.3/65535)*2; - wait(0.001f); - if (b_voltage>3.64) - { - battery_screen_charge(); - battery_condition=0; - } - else if (3.605>b_voltage>3.57) ///15% to 10% - { - battery_low_charge(); - battery_condition=1; - } - else if (3.57>b_voltage>3.535) /// 10% to 5% - { - battery_critically_low_charge(); - battery_condition=2; - } - else if (3.535>b_voltage) - { - battery_screen_nocharge(); - battery_condition=3; - } - +*/ + + //uint8_t battery_condition=0; +void battery_monitor() +{ + + float b_voltage; + b_voltage = A.read_u16()*(BATTERY_MAX_OPERATING_VOLTAGE/65535)*2; + wait(0.001f); + battery.printf("voltage=%f",b_voltage); + + if (b_voltage >= BATTERY_INTERMEDIATE_HIGH_VOLTAGE ) + battery_voltage_condition = BATTERY_SCREEN_CHARGE_CONDITION; + + else if ((b_voltage < BATTERY_INTERMEDIATE_HIGH_VOLTAGE ) && (b_voltage > BATTERY_MEDIUM_VOLTAGE)) // 15% to 10% Battery voltage + battery_voltage_condition = BATTERY_LOW_CHARGE_CONDITION ; + + else if ((b_voltage < BATTERY_MEDIUM_VOLTAGE) && (b_voltage > BATTERY_LOW_VOLTAGE)) // 10% to 5% battery volage + battery_voltage_condition = BATTERY_CRITICALLY_LOW_CHARGE_CONDITION; + + else if (b_voltage < BATTERY_LOW_VOLTAGE) + battery_voltage_condition = BATTERY_SCREEN_NO_CHARGE_CONDITION ; + + + + +} + +/* Function: To Display Battery Status + returns : void +*/ + +void battery_status_display() +{ + if (battery_voltage_condition == BATTERY_SCREEN_CHARGE_CONDITION) + battery_screen_charge(); + + else if (battery_voltage_condition == BATTERY_LOW_CHARGE_CONDITION) + battery_low_charge(); -return battery_condition; + else if (battery_voltage_condition == BATTERY_CRITICALLY_LOW_CHARGE_CONDITION) + battery_critically_low_charge(); + + else if (battery_voltage_condition == BATTERY_SCREEN_NO_CHARGE_CONDITION) { + do + { + battery_screen_nocharge(); + wait_ms(500); + } while(battery_voltage_condition == BATTERY_SCREEN_NO_CHARGE_CONDITION ); + + } +} + +/* Function : To get battery status depending battery voltage + returns : battery_voltage_condition + +*/ + +uint8_t get_battery_status() +{ + + return battery_voltage_condition; } \ No newline at end of file