Skip to content

Commit

Permalink
fix battery readings
Browse files Browse the repository at this point in the history
  • Loading branch information
devbis committed Oct 14, 2023
1 parent 3fc45e8 commit 151f0c3
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 200 deletions.
17 changes: 10 additions & 7 deletions src/app_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,21 @@ extern "C" {


/* Voltage detect module */
/* If you want to define the VOLTAGE_DETECT_ENABLE to 1,
* and the model of the development board is B91 evk or dongle,
* be sure to connect GPIO_PB0 to VCC.
/* If VOLTAGE_DETECT_ENABLE is set,
* 1) if MCU_CORE_826x is defined, the DRV_ADC_VBAT_MODE mode is used by default,
* and there is no need to configure the detection IO port;
* 2) if MCU_CORE_8258 or MCU_CORE_8278 is defined, the DRV_ADC_VBAT_MODE mode is used by default,
* we need to configure the detection IO port, and the IO must be in a floating state.
* 3) if MCU_CORE_B91 is defined, the DRV_ADC_BASE_MODE mode is used by default,
* we need to configure the detection IO port, and the IO must be connected to the target under test,
* such as VCC.
*/
#define VOLTAGE_DETECT_ENABLE 0

#define VOLTAGE_DETECT_ENABLE 1

#if defined(MCU_CORE_826x)
#define VOLTAGE_DETECT_ADC_PIN 0
#elif defined(MCU_CORE_8258) || defined(MCU_CORE_8278)
#define VOLTAGE_DETECT_ADC_PIN GPIO_PB5
#define VOLTAGE_DETECT_ADC_PIN GPIO_PC5
#elif defined(MCU_CORE_B91)
#define VOLTAGE_DETECT_ADC_PIN ADC_GPIO_PB0
#endif
Expand Down Expand Up @@ -171,7 +175,6 @@ extern "C" {
*/
typedef enum{
EV_POLL_ED_DETECT,
EV_POLL_PM,
EV_POLL_HCI,
EV_POLL_IDLE,
EV_POLL_MAX,
Expand Down
7 changes: 3 additions & 4 deletions src/app_i2c.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "compiler.h"
#include "tl_common.h"
#include "types.h"
#include "app_cfg.h"
#include "chip_8258/i2c.h"

_attribute_data_retention_ bool i2c_sending;

Expand All @@ -19,11 +18,11 @@ void send_i2c(u8 device_id, const u8 *buffer, int dataLen){
}

u8 test_i2c_device(u8 address){
reg_i2c_id = address<<1;
reg_i2c_id = address << 1;
reg_i2c_ctrl = FLD_I2C_CMD_START | FLD_I2C_CMD_ID;
while(reg_i2c_status & FLD_I2C_CMD_BUSY);
reg_i2c_ctrl = FLD_I2C_CMD_STOP;
while(reg_i2c_status & FLD_I2C_CMD_BUSY );

return (reg_i2c_status & FLD_I2C_NAK)?0:1;
return (reg_i2c_status & FLD_I2C_NAK) ? 0 : 1;
}
31 changes: 16 additions & 15 deletions src/app_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @date 2021
*
* @par Copyright (c) 2021, Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +20,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*******************************************************************************************************/

/**********************************************************************
Expand All @@ -32,7 +34,6 @@

#include "shtv3_sensor.h"
#include "lcd.h"
#include "device.h"

/**********************************************************************
* LOCAL CONSTANTS
Expand Down Expand Up @@ -147,20 +148,20 @@ void buttonKeepPressed(u8 btNum){
void buttonShortPressed(u8 btNum){
if(btNum == VK_SW1){
if(zb_isDeviceJoinedNwk()){
epInfo_t dstEpInfo;
memset((u8 *)&dstEpInfo, 0, sizeof(epInfo_t));

dstEpInfo.dstAddrMode = APS_SHORT_DSTADDR_WITHEP;
dstEpInfo.dstEp = SENSOR_DEVICE_ENDPOINT;
dstEpInfo.dstAddr.shortAddr = 0x0000;
dstEpInfo.profileId = HA_PROFILE_ID;

zoneStatusChangeNoti_t statusChangeNotification;

statusChangeNotification.zoneStatus = ZONE_STATUS_TEST;
statusChangeNotification.extStatus = 0;
statusChangeNotification.zoneId = ZCL_ZONE_ID_INVALID;
statusChangeNotification.delay = 0;
// epInfo_t dstEpInfo;
// memset((u8 *)&dstEpInfo, 0, sizeof(epInfo_t));
//
// dstEpInfo.dstAddrMode = APS_SHORT_DSTADDR_WITHEP;
// dstEpInfo.dstEp = SENSOR_DEVICE_ENDPOINT;
// dstEpInfo.dstAddr.shortAddr = 0x0000;
// dstEpInfo.profileId = HA_PROFILE_ID;

// zoneStatusChangeNoti_t statusChangeNotification;
//
// statusChangeNotification.zoneStatus = ZONE_STATUS_TEST;
// statusChangeNotification.extStatus = 0;
// statusChangeNotification.zoneId = ZCL_ZONE_ID_INVALID;
// statusChangeNotification.delay = 0;

// zcl_iasZone_statusChangeNotificationCmd(SENSOR_DEVICE_ENDPOINT, &dstEpInfo, TRUE, &statusChangeNotification);
}
Expand Down
2 changes: 2 additions & 0 deletions src/app_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @date 2021
*
* @par Copyright (c) 2021, Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +20,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*******************************************************************************************************/

#ifndef _APP_UI_H_
Expand Down
134 changes: 0 additions & 134 deletions src/battery.c

This file was deleted.

26 changes: 0 additions & 26 deletions src/battery.h

This file was deleted.

7 changes: 0 additions & 7 deletions src/board_8258_03mmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
extern "C" {
#endif

// BATTERY
#define GPIO_VBAT GPIO_PB0 // missing pin on case TLSR8253F512ET32
#define PB0_FUNC AS_GPIO
#define PB0_INPUT_ENABLE 1
#define PB0_DATA_OUT 1
#define PB0_OUTPUT_ENABLE 1

// BUTTON
#define BUTTON1 GPIO_PA5 // reset test point
#define PA5_FUNC AS_GPIO
Expand Down
19 changes: 12 additions & 7 deletions src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "zcl_relative_humidity.h"
#include "app_i2c.h"
#include "shtv3_sensor.h"
#include "battery.h"
#include "lcd.h"


Expand All @@ -33,7 +32,6 @@
* GLOBAL VARIABLES
*/
app_ctx_t g_sensorAppCtx;
extern battery_data_t battery_data;


#ifdef ZCL_OTA
Expand Down Expand Up @@ -181,16 +179,24 @@ u8 is_comfort(s16 t, u16 h) {
void read_sensor_and_save() {
s16 temp = 0;
u16 humi = 0;
u16 voltage, percentage;
u8 converted_voltage, percentage2;

read_sensor(&temp,&humi);
// printf("Temp: %d.%d, humid: %d\r\n", temp/10, temp % 10, humi);
g_zcl_temperatureAttrs.measuredValue = temp * 10;
g_zcl_relHumidityAttrs.measuredValue = humi * 100;

check_battery();
// printf("battery %d mv, %d %%\r\n", battery_data.battery_mv, battery_data.battery_level);
g_zcl_powerAttrs.batteryVoltage = battery_data.battery_mv / 100;
g_zcl_powerAttrs.batteryPercentage = battery_data.battery_level * 2;
voltage = drv_get_adc_data();
converted_voltage = (u8)(voltage / 100);
percentage = ((voltage - BATTERY_SAFETY_THRESHOLD) / 4);
if (percentage > 0xc8) percentage = 0xc8;
percentage2 = (u8)percentage;

// printf("converted voltage %d diff %d", converted_voltage, (voltage - BATTERY_SAFETY_THRESHOLD));
//printf(" , percentage2 %d\r\n", percentage2);
g_zcl_powerAttrs.batteryVoltage = converted_voltage;
g_zcl_powerAttrs.batteryPercentage = percentage2;

// update lcd
show_temp_symbol(1);
Expand Down Expand Up @@ -301,7 +307,6 @@ void user_init(bool isRetention)
drv_pm_wakeupPinConfig(g_sensorPmCfg, sizeof(g_sensorPmCfg)/sizeof(drv_pm_pinCfg_t));
#endif

random_generator_init(); //must
init_i2c();
init_sensor();
init_lcd(!isRetention);
Expand Down

0 comments on commit 151f0c3

Please sign in to comment.