Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 10 months ago.
Can we refactor the code to read this?
Original
- define AIN_VBAT_DIV 2 resistor divider
/* gps(tx, rx, en); */ DigitalOut gps_en(PB_11); GPS gps(PB_6, PB_7, PB_11); uint32_t gps_coord_cnt;
scpi_result_t vbatQ(scpi_t* context) { bool bat_flag = false; bool BatOffState;
if(gps.en_invert == true) BatOffState = true; else BatOffState = false;
if(gps_en == BatOffState) { bat_flag = true; gps.enable(1); }
SCPI_ResultDouble(context, bat->read()*AIN_VREF*AIN_VBAT_DIV);
if(bat_flag) gps.enable(0);
return SCPI_RES_OK; }
Would this do the same?
- define AIN_VBAT_DIV 2 resistor divider
/* gps(tx, rx, en); */ DigitalOut gps_en(PB_11); GPS gps(PB_6, PB_7, PB_11); uint32_t gps_coord_cnt;
scpi_result_t vbatQ(scpi_t* context) { bool bat_flag = false;
if(gps.en_invert) { bat_flag = true; gps.enable(1); }
SCPI_ResultDouble(context, bat->read()*AIN_VREF*AIN_VBAT_DIV);
if(bat_flag) gps.enable(0);
return SCPI_RES_OK; }
Question relating to:
1 Answer
8 years, 9 months ago.
Hi Mark, To read the battery, the GPS must be enabled since it is on an analog switch controlled by GPS enable pin. Then the GPS library will take care of the inversion. Thx, Loren