Page 340 - 2
P. 340
ind %= PSENSOR_SMOOTH;
p = psum / PSENSOR_SMOOTH;
#endif
powerValue = ( conf.psensornull > p ? conf.psensornull - p : p - conf.psensornull); // do
not use abs(), it would induce implicit cast to uint and overrun
analog.amperage = ((uint32_t)powerValue * conf.pint2ma) / 100; // [100mA] //old (will
overflow for 65A: powerValue * conf.pint2ma; // [1mA]
pMeter[PMOTOR_SUM] += ((currentTime-lastRead) * (uint32_t)((uint32_t)powerValue*conf.
pint2ma))/100000; // [10 mA * msec]
lastRead = currentTime;
#endif // POWERMETER_HARD
break;
}
case 1:
{
#if defined(VBAT) && !defined(VBAT_CELLS)
static uint8_t ind = 0;
static uint16_t vvec[VBAT_SMOOTH], vsum;
uint16_t v = analogRead(V_BATPIN);
#if VBAT_SMOOTH == 1
analog.vbat = (v*VBAT_PRESCALER) / conf.vbatscale + VBAT_OFFSET; // result is Vba
tt in 0.1V steps
#else
vsum += v;
vsum -= vvec[ind];
vvec[ind++] = v;
ind %= VBAT_SMOOTH;
#if VBAT_SMOOTH == VBAT_PRESCALER
analog.vbat = vsum / conf.vbatscale + VBAT_OFFSET; // result is Vbatt in 0.1V steps
#elif VBAT_SMOOTH < VBAT_PRESCALER
analog.vbat = (vsum * (VBAT_PRESCALER/VBAT_SMOOTH)) / conf.vbatscale + VBAT
_OFFSET; // result is Vbatt in 0.1V steps
#else
analog.vbat = ((vsum /VBAT_SMOOTH) * VBAT_PRESCALER) / conf.vbatscale + VBA
T_OFFSET; // result is Vbatt in 0.1V steps
#endif
#endif
#endif // VBAT
break;
}
case 2:
{
#if defined(RX_RSSI)
static uint8_t ind = 0;
- 340 -