define fixups

This commit is contained in:
Verkehrsrot 2019-03-23 11:04:22 +01:00
parent 18ca823d92
commit b91ef3ec7e
4 changed files with 21 additions and 18 deletions

View File

@ -8,7 +8,7 @@ esp_adc_cal_characteristics_t *adc_characs =
(esp_adc_cal_characteristics_t *)calloc(
1, sizeof(esp_adc_cal_characteristics_t));
static const adc1_channel_t adc_channel = HAS_BATTERY_PROBE;
static const adc1_channel_t adc_channel = BAT_MEASURE_ADC;
static const adc_atten_t atten = ADC_ATTEN_DB_11;
static const adc_unit_t unit = ADC_UNIT_1;
#endif
@ -43,19 +43,23 @@ uint16_t read_voltage() {
}
adc_reading /= NO_OF_SAMPLES;
// Convert ADC reading to voltage in mV
uint16_t voltage =
(uint16_t)esp_adc_cal_raw_to_voltage(adc_reading, adc_characs);
#ifdef BATT_FACTOR
voltage *= BATT_FACTOR;
uint32_t voltage = esp_adc_cal_raw_to_voltage(adc_reading, adc_characs);
#ifdef BAT_VOLTAGE_DIVIDER
voltage *= BAT_VOLTAGE_DIVIDER;
#endif
return voltage;
#ifdef BAT_MEASURE_EN // turn ext. power off
digitalWrite(EXT_POWER_SW, EXT_POWER_OFF);
#endif
return (uint16_t)voltage;
#else
return 0;
#endif
}
bool batt_sufficient() {
#ifdef HAS_BATTERY_PROBE
#ifdef BAT_MEASURE_ADC
uint16_t volts = read_voltage();
return ((volts < 1000) ||
(volts > OTA_MIN_BATT)); // no battery or battery sufficient

View File

@ -180,16 +180,15 @@ void setup() {
strcat_P(features, " PSRAM");
#endif
// set low power mode to off
#ifdef HAS_LOWPOWER_SWITCH
pinMode(HAS_LOWPOWER_SWITCH, OUTPUT);
#if (LOW_POWER_ACTIVE_LOW)
digitalWrite(HAS_LOWPOWER_SWITCH, HIGH);
#else
digitalWrite(HAS_LOWPOWER_SWITCH, LOW);
// set external power mode to off
#ifdef EXT_POWER_SW
pinMode(EXT_POWER_SW, OUTPUT);
digitalWrite(EXT_POWER_SW, EXT_POWER_ON);
strcat_P(features, " VEXT");
#endif
strcat_P(features, " LPWR");
#ifdef BAT_MEASURE_EN
pinMode(BAT_MEASURE_EN, OUTPUT);
#endif
// initialize leds
@ -224,7 +223,7 @@ void setup() {
#endif
// initialize battery status
#ifdef HAS_BATTERY_PROBE
#ifdef BAT_MEASURE_ADC
strcat_P(features, " BATT");
calibrate_voltage();
batt_voltage = read_voltage();

View File

@ -13,7 +13,7 @@
#include "mbedtls/aes.h"
#include "lmic/oslmic.h"
#if defined(USE_MBEDTLS_AES)
#if defined USE_MBEDTLS_AES
void lmic_aes_encrypt(u1_t *data, u1_t *key)
{

View File

@ -373,7 +373,7 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float celsius,
buffer[cursor++] = LPP_ANALOG_INPUT;
buffer[cursor++] = highByte(volt);
buffer[cursor++] = lowByte(volt);
#endif // HAS_BATTERY_PROBE
#endif // BAT_MEASURE_ADC
#if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_TEMPERATURE_CHANNEL;