8 years, 3 months ago.

Can we refactor the code to read this?

Original

  1. 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?

  1. 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:

SCPI interface to SX1272 and SX1276 SCPI

1 Answer

8 years, 2 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