Skip to content

Commit 221b898

Browse files
committed
demos/high_res: Add HMI evCharge data publish through MQTT
Create a shared variable to share current progress of EV charging. After each poll for ADC data, also publish the progress percentage on relevant topic via MQTT. Signed-off-by: Divyansh Mittal <d-mittal@ti.com>
1 parent ddec016 commit 221b898

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

demos/high_res/adc.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static lv_demo_high_res_api_t * api_hmi;
4141
static struct mosquitto *mosq;
4242
extern int back_pressed_adc;
4343
void publish_sensor_data(float);
44+
extern int ev_charge;
4445

4546
/**
4647
* enum autochan - state for the automatic channel enabling mechanism
@@ -102,7 +103,13 @@ void publish_sensor_data(float temp)
102103
rc = mosquitto_publish(mosq, NULL, "SmartHome/temp", strlen(payload), payload, 1, false);
103104
if(rc != MOSQ_ERR_SUCCESS){
104105
fprintf(stderr, "Error publishing: %s\n", mosquitto_strerror(rc));
105-
}
106+
}
107+
108+
snprintf(payload, sizeof(payload), "%d", ev_charge);
109+
rc = mosquitto_publish(mosq, NULL, "SmartHome/evCharge", strlen(payload), payload, 1, false);
110+
if(rc != MOSQ_ERR_SUCCESS){
111+
fprintf(stderr, "Error publishing: %s\n", mosquitto_strerror(rc));
112+
}
106113
}
107114

108115
int mqtt_temp_pub_init(){

demos/high_res/lv_demo_high_res_app_ev_charging.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
* DEFINES
2121
*********************/
2222

23+
/*********************
24+
* GLOBAL VARIABLE
25+
*********************/
26+
int ev_charge = 0;
27+
2328
/**********************
2429
* TYPEDEFS
2530
**********************/
@@ -210,6 +215,7 @@ static void anim_exec_cb(void * var, int32_t v)
210215
lv_demo_high_res_ctx_t * c = lv_obj_get_user_data(base_obj);
211216

212217
lv_subject_set_int(&c->ev_charging_progress, v);
218+
ev_charge = lv_map(lv_subject_get_int(&c->ev_charging_progress), 0, EV_CHARGING_RANGE_END, 0, 100);
213219

214220
if(c->ev_charging_bg_cont) {
215221
anim_state_t * anim_state = lv_obj_get_user_data(c->ev_charging_bg_cont);

0 commit comments

Comments
 (0)