diff --git a/.gitignore b/.gitignore index 96d9a054a56c093ea93a6a0f47a5f81419911938..7c64978a57eeeee549764602f67c38e80bd43c22 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,4 @@ sdkconfig.old # This directory contains user-specific environment configurations /environments/* # Ignore symlink to current environment -/qthing/environment.h +/qthing/include/environment.h diff --git a/bin/set-environment b/bin/set-environment index 5c3e29eec4b4e25b0292dca5f36789bd3257a43c..51a8b19bafd2b6577b78b636c0f7ac9b43499b7c 100755 --- a/bin/set-environment +++ b/bin/set-environment @@ -17,9 +17,9 @@ function link_environment { else TARGET="../$1" fi - echo "Linking qthing/environment.h to $TARGET" - ln -snf "$TARGET" "qthing/environment.h" - touch --no-create "qthing/environment.h" + echo "Linking qthing/include/environment.h to $TARGET" + ln -snf "$TARGET" "qthing/include/environment.h" + touch --no-create "qthing/include/environment.h" } if [[ -z "$1" ]]; then diff --git a/qthing/CMakeLists.txt b/qthing/CMakeLists.txt index ffe1285dbe0ab2c71ac2021a2ce5b968416c9d9d..21a3d2c434ecb2bb951a38183d5094d9d7666b0a 100644 --- a/qthing/CMakeLists.txt +++ b/qthing/CMakeLists.txt @@ -6,8 +6,7 @@ idf_component_register( "system" INCLUDE_DIRS - "." - "network" + "include" REQUIRES ESP32-Digital-RGB-LED-Drivers diff --git a/qthing/color.cpp b/qthing/color.cpp index 82b3d978ae745d6cb9ebf41878693ffc948d301d..b6ce54ef7c426cfbb5e17d04061802dad75145be 100644 --- a/qthing/color.cpp +++ b/qthing/color.cpp @@ -1,4 +1,4 @@ -#include <qthing.hpp> +#include "qthing_legacy.hpp" #include <cmath> namespace qthing { diff --git a/qthing/device.hpp b/qthing/device.hpp deleted file mode 100644 index b6c6b72a327514ac4ede0208fb6afdb942b46595..0000000000000000000000000000000000000000 --- a/qthing/device.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef DEVICE_H -#define DEVICE_H - -void device_main(); - -#endif \ No newline at end of file diff --git a/qthing/event.cpp b/qthing/event.cpp index db915c83f6824d090a1118b625be658fbc9f3e74..f8b4a04e644bf7af132c375fa192f998dd6104b5 100644 --- a/qthing/event.cpp +++ b/qthing/event.cpp @@ -1,4 +1,4 @@ -#include <qthing.hpp> +#include "qthing_legacy.hpp" #include "event.hpp" namespace qthing { diff --git a/qthing/include/device.hpp b/qthing/include/device.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ddab8cf611f6414017fc333c09ef9b942312de8c --- /dev/null +++ b/qthing/include/device.hpp @@ -0,0 +1,3 @@ +#pragma once + +void device_main(); diff --git a/qthing/event.hpp b/qthing/include/event.hpp similarity index 83% rename from qthing/event.hpp rename to qthing/include/event.hpp index a8e6090e40fb39028c1ebc03321053047aee6323..90278470c3d443db392a8f174b7eeae09f79031f 100644 --- a/qthing/event.hpp +++ b/qthing/include/event.hpp @@ -1,13 +1,14 @@ -#ifndef EVENT_H -#define EVENT_H +#pragma once -#include <qthing.hpp> +#include "qthing_legacy.hpp" #include <string> #include <functional> namespace qthing { +#ifndef QTHING_HIDE_PRIVATE_API + using string_callback_t = std::function<void(const std::string&)>; void set_oled_log_callback(string_callback_t callback); @@ -18,6 +19,6 @@ void update_eth_connection_status(connection_status_t status); void update_mqtt_connection_status(connection_status_t status); -} - #endif + +} diff --git a/qthing/io.hpp b/qthing/include/io.hpp similarity index 79% rename from qthing/io.hpp rename to qthing/include/io.hpp index b2d94cad1c8ad07226e021a3ab17a7bee964621d..3e1338de80ab47f1dab1accebbc427b9302013a2 100644 --- a/qthing/io.hpp +++ b/qthing/include/io.hpp @@ -1,6 +1,6 @@ #pragma once -#include "qthing.hpp" +#include "qthing_legacy.hpp" #include <stdint.h> #include <string> @@ -10,8 +10,12 @@ namespace qthing { +#ifndef QTHING_HIDE_PRIVATE_API + void gpio_init_input(gpio_num_t gpio_num); void gpio_init_output(gpio_num_t gpio_num, uint32_t level); void pulse_relay(gpio_num_t gpio_off); +#endif + } diff --git a/qthing/peripherals/led_strip.hpp b/qthing/include/led_strip.hpp similarity index 82% rename from qthing/peripherals/led_strip.hpp rename to qthing/include/led_strip.hpp index 47d28a41d658bc613cef480ba3ffb2a6da1cc50c..b66eecc69bda868b382058c805248ecc4d483de5 100644 --- a/qthing/peripherals/led_strip.hpp +++ b/qthing/include/led_strip.hpp @@ -7,4 +7,4 @@ #include "esp32_digital_led_lib.h" -#include <qthing.hpp> +#include "qthing_legacy.hpp" diff --git a/qthing/measured.hpp b/qthing/include/measured.hpp similarity index 97% rename from qthing/measured.hpp rename to qthing/include/measured.hpp index b6dfb63edbf05badf17a3fdc9e9a81381e365285..f714cbfcc65b23f32f695fbf1d45d20a2610360c 100644 --- a/qthing/measured.hpp +++ b/qthing/include/measured.hpp @@ -13,6 +13,8 @@ namespace qthing { +#ifndef QTHING_HIDE_PRIVATE_API + namespace measured { typedef struct { @@ -55,4 +57,7 @@ namespace qthing { void mqtt(const std::vector<qthing::measured::sensor_data_t>& data); } } + +#endif + } diff --git a/qthing/mqtt.hpp b/qthing/include/mqtt.hpp similarity index 57% rename from qthing/mqtt.hpp rename to qthing/include/mqtt.hpp index 1482cababdb83e17f6273eb0fb04e4f1ac38d987..1b8a5066d3c9927f2a63437d00e3128d308ed911 100644 --- a/qthing/mqtt.hpp +++ b/qthing/include/mqtt.hpp @@ -1,15 +1,16 @@ -#ifndef MQTT_H -#define MQTT_H +#pragma once -#include <qthing.hpp> +#include "qthing_legacy.hpp" #include <string> #include <functional> namespace qthing { -void mqtt_client_start(); +#ifndef QTHING_HIDE_PRIVATE_API -} +void mqtt_client_start(); #endif + +} diff --git a/qthing/mqtt_c.h b/qthing/include/mqtt_c.h similarity index 72% rename from qthing/mqtt_c.h rename to qthing/include/mqtt_c.h index dd791e65f77b779f62d36c00b544b86fbda6a878..fc2e1aa9227d5e88b42b48ee54073a630a6ce383 100644 --- a/qthing/mqtt_c.h +++ b/qthing/include/mqtt_c.h @@ -1,10 +1,11 @@ // Include as extern "C" -#ifndef MQTT_C_H -#define MQTT_C_H +#pragma once #include "mqtt_client.h" +#ifndef QTHING_HIDE_PRIVATE_API + esp_mqtt_client_handle_t mqtt_client_start_c(mqtt_event_callback_t mqtt_event_handler); -#endif \ No newline at end of file +#endif diff --git a/qthing/mqtt_common.h b/qthing/include/mqtt_common.h similarity index 92% rename from qthing/mqtt_common.h rename to qthing/include/mqtt_common.h index 945f3164f64aa2dc9fb6a1563360f58110f35a13..3400ea68d2feb9ddfa5a92cdc0231838d54f7aba 100644 --- a/qthing/mqtt_common.h +++ b/qthing/include/mqtt_common.h @@ -1,5 +1,4 @@ -#ifndef MQTT_COMMON_H -#define MQTT_COMMON_H +#pragma once #include "environment.h" #include "device_config.h" @@ -20,5 +19,3 @@ #define OTA_PROGRESS_TOPIC DEVICE_NAMESPACE "ota/progress" #define OTA_STATE_TOPIC DEVICE_NAMESPACE "ota/state" #define OTA_ERROR_TOPIC DEVICE_NAMESPACE "ota/error" - -#endif diff --git a/qthing/mqtt_ota.hpp b/qthing/include/mqtt_ota.hpp similarity index 67% rename from qthing/mqtt_ota.hpp rename to qthing/include/mqtt_ota.hpp index f6c6a1f7a30851c2680f433b3bcacf089518b3cf..f873256e24b7d6b3a46c1f57d40cfe923975515f 100644 --- a/qthing/mqtt_ota.hpp +++ b/qthing/include/mqtt_ota.hpp @@ -1,14 +1,14 @@ -#ifndef MQTT_OTA_H -#define MQTT_OTA_H - -#include <qthing.hpp> +#pragma once +#include "qthing_legacy.hpp" namespace qthing { +#ifndef QTHING_HIDE_PRIVATE_API + void handle_ota_message(const multipart_message_t& message); void add_ota_event_callback(ota_event_callback_t handler); -} - #endif + +} diff --git a/qthing/include/network.hpp b/qthing/include/network.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4908436dc1239052002498043b124e1a35e0300f --- /dev/null +++ b/qthing/include/network.hpp @@ -0,0 +1,26 @@ +#pragma once + +namespace qthing { + + +void enable_wifi(); +connection_status_t get_wifi_connection_status(); +void add_wifi_connection_status_callback(connection_status_callback_t callback); +void add_combined_mqtt_connection_status_callback(connection_status_callback_t handler); + +void enable_ethernet_lan8720(); +connection_status_t get_eth_connection_status(); +void add_eth_connection_status_callback(connection_status_callback_t callback); + +connection_status_t get_network_connection_status(); +void add_network_connection_status_callback(connection_status_callback_t callback); + + +#ifndef QTHING_HIDE_PRIVATE_API + +void start_network_clients(); +void initialize_network(); + +#endif + +} diff --git a/qthing/oled_symbols.hpp b/qthing/include/oled_symbols.hpp similarity index 97% rename from qthing/oled_symbols.hpp rename to qthing/include/oled_symbols.hpp index 63e93c68fed4970137934e9b68bd39ec4617c747..af8e406a418ee0a829745f4b20f78792c24d80b3 100644 --- a/qthing/oled_symbols.hpp +++ b/qthing/include/oled_symbols.hpp @@ -1,3 +1,5 @@ +#ifndef QTHING_HIDE_PRIVATE_API + #include "Arduino.h" const uint8_t wifi_connected_symbol[] PROGMEM = { @@ -101,3 +103,4 @@ const uint8_t other_symbol[] PROGMEM = { B00000000 }; +#endif diff --git a/qthing/polyfill.hpp b/qthing/include/polyfill.hpp similarity index 74% rename from qthing/polyfill.hpp rename to qthing/include/polyfill.hpp index 84f38efbc4605455c511bdfb15c69af5a368ee28..87cc3ce286d7881df51ac797da20839741e5d444 100644 --- a/qthing/polyfill.hpp +++ b/qthing/include/polyfill.hpp @@ -1,6 +1,10 @@ +#pragma once + #include <string> #include <sstream> +#ifndef QTHING_HIDE_PRIVATE_API + template <typename T> std::string to_string(T value) { @@ -8,3 +12,5 @@ std::string to_string(T value) os << value ; return os.str() ; } + +#endif diff --git a/qthing/include/power.hpp b/qthing/include/power.hpp new file mode 100644 index 0000000000000000000000000000000000000000..159cd15ad290f06aa297bd65aac67179dde239c0 --- /dev/null +++ b/qthing/include/power.hpp @@ -0,0 +1,7 @@ +#pragma once + +namespace qthing { + +void power_managment_max_power(); + +} diff --git a/qthing/include/qthing b/qthing/include/qthing new file mode 100644 index 0000000000000000000000000000000000000000..0f8fbdc153ce070b03be16c0329ea177229716e9 --- /dev/null +++ b/qthing/include/qthing @@ -0,0 +1,11 @@ +#pragma once + +#define QTHING_HIDE_PRIVATE_API + +#include "qthing_legacy.hpp" + +#include "network.hpp" +#include "power.hpp" +#include "util.hpp" + +#undef QTHING_HIDE_PRIVATE_API diff --git a/qthing/include/qthing.hpp b/qthing/include/qthing.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0f8fbdc153ce070b03be16c0329ea177229716e9 --- /dev/null +++ b/qthing/include/qthing.hpp @@ -0,0 +1,11 @@ +#pragma once + +#define QTHING_HIDE_PRIVATE_API + +#include "qthing_legacy.hpp" + +#include "network.hpp" +#include "power.hpp" +#include "util.hpp" + +#undef QTHING_HIDE_PRIVATE_API diff --git a/qthing/qthing.hpp b/qthing/include/qthing_legacy.hpp similarity index 92% rename from qthing/qthing.hpp rename to qthing/include/qthing_legacy.hpp index 6067cb8a8bfbe9c54afb2dc8fd3ba6ebb0d626d7..c547cda5f5a885e6289a50d3fa7d697a63db76cd 100644 --- a/qthing/qthing.hpp +++ b/qthing/include/qthing_legacy.hpp @@ -1,5 +1,4 @@ -#ifndef QTHING_H -#define QTHING_H +#pragma once #include <string> @@ -46,19 +45,6 @@ namespace qthing { void enable_status_led(gpio_num_t gpio = GPIO_NUM_2, bool negated = false); void show_activity(); - // network - void enable_wifi(); - connection_status_t get_wifi_connection_status(); - void add_wifi_connection_status_callback(connection_status_callback_t callback); - void add_combined_mqtt_connection_status_callback(connection_status_callback_t handler); - - void enable_ethernet_lan8720(); - connection_status_t get_eth_connection_status(); - void add_eth_connection_status_callback(connection_status_callback_t callback); - - connection_status_t get_network_connection_status(); - void add_network_connection_status_callback(connection_status_callback_t callback); - // mqtt void publish_message(const std::string& topic, const std::string& message); void add_message_callback(const std::string& topic, message_callback_t callback); @@ -83,9 +69,6 @@ namespace qthing { void enable_lcd(const std::string& topic, uint8_t rs, uint8_t en, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); - // power - void power_managment_max_power(); - // LED strips enum led_strip_types_t { LED_WS2812_V1, @@ -262,11 +245,10 @@ namespace qthing { bool get_key_state(uint8_t x, uint8_t y); uint32_t get_key_activation_time(uint8_t x, uint8_t y); } -} // utility std::string to_string(float value, int precision = 2); std::string to_string(uint32_t value); std::string to_string(struct sockaddr_in6 sourceAddr); -#endif +} diff --git a/qthing/rc_433.hpp b/qthing/include/rc_433.hpp similarity index 89% rename from qthing/rc_433.hpp rename to qthing/include/rc_433.hpp index 2bf9316558ec8aefd010349639993735d2eb99a5..7a1764e22f0d5eb0482dc0df91971cefb6bcdfa7 100644 --- a/qthing/rc_433.hpp +++ b/qthing/include/rc_433.hpp @@ -1,12 +1,13 @@ -#ifndef RC_433_H -#define RC_433_H +#pragma once #include <string> #include "driver/gpio.h" - namespace qthing { + +#ifndef QTHING_HIDE_PRIVATE_API + void rc_switch_on(const std::string& code); void rc_switch_off(const std::string& code); void rc_switch(const std::string& code, bool state); @@ -14,6 +15,6 @@ void rc_switch(const std::string& code, bool state); void rc_enable_send(const std::string& send_on_topic, const std::string& send_off_topic, gpio_num_t gpio); void rc_enable_receive(const std::string& topic, gpio_num_t gpio); -} - #endif + +} diff --git a/qthing/sensor.hpp b/qthing/include/sensor.hpp similarity index 58% rename from qthing/sensor.hpp rename to qthing/include/sensor.hpp index 855b2a6e94ec65e081945e6aa760bb8fa4ea3748..75ec461288005ee4a71720dfcf1490fc68eecd9b 100644 --- a/qthing/sensor.hpp +++ b/qthing/include/sensor.hpp @@ -1,10 +1,11 @@ -#ifndef SENSOR_H -#define SENSOR_H +#pragma once namespace qthing { -void add_soil_moisture_sensor(); +#ifndef QTHING_HIDE_PRIVATE_API -} +void add_soil_moisture_sensor(); #endif + +} diff --git a/qthing/network/udp.hpp b/qthing/include/udp.hpp similarity index 60% rename from qthing/network/udp.hpp rename to qthing/include/udp.hpp index 880516b556176e1561699cfacafb7ac2df6e6ccc..2937cec80d6945805a4e19ee9ee46964c218048c 100644 --- a/qthing/network/udp.hpp +++ b/qthing/include/udp.hpp @@ -2,6 +2,10 @@ namespace qthing { +#ifndef QTHING_HIDE_PRIVATE_API + void start_udp_server(); +#endif + } diff --git a/qthing/include/util.hpp b/qthing/include/util.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a9e37f24edadcb4d8f8205874bbb8246fac7f6df --- /dev/null +++ b/qthing/include/util.hpp @@ -0,0 +1,7 @@ +#pragma once + +namespace qthing { + +unsigned long millis(); + +} diff --git a/qthing/io.cpp b/qthing/io.cpp index bb5db70f65222bde77ad1ad105276658aa1415aa..eda65337018c85390c5c1e8894c996cfb2ed37b1 100644 --- a/qthing/io.cpp +++ b/qthing/io.cpp @@ -1,4 +1,4 @@ -#include <qthing.hpp> +#include "qthing_legacy.hpp" #include "io.hpp" #include "mqtt.hpp" diff --git a/qthing/lcd.cpp b/qthing/lcd.cpp index a08efc030c7c843b0004f87d8715e44e7fa04efe..433de176a5e3a74edce78b92ec91e134d49b35de 100644 --- a/qthing/lcd.cpp +++ b/qthing/lcd.cpp @@ -1,5 +1,7 @@ -#include <qthing.hpp> +#include "qthing_legacy.hpp" + #include "mqtt.hpp" +#include "network.hpp" #include <string> #include <vector> diff --git a/qthing/measured.cpp b/qthing/measured.cpp index e537a52a81decb0515d999f165c3195257c890b9..bcd33467b78af4029c5d394dc2b40c62549e9d0a 100644 --- a/qthing/measured.cpp +++ b/qthing/measured.cpp @@ -7,7 +7,7 @@ #include "freertos/task.h" #include "esp_log.h" -#include "qthing.hpp" +#include "qthing_legacy.hpp" #include "mqtt_common.h" diff --git a/qthing/mqtt_ota.cpp b/qthing/mqtt_ota.cpp index 2f71521b5acb3aa9180e65b878d8e94d7417920d..39ed83c06015342098a59260fcd903213c789392 100644 --- a/qthing/mqtt_ota.cpp +++ b/qthing/mqtt_ota.cpp @@ -6,7 +6,7 @@ #include "esp_system.h" #include "esp_ota_ops.h" -#include <qthing.hpp> +#include "qthing_legacy.hpp" #define TAG "MQTT_OTA" diff --git a/qthing/network/network.cpp b/qthing/network/network.cpp index f2479e684f53b59faf405e4d0dd63f782961768a..78ab9d8b249a9f0eb0e121b4d24d95566282e205 100644 --- a/qthing/network/network.cpp +++ b/qthing/network/network.cpp @@ -1,10 +1,11 @@ -#include "qthing.hpp" +#include "qthing_legacy.hpp" + #include "io.hpp" #include "environment.h" #include "device_config.h" #include "event.hpp" #include "mqtt.hpp" -#include "network/udp.hpp" +#include "udp.hpp" #include "string.h" diff --git a/qthing/network/network.hpp b/qthing/network/network.hpp deleted file mode 100644 index 4105e51af4998aa7642cbe70fd90e54b0275babe..0000000000000000000000000000000000000000 --- a/qthing/network/network.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -namespace qthing { - -void start_network_clients(); -void initialize_network(); - -} diff --git a/qthing/network/network_animation.cpp b/qthing/network/network_animation.cpp index 65a0c2faf980c46698ab18b0b1a8f757daee19ae..6bc42198a74847c682cf7578d4aa1ee827c58bc6 100644 --- a/qthing/network/network_animation.cpp +++ b/qthing/network/network_animation.cpp @@ -1,5 +1,6 @@ -#import <qthing.hpp> -#import "peripherals/led_strip.hpp" +#import "qthing_legacy.hpp" + +#import "led_strip.hpp" #import <algorithm> #import <vector> diff --git a/qthing/network/udp.cpp b/qthing/network/udp.cpp index 350a321f20e295d6c037dd091e20173a5fcd08d3..24d948c4f8057c2ed19e58d9537e21a909847bd8 100644 --- a/qthing/network/udp.cpp +++ b/qthing/network/udp.cpp @@ -1,4 +1,4 @@ -#include <qthing.hpp> +#include "qthing_legacy.hpp" #include <map> @@ -74,7 +74,7 @@ static void udp_server_task(void *pvParameters) } // Data received else { - ESP_LOGI(TAG, "Received %d bytes from %s", len, to_string(sourceAddr).c_str()); + ESP_LOGI(TAG, "Received %d bytes from %s", len, qthing::to_string(sourceAddr).c_str()); std::string payload_str(rx_buffer); int16_t lenBestMatch = -1; diff --git a/qthing/network/wifi.cpp b/qthing/network/wifi.cpp index 53ecf2117d4ef1626795dbfe70c80d0e2dafe33f..fed1a75774f14f17cccf482663a7596b6644703c 100644 --- a/qthing/network/wifi.cpp +++ b/qthing/network/wifi.cpp @@ -1,4 +1,5 @@ -#include "qthing.hpp" +#include "qthing_legacy.hpp" + #include "network.hpp" #include "io.hpp" #include "environment.h" diff --git a/qthing/ntp.cpp b/qthing/ntp.cpp index 06f08594cbb2156aecf4494b85a78360bf8bef2f..3c6879de3e00c3d0946a359469929758ed46db09 100644 --- a/qthing/ntp.cpp +++ b/qthing/ntp.cpp @@ -1,6 +1,6 @@ #undef __STRICT_ANSI__ -#include <qthing.hpp> +#include "qthing_legacy.hpp" #include <freertos/FreeRTOS.h> #include "freertos/task.h" diff --git a/qthing/oled.cpp b/qthing/oled.cpp index a9cc356e537e07b0c815492dc015c8460348e895..f8e1ea9dcaab70e9cce960f3fe22468476545451 100644 --- a/qthing/oled.cpp +++ b/qthing/oled.cpp @@ -1,6 +1,7 @@ -#include <qthing.hpp> +#include "qthing_legacy.hpp" #include "event.hpp" +#include "network.hpp" #include "Arduino.h" #include "SSD1306Wire.h" diff --git a/qthing/peripherals/button_panel_5x5.cpp b/qthing/peripherals/button_panel_5x5.cpp index 2d1b615c8ba122540690457fe9696da72ba040db..10bcac1300be4628273bd76a105582148e18467d 100644 --- a/qthing/peripherals/button_panel_5x5.cpp +++ b/qthing/peripherals/button_panel_5x5.cpp @@ -1,5 +1,6 @@ -#include <qthing.hpp> -#include <io.hpp> +#include "qthing_legacy.hpp" + +#include "io.hpp" #include <array> #include <functional> diff --git a/qthing/peripherals/led_strip.cpp b/qthing/peripherals/led_strip.cpp index 53f62cde7aec7b5c3d413ab6140a3cbfd53b9b08..caba405ff93b95486ae62f1d94ad5daa3d80daa6 100644 --- a/qthing/peripherals/led_strip.cpp +++ b/qthing/peripherals/led_strip.cpp @@ -1,6 +1,7 @@ -#include <qthing.hpp> +#include "qthing_legacy.hpp" #include "led_strip.hpp" +#include "power.hpp" #include <algorithm> diff --git a/qthing/sensor.cpp b/qthing/sensor.cpp index 61e329ddc05e4219a1da058e6aba1896560dd0fb..fa03f057bed853cc26225397f96fe514fa57571d 100644 --- a/qthing/sensor.cpp +++ b/qthing/sensor.cpp @@ -1,7 +1,9 @@ +#include "qthing_legacy.hpp" + #include "mqtt.hpp" +#include "polyfill.hpp" #include <string> -#include "polyfill.hpp" #include "esp_log.h" #include <driver/adc.h> @@ -10,8 +12,6 @@ #define SLEEP_PERIOD 60 * 1000 / portTICK_PERIOD_MS -namespace qthing { - bool message = false; void soil_moisture_sensor_task(void* arg) { adc1_config_width(ADC_WIDTH_12Bit); @@ -23,11 +23,11 @@ void soil_moisture_sensor_task(void* arg) { value += adc1_get_raw(ADC1_CHANNEL_4); vTaskDelay(1000 / 16 / portTICK_PERIOD_MS); } - publish_message("device/plant_auto/soil_moisture", to_string(value)); + qthing::publish_message("device/plant_auto/soil_moisture", to_string(value)); ESP_LOGI("SOIL_SENSOR", "%i", value); if (!message && value < 30000) { - publish_message("edi/cmd/say", "{\"args\": \"iiiiih, ich bin nass\"}"); + qthing::publish_message("edi/cmd/say", "{\"args\": \"iiiiih, ich bin nass\"}"); message = true; } @@ -38,5 +38,3 @@ void soil_moisture_sensor_task(void* arg) { void add_soil_moisture_sensor() { xTaskCreate(soil_moisture_sensor_task, "soil_moisture_sensor_task", 2048, NULL, 4, NULL); } - -} diff --git a/qthing/status.cpp b/qthing/status.cpp index c8ce3822218cd8a533ce036ffe9f71301f3de6e8..8b253bb510599a12688c2592df50f56e1b63798f 100644 --- a/qthing/status.cpp +++ b/qthing/status.cpp @@ -1,6 +1,7 @@ -#include <qthing.hpp> +#include "qthing_legacy.hpp" #include "io.hpp" +#include "network.hpp" #include "freertos/FreeRTOS.h" #include "freertos/task.h" diff --git a/qthing/system/power.cpp b/qthing/system/power.cpp index 3e0152d81fb0db9aec43419cea4e9b56ceaaf9bd..ded7b7d43559fe62a1b4080f3fa69e553ad81298 100644 --- a/qthing/system/power.cpp +++ b/qthing/system/power.cpp @@ -1,4 +1,6 @@ -#include <qthing.hpp> +#include "qthing_legacy.hpp" + +#include "power.hpp" #include "esp_pm.h" #include "freertos/FreeRTOS.h" @@ -8,6 +10,7 @@ static bool max_power = false; namespace qthing { + void power_managment_max_power() { if (!max_power) { max_power = true; @@ -23,4 +26,5 @@ namespace qthing { vTaskDelay(200 / portTICK_PERIOD_MS); } } + } diff --git a/qthing/util.cpp b/qthing/util.cpp index 8f1f820039ed9ca38459cda2a14386ce6b87341a..436f0be4198267c983211d87baf18e58bbe14c1d 100644 --- a/qthing/util.cpp +++ b/qthing/util.cpp @@ -1,4 +1,5 @@ -#include <qthing.hpp> +#include "qthing_legacy.hpp" + #include "util.hpp" #include <sstream> @@ -7,24 +8,24 @@ #include "freertos/task.h" #include "lwip/sockets.h" -unsigned long IRAM_ATTR millis() { +unsigned long IRAM_ATTR qthing::millis() { return xTaskGetTickCount() * portTICK_PERIOD_MS; } -std::string to_string(float value, int precision) { +std::string qthing::to_string(float value, int precision) { std::stringstream stream; stream.precision(precision); stream << value; return stream.str(); } -std::string to_string(uint32_t value) { +std::string qthing::to_string(uint32_t value) { std::stringstream stream; stream << value; return stream.str(); } -std::string to_string(struct sockaddr_in6 sourceAddr) { +std::string qthing::to_string(struct sockaddr_in6 sourceAddr) { char addr_str[128]; if (sourceAddr.sin6_family == PF_INET) { diff --git a/qthing/util.hpp b/qthing/util.hpp deleted file mode 100644 index 54a34a0774517100085649c9998a077142c9e0ee..0000000000000000000000000000000000000000 --- a/qthing/util.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef UTIL_H -#define UTIL_H - -unsigned long millis(); - -#endif