Skip to content

Commit 48c0717

Browse files
Performed naïve conversion to C++ (no deviations from C observed) (#13)
1 parent 1802517 commit 48c0717

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

main/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
idf_component_register(SRCS "app_main.c"
1+
idf_component_register(SRCS "app_main.cpp"
22
INCLUDE_DIRS ".")

main/app_main.c renamed to main/app_main.cpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ typedef struct sensor_t {
5959

6060
char device_id[19];
6161
char *edge_pub_topic;
62-
char *mqtt_hello = "NO HELLO";
63-
sensor sensors[MAX_DEVICES] = {0};
62+
char *mqtt_hello;
63+
sensor sensors[MAX_DEVICES] = {};
6464

6565
struct hello {
6666
const char *entity_type;
@@ -234,8 +234,8 @@ void onewire_start(void)
234234

235235
ESP_LOGI(TAG, "[1-Wire] looking for connected devices on pin %d...", GPIO_DS18B20_0);
236236

237-
OneWireBus_ROMCode device_rom_codes[MAX_DEVICES] = {0};
238-
OneWireBus_SearchState search_state = {0};
237+
OneWireBus_ROMCode device_rom_codes[MAX_DEVICES] = {};
238+
OneWireBus_SearchState search_state = {};
239239
bool found = false;
240240
owb_search_first(owb, &search_state, &found);
241241
while (found) {
@@ -322,7 +322,7 @@ void onewire_poll(void)
322322
// Read the results immediately after conversion otherwise it may fail
323323
// (using printf before reading may take too long)
324324
float readings[MAX_DEVICES] = { 0 };
325-
DS18B20_ERROR errors[MAX_DEVICES] = { 0 };
325+
DS18B20_ERROR errors[MAX_DEVICES] = {};
326326

327327
for (int offset = 0; offset < devices_found; ++offset) {
328328
errors[offset] = ds18b20_read_temp(devices[offset], &readings[offset]);
@@ -399,21 +399,20 @@ static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event)
399399
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
400400
{
401401
ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%d", base, event_id);
402-
mqtt_event_handler_cb(event_data);
402+
mqtt_event_handler_cb((esp_mqtt_event_handle_t) event_data);
403403
}
404404

405405
void mqtt_start(void)
406406
{
407-
esp_mqtt_client_config_t mqtt_cfg = {
408-
.uri = CONFIG_BROKER_URL,
409-
};
407+
esp_mqtt_client_config_t mqtt_cfg = {};
408+
mqtt_cfg.uri = CONFIG_BROKER_URL;
410409

411410
mqtt_client = esp_mqtt_client_init(&mqtt_cfg);
412-
esp_mqtt_client_register_event(mqtt_client, ESP_EVENT_ANY_ID, mqtt_event_handler, mqtt_client);
411+
esp_mqtt_client_register_event(mqtt_client, (esp_mqtt_event_id_t) ESP_EVENT_ANY_ID, mqtt_event_handler, mqtt_client);
413412
esp_mqtt_client_start(mqtt_client);
414413
}
415414

416-
void app_main(void)
415+
extern "C" void app_main(void)
417416
{
418417
ESP_LOGI(TAG, "[core] Oh, hai");
419418
ESP_LOGI(TAG, "[core] free memory: %d bytes", esp_get_free_heap_size());

0 commit comments

Comments
 (0)