Elite power off when low battery[init]

This commit is contained in:
YiChin
2020-06-29 15:35:18 +08:00
parent 6cf988a54c
commit 07ebae4f64
5 changed files with 46 additions and 26 deletions
@@ -37,4 +37,19 @@ static uint8_t headstage_battery_volt2() {
return battery_volt;
}
static uint8_t headstage_battery_volt(){
uint16_t bat_volt = 0;
ReadBatVolt(spi_ADC_rxbuf);
bat_volt = (uint16_t) (spi_ADC_rxbuf[0] << 8) | (uint16_t) (spi_ADC_rxbuf[1]);
// Battery voltage < 3V, turn off Elite.
if(bat_volt < 8500 && bat_volt > 200) {
PIN_setOutputValue(pin_handle, enable_5v, 0);
}else{
PIN_setOutputValue(pin_handle, enable_5v, 1);
}
return battery_volt;
}
#endif // HEADSTAGE_BATT_H
@@ -4,9 +4,9 @@
#define VERSION_DATE_YEAR 20
#define VERSION_DATE_MONTH 6
#define VERSION_DATE_DAY 24
#define VERSION_DATE_HOUR 17
#define VERSION_DATE_MINUTE 42
#define VERSION_DATE_DAY 29
#define VERSION_DATE_HOUR 15
#define VERSION_DATE_MINUTE 35
// this is NOT the version hash !!
// it's the last version hash
@@ -1380,14 +1380,6 @@ static void update_ZM_instruction(uint8 *ins) {
cis_buf[2] = headstage_battery_volt2();
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
#define THREE_POINT_THREE_VOLT 845
if (AONBatMonBatteryVoltageGet() < THREE_POINT_THREE_VOLT){
LED_color(DARKLED, 0xFF, 0xFF, 0x00);
PIN_setOutputValue(pin_handle, enable_5v, 0); // disable 5V
headstage_power_shutdown();
}
#undef THREE_POINT_THREE_VOLT
break;
}
@@ -57,14 +57,6 @@ static void ZM_init() {
ADCGainControl(GAIN_AUTO);
elite_gptimer_open();
#define THREE_POINT_THREE_VOLT 845
if (AONBatMonBatteryVoltageGet() < THREE_POINT_THREE_VOLT){
// LED_color(DARKLED, 0xFF, 0xFF, 0x00);
// PIN_setOutputValue(pin_handle, enable_5v, 0); // disable 5V
// headstage_power_shutdown();
}
#undef THREE_POINT_THREE_VOLT
// PIN_registerIntCb(pin_handle, switch_on_callback);
// PIN_setInterrupt(pin_handle, switch_on | PIN_IRQ_POSEDGE);
}
@@ -545,18 +545,13 @@ static void SimpleBLEPeripheral_init(void) {
static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
#define CLOCK_ONE_SECOND 10000
uint16_t bat_counter = 0;
// Initialize application
SimpleBLEPeripheral_init();
headstage_init_device_info();
ZM_init();
#define THREE_POINT_THREE_VOLT 845
if (AONBatMonBatteryVoltageGet() < THREE_POINT_THREE_VOLT){
LED_color(DARKLED, 0xFF, 0xFF, 0x00);
PIN_setOutputValue(pin_handle, enable_5v, 0); // disable 5V
headstage_power_shutdown();
}
#undef THREE_POINT_THREE_VOLT
Elite_SPI_init();
WorkMode *WorkModeData = CreateWorkMode();
@@ -622,6 +617,32 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
events &= ~SBP_PERIODIC_EVT;
if (!PeriodicEvent) { // if there is no periodic event
key = PIN_getInputValue(switch_on);
if (bat_counter == CLOCK_ONE_SECOND*1) {
// #define THREE_POINT_THREE_VOLT 845
// // Battery voltage < 3.3V, turn off Elite.
// if ((AONBatMonBatteryVoltageGet() < THREE_POINT_THREE_VOLT) && (AONBatMonBatteryVoltageGet() > 256)){
// LED_color(DARKLED, 0xFF, 0xFF, 0x00);
// PIN_setOutputValue(pin_handle, enable_5v, 0); // disable 5V
// headstage_power_shutdown();
// }else{
// PIN_setOutputValue(pin_handle, enable_5v, 1);
// }
// #undef THREE_POINT_THREE_VOLT
uint16_t bat_volt = 0;
ReadBatVolt(spi_ADC_rxbuf);
bat_volt = (uint16_t) (spi_ADC_rxbuf[0] << 8) | (uint16_t) (spi_ADC_rxbuf[1]);
// Battery voltage < 3V, turn off Elite.
if(bat_volt < 8500 && bat_volt > 200) {
PIN_setOutputValue(pin_handle, enable_5v, 0);
}else{
PIN_setOutputValue(pin_handle, enable_5v, 1);
}
bat_counter = 0;
} else {
bat_counter++;
}
if (EliteOn) {
if (counter6994 < CLOCK_ONE_SECOND/2) { // counter6994 enable a IC after 35 counts
counter6994++;