Minor code cleanup
This commit is contained in:
parent
6b37b96048
commit
1ecbdf3dae
|
@ -1437,16 +1437,16 @@ static void cliSetVar(const clivalue_t *var, const int_float_value_t value)
|
||||||
switch (var->type & VALUE_TYPE_MASK) {
|
switch (var->type & VALUE_TYPE_MASK) {
|
||||||
case VAR_UINT8:
|
case VAR_UINT8:
|
||||||
case VAR_INT8:
|
case VAR_INT8:
|
||||||
*(char *)ptr = (char)value.int_value;
|
*(int8_t *)ptr = value.int_value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VAR_UINT16:
|
case VAR_UINT16:
|
||||||
case VAR_INT16:
|
case VAR_INT16:
|
||||||
*(short *)ptr = (short)value.int_value;
|
*(int16_t *)ptr = value.int_value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VAR_UINT32:
|
case VAR_UINT32:
|
||||||
*(int *)ptr = (int)value.int_value;
|
*(uint32_t *)ptr = value.int_value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VAR_FLOAT:
|
case VAR_FLOAT:
|
||||||
|
@ -1639,7 +1639,7 @@ void cliProcess(void)
|
||||||
}
|
}
|
||||||
for (; i < bufferIndex; i++)
|
for (; i < bufferIndex; i++)
|
||||||
cliWrite(cliBuffer[i]);
|
cliWrite(cliBuffer[i]);
|
||||||
} else if (!bufferIndex && c == 4) {
|
} else if (!bufferIndex && c == 4) { // CTRL-D
|
||||||
cliExit(cliBuffer);
|
cliExit(cliBuffer);
|
||||||
return;
|
return;
|
||||||
} else if (c == 12) {
|
} else if (c == 12) {
|
||||||
|
|
|
@ -92,23 +92,20 @@ void batteryInit(batteryConfig_t *initialBatteryConfig)
|
||||||
delay((32 / BATTERY_SAMPLE_COUNT) * 10);
|
delay((32 / BATTERY_SAMPLE_COUNT) * 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// autodetect cell count, going from 1S..8S
|
unsigned cells = (vbat / batteryConfig->vbatmaxcellvoltage) + 1;
|
||||||
for (i = 1; i < 8; i++) {
|
if(cells > 8) // something is wrong, we expect 8 cells maximum (and autodetection will be problematic at 6+ cells)
|
||||||
if (vbat < i * batteryConfig->vbatmaxcellvoltage)
|
cells = 8;
|
||||||
break;
|
batteryCellCount = cells;
|
||||||
}
|
|
||||||
|
|
||||||
batteryCellCount = i;
|
|
||||||
batteryWarningVoltage = batteryCellCount * batteryConfig->vbatwarningcellvoltage;
|
batteryWarningVoltage = batteryCellCount * batteryConfig->vbatwarningcellvoltage;
|
||||||
batteryCriticalVoltage = batteryCellCount * batteryConfig->vbatmincellvoltage;
|
batteryCriticalVoltage = batteryCellCount * batteryConfig->vbatmincellvoltage;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ADCVREF 33L
|
#define ADCVREF 3300 // in mV
|
||||||
int32_t currentSensorToCentiamps(uint16_t src)
|
int32_t currentSensorToCentiamps(uint16_t src)
|
||||||
{
|
{
|
||||||
int32_t millivolts;
|
int32_t millivolts;
|
||||||
|
|
||||||
millivolts = ((uint32_t)src * ADCVREF * 100) / 4095;
|
millivolts = ((uint32_t)src * ADCVREF) / 4096;
|
||||||
millivolts -= batteryConfig->currentMeterOffset;
|
millivolts -= batteryConfig->currentMeterOffset;
|
||||||
|
|
||||||
return (millivolts * 1000) / (int32_t)batteryConfig->currentMeterScale; // current in 0.01A steps
|
return (millivolts * 1000) / (int32_t)batteryConfig->currentMeterScale; // current in 0.01A steps
|
||||||
|
|
|
@ -322,13 +322,12 @@ void handleSmartPortTelemetry(void)
|
||||||
smartPortIdCnt++;
|
smartPortIdCnt++;
|
||||||
|
|
||||||
int32_t tmpi;
|
int32_t tmpi;
|
||||||
uint32_t tmpui;
|
|
||||||
static uint8_t t1Cnt = 0;
|
static uint8_t t1Cnt = 0;
|
||||||
|
|
||||||
switch(id) {
|
switch(id) {
|
||||||
case FSSP_DATAID_SPEED :
|
case FSSP_DATAID_SPEED :
|
||||||
if (sensors(SENSOR_GPS) && STATE(GPS_FIX)) {
|
if (sensors(SENSOR_GPS) && STATE(GPS_FIX)) {
|
||||||
tmpui = (GPS_speed * 36 + 36 / 2) / 100;
|
uint32_t tmpui = (GPS_speed * 36 + 36 / 2) / 100;
|
||||||
smartPortSendPackage(id, tmpui); // given in 0.1 m/s, provide in KM/H
|
smartPortSendPackage(id, tmpui); // given in 0.1 m/s, provide in KM/H
|
||||||
smartPortHasRequest = 0;
|
smartPortHasRequest = 0;
|
||||||
}
|
}
|
||||||
|
@ -355,7 +354,7 @@ void handleSmartPortTelemetry(void)
|
||||||
//case FSSP_DATAID_ADC2 :
|
//case FSSP_DATAID_ADC2 :
|
||||||
case FSSP_DATAID_LATLONG :
|
case FSSP_DATAID_LATLONG :
|
||||||
if (sensors(SENSOR_GPS) && STATE(GPS_FIX)) {
|
if (sensors(SENSOR_GPS) && STATE(GPS_FIX)) {
|
||||||
tmpui = 0;
|
uint32_t tmpui = 0;
|
||||||
// the same ID is sent twice, one for longitude, one for latitude
|
// the same ID is sent twice, one for longitude, one for latitude
|
||||||
// the MSB of the sent uint32_t helps FrSky keep track
|
// the MSB of the sent uint32_t helps FrSky keep track
|
||||||
// the even/odd bit of our counter helps us keep track
|
// the even/odd bit of our counter helps us keep track
|
||||||
|
|
Loading…
Reference in New Issue