Merge pull request #594 from cyberman54/development

battery level code switched to callback
This commit is contained in:
Verkehrsrot 2020-04-14 10:59:32 +02:00 committed by GitHub
commit e3a6d231e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 12 deletions

View File

@ -33,7 +33,7 @@ void os_getDevEui(u1_t *buf);
void lora_send(void *pvParameters);
void lora_enqueuedata(MessageBuffer_t *message);
void lora_queuereset(void);
void lora_setBattLevel(uint8_t batt_percent);
uint8_t myBattLevelCb(void *pUserData);
void IRAM_ATTR myEventCallback(void *pUserData, ev_t ev);
void IRAM_ATTR myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg,
size_t nMsg);
@ -41,7 +41,6 @@ void IRAM_ATTR myTxCallback(void *pUserData, int fSuccess);
const char *getSfName(rps_t rps);
const char *getBwName(rps_t rps);
const char *getCrName(rps_t rps);
// u1_t os_getBattLevel(void);
#if (VERBOSE)

View File

@ -288,7 +288,6 @@ void lora_send(void *pvParameters) {
void lora_stack_reset() {
LMIC_reset(); // reset LMIC MAC
read_battlevel(); // refresh battery value for LMIC MAC
}
esp_err_t lora_stack_init(bool do_join) {
@ -392,6 +391,8 @@ void lmictask(void *pvParameters) {
// LMIC_reset() doesn't affect callbacks, so we can do this first.
LMIC_registerRxMessageCb(myRxCallback, NULL);
LMIC_registerEventCb(myEventCallback, NULL);
// to come with future LMIC version
// LMIC_registerBattLevelCb(myBattLevelCb, NULL);
// Reset the MAC state. Session and pending data transfers will be
// discarded.
@ -470,7 +471,7 @@ void myEventCallback(void *pUserData, ev_t ev) {
ESP_LOGD(TAG, "%s", lmic_event_msg);
}
void lora_setBattLevel(uint8_t batt_percent) {
uint8_t myBattLevelCb(void *pUserData) {
// set the battery value to send by LMIC in MAC Command
// DevStatusAns. Available defines in lorabase.h:
@ -482,6 +483,7 @@ void lora_setBattLevel(uint8_t batt_percent) {
// MCMD_DEVS_BATT_MAX from bat_percent value
uint8_t lmic_batt_level;
uint8_t const batt_percent = read_battlevel();
if (batt_percent == 0)
lmic_batt_level = MCMD_DEVS_BATT_NOINFO;
@ -499,7 +501,7 @@ void lora_setBattLevel(uint8_t batt_percent) {
lmic_batt_level =
batt_percent / 100.0 * (MCMD_DEVS_BATT_MAX - MCMD_DEVS_BATT_MIN + 1);
//LMIC_setBattLevel(lmic_batt_level);
return lmic_batt_level;
}
// event EV_RXCOMPLETE message handler

View File

@ -214,8 +214,8 @@ uint8_t read_battlevel(mapFn_t mapFunction) {
// returns the estimated battery level in values 0 ... 100 [percent]
const uint16_t batt_voltage = read_voltage();
uint8_t batt_percent;
const uint16_t batt_voltage = read_voltage();
if (batt_voltage <= BAT_MIN_VOLTAGE)
batt_percent = 0;
@ -228,11 +228,6 @@ uint8_t read_battlevel(mapFn_t mapFunction) {
ESP_LOGD(TAG, "batt_voltage = %dmV / batt_percent = %d%%", batt_voltage,
batt_percent);
#if (HAS_LORA)
// to come with future LMIC version
lora_setBattLevel(batt_percent);
#endif
return batt_percent;
}