Browse Source

reorganise project

Bence Balint 3 years ago
parent
commit
ca5aaeec96

+ 7 - 7
CMakeLists.txt

@@ -3,16 +3,16 @@ set(CMAKE_CXX_STANDARD 17)
 idf_component_register(
         SRCS
         "src/kbf.cpp"
-        "src/kbf_adc.cpp"
-        "src/kbf_gpio.cpp"
+        "src/adc.cpp"
+        "src/gpio.cpp"
         "src/http/client.cpp"
         "src/http/common.cpp"
         "src/http/server.cpp"
-        "src/kbf_net.cpp"
-        "src/kbf_nvs.cpp"
-        "src/kbf_spiffs.cpp"
-        "src/kbf_task.cpp"
-        "src/kbf_uart.cpp"
+        "src/net.cpp"
+        "src/nvs.cpp"
+        "src/spiffs.cpp"
+        "src/task.cpp"
+        "src/uart.cpp"
         "src/wifi/ap.cpp"
         "src/wifi/sta.cpp"
         "src/wifi/driver.cpp"

+ 1 - 1
doxygen.conf

@@ -864,7 +864,7 @@ WARN_LOGFILE           =
 # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
 # Note: If this tag is empty the current directory is searched.
 
-INPUT                  = include src test test_app
+INPUT                  = include include/kbf include/kbf/http src test test_app
 
 # This tag can be used to specify the character encoding of the source files
 # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses

+ 0 - 0
include/kbf_adc.h → include/kbf/adc.h


+ 1 - 1
include/kbf_gpio.h → include/kbf/gpio.h

@@ -3,7 +3,7 @@
 
 #include <driver/gpio.h>
 
-#include "kbf_task.h"
+#include "task.h"
 
 /**
  * General-Purpose Input/Output pin functions

+ 3 - 3
include/http/client.h → include/kbf/http/client.h

@@ -7,16 +7,16 @@
 #include <esp_err.h>
 #include <esp_http_client.h>
 
-#include "kbf_http.h"
+#include "kbf/http/common.h"
 
 using std::string;
 using std::shared_ptr;
 
 namespace kbf::http {
     /**
-     * @brief Asynchronous HTTP Client.
+     * @brief HTTP Client.
      *
-     * @note May only perform 1 request at a time, but can be reused afterwards.
+     * @note May only perform 1 request at a time, but can be (and should be) reused afterwards.
      */
     class Client {
     public:

+ 0 - 0
include/kbf_http.h → include/kbf/http/common.h


+ 1 - 1
include/http/server.h → include/kbf/http/server.h

@@ -7,7 +7,7 @@
 
 #include <esp_http_server.h>
 
-#include "kbf_http.h"
+#include "kbf/http/common.h"
 
 using std::string;
 using std::vector;

+ 0 - 0
include/kbf_assert.h → include/kbf/macros.h


+ 0 - 0
include/kbf_net.h → include/kbf/net.h


+ 0 - 0
include/kbf_nvs.h → include/kbf/nvs.h


+ 0 - 0
include/kbf_spiffs.h → include/kbf/spiffs.h


+ 0 - 0
include/kbf_task.h → include/kbf/task.h


+ 1 - 1
include/kbf_uart.h → include/kbf/uart.h

@@ -7,7 +7,7 @@
 #include <freertos/FreeRTOS.h>
 #include <freertos/queue.h>
 
-#include "kbf_task.h"
+#include "task.h"
 
 using std::string;
 

+ 1 - 1
include/kbf_wifi.h → include/kbf/wifi.h

@@ -8,7 +8,7 @@
 #include <esp_wifi.h>
 #include <esp_log.h>
 
-#include "kbf_net.h"
+#include "net.h"
 
 using std::string;
 using std::shared_ptr;

+ 8 - 6
src/kbf_adc.cpp → src/adc.cpp

@@ -1,10 +1,12 @@
-#include "kbf_adc.h"
+#include "kbf/adc.h"
 
 #include <esp_log.h>
 
-#include "kbf_assert.h"
+#include "kbf/macros.h"
 
-kbf::adc::ADC1::ADC1(int channel) : channel(static_cast<adc1_channel_t>(channel)) {
+using namespace kbf;
+
+adc::ADC1::ADC1(int channel) : channel(static_cast<adc1_channel_t>(channel)) {
     ESP_LOGI(TAG, "configuring ADC1 channel %d", channel);
     CHECK(adc1_config_width(KBF_ADC_WIDTH));
     CHECK(adc1_config_channel_atten(this->channel, KBF_ADC_ATTEN));
@@ -28,7 +30,7 @@ kbf::adc::ADC1::ADC1(int channel) : channel(static_cast<adc1_channel_t>(channel)
     }
 }
 
-uint32_t kbf::adc::ADC1::readRaw() const {
+uint32_t adc::ADC1::readRaw() const {
     int reading = 0;
     for (int i = 0; i < KBF_ADC_NUM_SAMPLES; i++) {
         reading += adc1_get_raw(channel);
@@ -37,7 +39,7 @@ uint32_t kbf::adc::ADC1::readRaw() const {
     return reading;
 }
 
-uint32_t kbf::adc::ADC1::readVoltage() const {
+uint32_t adc::ADC1::readVoltage() const {
     uint32_t reading = 0;
     for (int i = 0; i < KBF_ADC_NUM_SAMPLES; i++) {
         uint32_t voltage = 0;
@@ -48,6 +50,6 @@ uint32_t kbf::adc::ADC1::readVoltage() const {
     return reading;
 }
 
-uint32_t kbf::adc::ADC1::rawToVoltage(int raw) const {
+uint32_t adc::ADC1::rawToVoltage(int raw) const {
     return esp_adc_cal_raw_to_voltage(raw, adcChars);
 }

+ 13 - 11
src/kbf_gpio.cpp → src/gpio.cpp

@@ -1,30 +1,32 @@
-#include "kbf_gpio.h"
+#include "kbf/gpio.h"
 
 #include <esp_log.h>
 #include <esp_sleep.h>
 
-#include <kbf.h>
-#include "kbf_assert.h"
+#include "kbf.h"
+#include "kbf/macros.h"
 
-kbf::gpio::Output::Output(int pin) : pin(static_cast<gpio_num_t>(pin)) {
+using namespace kbf;
+
+gpio::Output::Output(int pin) : pin(static_cast<gpio_num_t>(pin)) {
     ESP_LOGI(TAG, "setting GPIO %d to OUTPUT mode", pin);
     CHECK(gpio_reset_pin(this->pin));
     CHECK(gpio_set_direction(this->pin, GPIO_MODE_OUTPUT));
 }
 
-void kbf::gpio::Output::high() const {
+void gpio::Output::high() const {
     gpio_set_level(pin, 1);
 }
 
-void kbf::gpio::Output::low() const {
+void gpio::Output::low() const {
     gpio_set_level(pin, 0);
 }
 
-bool kbf::gpio::Output::isHigh() const {
+bool gpio::Output::isHigh() const {
     return gpio_get_level(pin);
 }
 
-void kbf::gpio::Output::startPulse(int delay_ms, int limit) {
+void gpio::Output::startPulse(int delay_ms, int limit) {
     ESP_LOGI(TAG, "starting pulse on GPIO %d; delay = %d, limit = %d", pin, delay_ms, limit);
     string taskName = "kbf_gpio_p" + std::to_string(pin);
     if (pulseTask != nullptr && pulseTask->isRunning()) {
@@ -34,10 +36,10 @@ void kbf::gpio::Output::startPulse(int delay_ms, int limit) {
     pulseDelay = delay_ms;
     pulseLimit = limit;
     delete pulseTask;
-    pulseTask = new kbf::Task(taskName, pulseCallback, this);
+    pulseTask = new Task(taskName, pulseCallback, this);
 }
 
-void kbf::gpio::Output::stopPulse() {
+void gpio::Output::stopPulse() {
     ESP_LOGI(TAG, "stopping pulse on GPIO %d", pin);
     if (pulseTask == nullptr) {
         ESP_LOGE(TAG, "pulse task not running");
@@ -47,7 +49,7 @@ void kbf::gpio::Output::stopPulse() {
     low();
 }
 
-void kbf::gpio::Output::pulseCallback(void *arg_ptr) {
+void gpio::Output::pulseCallback(void *arg_ptr) {
     auto output = static_cast<Output *>(arg_ptr);
     int count = 0;
     while (output->pulseLimit < 0 || count++ < output->pulseLimit) {

+ 2 - 2
src/http/client.cpp

@@ -1,9 +1,9 @@
-#include "http/client.h"
+#include "kbf/http/client.h"
 
 #include <freertos/task.h>
 #include <esp_log.h>
 
-#include "kbf_assert.h"
+#include "kbf/macros.h"
 
 using namespace kbf;
 using std::make_shared;

+ 10 - 9
src/http/common.cpp

@@ -1,4 +1,4 @@
-#include "kbf_http.h"
+#include "kbf/http/common.h"
 
 #include <regex>
 #include <utility>
@@ -6,10 +6,11 @@
 #include <esp_log.h>
 #include <esp_http_server.h>
 
-#include "kbf_assert.h"
+#include "kbf/macros.h"
 
+using namespace kbf;
 
-void kbf::http::HTTPObject::parseToMap(map<string, string> &target, const string &buffer) {
+void http::HTTPObject::parseToMap(map<string, string> &target, const string &buffer) {
     auto queryString = string(buffer);
 
     std::regex  regex("([\\w]+)=([\\w]+)");
@@ -21,7 +22,7 @@ void kbf::http::HTTPObject::parseToMap(map<string, string> &target, const string
     }
 }
 
-kbf::http::Request::Request(httpd_req_t *httpdRequest) {
+http::Request::Request(httpd_req_t *httpdRequest) {
     this->httpdRequest = httpdRequest;
     method = static_cast<Method>(httpdRequest->method);
     uri    = httpdRequest->uri;
@@ -33,7 +34,7 @@ kbf::http::Request::Request(httpd_req_t *httpdRequest) {
     readBody();
 }
 
-string kbf::http::Request::readHeader(const string &header) {
+string http::Request::readHeader(const string &header) {
     auto len = httpd_req_get_hdr_value_len(httpdRequest, header.c_str());
     if (len == 0) {
         ESP_LOGD(TAG, "  header not found: %s", header.c_str());
@@ -46,7 +47,7 @@ string kbf::http::Request::readHeader(const string &header) {
     return buffer;
 }
 
-void kbf::http::Request::readQuery() {
+void http::Request::readQuery() {
     auto queryLen = httpd_req_get_url_query_len(httpdRequest);
     char buffer[queryLen + 1];
 
@@ -61,7 +62,7 @@ void kbf::http::Request::readQuery() {
     parseToMap(query, buffer);
 }
 
-void kbf::http::Request::readBody() {
+void http::Request::readBody() {
     if (httpdRequest->content_len == 0) {
         return;
     }
@@ -91,10 +92,10 @@ void kbf::http::Request::readBody() {
     }
 }
 
-kbf::http::Response::Response(string body, int status, string contentType) : HTTPObject(std::move(body)),
+http::Response::Response(string body, int status, string contentType) : HTTPObject(std::move(body)),
                                                                              status(status),
                                                                              contentType(std::move(contentType)) {
 }
 
-kbf::http::HTTPObject::HTTPObject(string body) : body(std::move(body)) {
+http::HTTPObject::HTTPObject(string body) : body(std::move(body)) {
 }

+ 2 - 3
src/http/server.cpp

@@ -1,13 +1,12 @@
-#include "http/server.h"
+#include "kbf/http/server.h"
 
 #include <esp_log.h>
 #include <memory>
 
-#include "kbf_assert.h"
+#include "kbf/macros.h"
 
 using namespace kbf;
 
-
 http::Server &http::Server::route(http::Server::Route route) {
     ESP_LOGD(TAG, "adding route: %s", route.uri.c_str());
     routes.push_back(route);

+ 2 - 0
src/kbf.cpp

@@ -2,9 +2,11 @@
 
 #include <freertos/FreeRTOS.h>
 #include <freertos/task.h>
+#include <esp_log.h>
 
 static constexpr const char *TAG = "kbf";
 
 void kbf::sleep(uint32_t milliseconds) {
+    ESP_LOGD(TAG, "sleeping task for %d ms", milliseconds);
     vTaskDelay(milliseconds / portTICK_PERIOD_MS);
 }

+ 12 - 8
src/kbf_net.cpp → src/net.cpp

@@ -1,4 +1,4 @@
-#include "kbf_net.h"
+#include "kbf/net.h"
 
 #include <sstream>
 #include <iomanip>
@@ -7,9 +7,13 @@
 #include <esp_system.h>
 #include <esp_log.h>
 
-#include "kbf_assert.h"
+#include "kbf/macros.h"
 
-std::string kbf::net::MAC::str() const {
+using std::string;
+
+using namespace kbf;
+
+string net::MAC::str() const {
     using std::setw;
     std::stringstream ss;
     ss << std::hex << std::setfill('0') << setw(2) << std::right << std::uppercase
@@ -22,19 +26,19 @@ std::string kbf::net::MAC::str() const {
     return ss.str();
 }
 
-kbf::net::MAC::MAC(const uint8_t addr[6]) {
+net::MAC::MAC(const uint8_t addr[6]) {
     // TODO look up some (syntax) magic for array initialization
     for (int i = 0; i < 6; i++) {
         this->addr[i] = addr[i];
     }
 }
 
-void kbf::net::setMac(const MAC &mac) {
+void net::setMac(const MAC &mac) {
     ESP_LOGI(TAG, "setting base MAC address to %s", mac.str().c_str());
     CHECK(esp_base_mac_addr_set(mac.addr));
 }
 
-kbf::net::MAC kbf::net::getMac() {
+net::MAC net::getMac() {
     uint8_t addr[6]{};
     CHECK(esp_base_mac_addr_get(addr));
 
@@ -43,6 +47,6 @@ kbf::net::MAC kbf::net::getMac() {
     return mac;
 }
 
-std::string kbf::net::IP::str() const {
-    return std::string(inet_ntoa(addr));
+string net::IP::str() const {
+    return string(inet_ntoa(addr));
 }

+ 32 - 29
src/kbf_nvs.cpp → src/nvs.cpp

@@ -1,16 +1,18 @@
-#include "kbf_nvs.h"
+#include "kbf/nvs.h"
 
 #include <esp_log.h>
 #include <nvs_flash.h>
 
-#include "kbf_assert.h"
+#include "kbf/macros.h"
 
-static constexpr const char *TAG = "kbf::nvs";
+using namespace kbf;
+
+static constexpr const char *TAG = "nvs";
 
 static std::atomic<bool> initialized = {false};
 
-void kbf::nvs::init() {
-    ESP_LOGI(TAG, "init()");
+void nvs::init() {
+    ESP_LOGD(TAG, "init()");
 
     if (initialized) {
         ESP_LOGW(TAG, "NVS already initialized");
@@ -27,30 +29,31 @@ void kbf::nvs::init() {
     initialized = true;
 }
 
-void kbf::nvs::erase() {
+void nvs::erase() {
     ESP_LOGW(TAG, "erasing flash");
     CHECK(nvs_flash_erase());
     initialized = false;
 }
 
-kbf::nvs::NVS::NVS(const string &name) : name(name) {
+nvs::NVS::NVS(const string &name) : name(name) {
+    ESP_LOGD(TAG, "NVS(\"%s\")", name.c_str());
+
     if (!initialized) {
         init();
     }
 
-    ESP_LOGI(TAG, "opening handle for namespace \"%s\"", name.c_str());
     CHECK(nvs_open(name.c_str(), NVS_READWRITE, &handle));
 }
 
-kbf::nvs::NVS::~NVS() {
-    ESP_LOGI(TAG, "closing handle for namespace \"%s\"", name.c_str());
+nvs::NVS::~NVS() {
+    ESP_LOGD(TAG, "~NVS(\"%s\")", name.c_str());
     nvs_close(handle);
 }
 
 static bool checkReadError(const string &key, const string &value, esp_err_t err) {
     switch (err) {
         case ESP_OK:
-            ESP_LOGI(TAG, "read %s from %s", value.c_str(), key.c_str());
+            ESP_LOGD(TAG, "read %s from %s", value.c_str(), key.c_str());
             return true;
         case ESP_ERR_NVS_NOT_FOUND:
             ESP_LOGW(TAG, "key not found: %s", key.c_str());
@@ -62,79 +65,79 @@ static bool checkReadError(const string &key, const string &value, esp_err_t err
 }
 
 template<>
-bool kbf::nvs::NVS::read<int8_t>(const string &key, int8_t &value) {
+bool nvs::NVS::read<int8_t>(const string &key, int8_t &value) {
     esp_err_t err = nvs_get_i8(handle, key.c_str(), &value);
     return checkReadError(key, std::to_string(value), err);
 }
 
 template<>
-bool kbf::nvs::NVS::read<uint8_t>(const string &key, uint8_t &value) {
+bool nvs::NVS::read<uint8_t>(const string &key, uint8_t &value) {
     esp_err_t err = nvs_get_u8(handle, key.c_str(), &value);
     return checkReadError(key, std::to_string(value), err);
 }
 
 template<>
-bool kbf::nvs::NVS::read<int16_t>(const string &key, int16_t &value) {
+bool nvs::NVS::read<int16_t>(const string &key, int16_t &value) {
     esp_err_t err = nvs_get_i16(handle, key.c_str(), &value);
     return checkReadError(key, std::to_string(value), err);
 }
 
 template<>
-bool kbf::nvs::NVS::read<uint16_t>(const string &key, uint16_t &value) {
+bool nvs::NVS::read<uint16_t>(const string &key, uint16_t &value) {
     esp_err_t err = nvs_get_u16(handle, key.c_str(), &value);
     return checkReadError(key, std::to_string(value), err);
 }
 
 template<>
-bool kbf::nvs::NVS::read<int32_t>(const string &key, int32_t &value) {
+bool nvs::NVS::read<int32_t>(const string &key, int32_t &value) {
     esp_err_t err = nvs_get_i32(handle, key.c_str(), &value);
     return checkReadError(key, std::to_string(value), err);
 }
 
 template<>
-bool kbf::nvs::NVS::read<uint32_t>(const string &key, uint32_t &value) {
+bool nvs::NVS::read<uint32_t>(const string &key, uint32_t &value) {
     esp_err_t err = nvs_get_u32(handle, key.c_str(), &value);
     return checkReadError(key, std::to_string(value), err);
 }
 
 template<>
-void kbf::nvs::NVS::write<int8_t>(const string &key, int8_t &value) {
-    ESP_LOGI(TAG, "writing %d to %s", value, key.c_str());
+void nvs::NVS::write<int8_t>(const string &key, int8_t &value) {
+    ESP_LOGD(TAG, "writing %d to %s", value, key.c_str());
     CHECK(nvs_set_i8(handle, key.c_str(), value));
     CHECK(nvs_commit(handle));
 }
 
 template<>
-void kbf::nvs::NVS::write<uint8_t>(const string &key, uint8_t &value) {
-    ESP_LOGI(TAG, "writing %d to %s", value, key.c_str());
+void nvs::NVS::write<uint8_t>(const string &key, uint8_t &value) {
+    ESP_LOGD(TAG, "writing %d to %s", value, key.c_str());
     CHECK(nvs_set_u8(handle, key.c_str(), value));
     CHECK(nvs_commit(handle));
 }
 
 template<>
-void kbf::nvs::NVS::write<int16_t>(const string &key, int16_t &value) {
-    ESP_LOGI(TAG, "writing %d to %s", value, key.c_str());
+void nvs::NVS::write<int16_t>(const string &key, int16_t &value) {
+    ESP_LOGD(TAG, "writing %d to %s", value, key.c_str());
     CHECK(nvs_set_i16(handle, key.c_str(), value));
     CHECK(nvs_commit(handle));
 }
 
 template<>
-void kbf::nvs::NVS::write<uint16_t>(const string &key, uint16_t &value) {
-    ESP_LOGI(TAG, "writing %d to %s", value, key.c_str());
+void nvs::NVS::write<uint16_t>(const string &key, uint16_t &value) {
+    ESP_LOGD(TAG, "writing %d to %s", value, key.c_str());
     CHECK(nvs_set_u16(handle, key.c_str(), value));
     CHECK(nvs_commit(handle));
 }
 
 template<>
-void kbf::nvs::NVS::write<int32_t>(const string &key, int32_t &value) {
-    ESP_LOGI(TAG, "writing %d to %s", value, key.c_str());
+void nvs::NVS::write<int32_t>(const string &key, int32_t &value) {
+    ESP_LOGD(TAG, "writing %d to %s", value, key.c_str());
     CHECK(nvs_set_i32(handle, key.c_str(), value));
     CHECK(nvs_commit(handle));
 }
 
 template<>
-void kbf::nvs::NVS::write<uint32_t>(const string &key, uint32_t &value) {
-    ESP_LOGI(TAG, "writing %u to %s", value, key.c_str());
+void nvs::NVS::write<uint32_t>(const string &key, uint32_t &value) {
+    ESP_LOGD(TAG, "writing %u to %s", value, key.c_str());
     CHECK(nvs_set_u32(handle, key.c_str(), value));
     CHECK(nvs_commit(handle));
 }

+ 2 - 2
src/kbf_spiffs.cpp → src/spiffs.cpp

@@ -1,8 +1,8 @@
-#include "kbf_spiffs.h"
+#include "kbf/spiffs.h"
 
 #include <esp_log.h>
 
-#include "kbf_assert.h"
+#include "kbf/macros.h"
 
 kbf::SPIFFS::SPIFFS(const string &mountPoint, const char *label) :
         config({

+ 6 - 6
src/kbf_task.cpp → src/task.cpp

@@ -1,17 +1,17 @@
-#include "kbf_task.h"
+#include "kbf/task.h"
 
 #include <utility>
 
 #include <esp_log.h>
 
-#include <kbf_assert.h>
+#include <kbf/macros.h>
 
 static constexpr const char *TAG = "kbf::task";
 
 kbf::Task::Task(string name, TaskFunc function, void *data) : function(function),
                                                                     name(std::move(name)),
                                                                     data(data) {
-    ESP_LOGI(TAG, "creating task: %s", this->name.c_str());
+    ESP_LOGD(TAG, "creating task: %s", this->name.c_str());
 
     handle = nullptr;
     auto ret = xTaskCreate(task, name.c_str(), 4096, this, 5, &handle);
@@ -30,7 +30,7 @@ kbf::Task::~Task() {
 
 void kbf::Task::stop() {
     if (running) {
-        ESP_LOGI(TAG, "stopping task: %s", name.c_str());
+        ESP_LOGD(TAG, "stopping task: %s", name.c_str());
         vTaskDelete(handle);
         running = false;
     } else {
@@ -44,11 +44,11 @@ void kbf::Task::task(void *pvParameters) {
         ABORT("task has no name! debug me");
     }
 
-    ESP_LOGI(TAG, "begin task: %s", task->name.c_str());
+    ESP_LOGD(TAG, "begin task: %s", task->name.c_str());
     task->running = true;
     task->function(task->data);
     task->running = false;
-    ESP_LOGI(TAG, "end task: %s", task->name.c_str());
+    ESP_LOGD(TAG, "end task: %s", task->name.c_str());
     vTaskDelete(task->handle);
 }
 

+ 17 - 16
src/kbf_uart.cpp → src/uart.cpp

@@ -1,4 +1,4 @@
-#include "kbf_uart.h"
+#include "kbf/uart.h"
 
 #include <string_view>
 
@@ -8,11 +8,13 @@
 #include <freertos/queue.h>
 
 #include "kbf.h"
-#include "kbf_assert.h"
+#include "kbf/macros.h"
 
 using std::string_view;
 
-kbf::UART::UART(int port, int baudRate) : port(port) {
+using namespace kbf;
+
+UART::UART(int port, int baudRate) : port(port) {
     ESP_LOGI(TAG, "UART(%d, %d)", port, baudRate);
 
     if (isDriverInstalled(port)) {
@@ -33,10 +35,10 @@ kbf::UART::UART(int port, int baudRate) : port(port) {
 
     CHECK(uart_set_pin(port, NO_CHANGE, NO_CHANGE, NO_CHANGE, NO_CHANGE));
 
-    task = new kbf::Task("kbf_uart_" + std::to_string(port), taskFunc, this);
+    task = new Task("kbf_uart_" + std::to_string(port), taskFunc, this);
 }
 
-kbf::UART::~UART() {
+UART::~UART() {
     ESP_LOGI(TAG, "~UART()");
     esp_err_t err = uart_wait_tx_done(port, WAIT_ON_DESTROY);
     if (err == ESP_ERR_TIMEOUT) {
@@ -47,17 +49,16 @@ kbf::UART::~UART() {
     CHECK(uart_driver_delete(port));
 }
 
-void kbf::UART::setPins(int rx, int tx, int rts, int cts) const {
+void UART::setPins(int rx, int tx, int rts, int cts) const {
     CHECK(uart_set_pin(port, rx, tx, rts, cts));
 }
 
-bool kbf::UART::isDriverInstalled(int port) {
+bool UART::isDriverInstalled(int port) {
     return uart_is_driver_installed(port);
 }
 
-void kbf::UART::write(const string &data) const {
-    ESP_LOGI(TAG, "write(len = %d)", data.size() + 1);
-//    ESP_LOGI(TAG, "write(%s); len = %d", data.c_str(), data.length() + 1);
+void UART::write(const string &data) const {
+    ESP_LOGD(TAG, "write(%s); len = %d", data.c_str(), data.size() + 1);
 
     auto len = uart_write_bytes(port, data.c_str(), data.size() + 1);
 
@@ -72,7 +73,7 @@ void kbf::UART::write(const string &data) const {
     }
 }
 
-string kbf::UART::read() {
+string UART::read() {
     ESP_LOGI(TAG, "read()");
     mutex.lock();
     buffer.clear();
@@ -83,23 +84,23 @@ string kbf::UART::read() {
         mutex.lock();
         if (!buffer.empty()) break;
         mutex.unlock();
-        kbf::sleep(200); // FIXME keeps the tests from failing... *sad face*
+        sleep(200); // FIXME keeps the tests from failing... *sad face*
     }
 
     return buffer;
 }
 
-void kbf::UART::waitFor(const string &signal) {
+void UART::waitFor(const string &signal) {
     while (read() != signal);
 }
 
-[[noreturn]] void kbf::UART::taskFunc(void *uartInstance) {
+[[noreturn]] void UART::taskFunc(void *uartInstance) {
     auto uart = static_cast<UART *>(uartInstance);
 
     uart_event_t event;
     while (true) {
         if (xQueueReceive(uart->queue, &event, portMAX_DELAY) == pdFALSE) continue;
-//        ESP_LOGI(TAG, "event: %d", event.type);
+        ESP_LOGD(TAG, "event: %d", event.type);
 
         if (event.type == UART_DATA) {
             if (event.size > BUFFER_SIZE) {
@@ -109,7 +110,7 @@ void kbf::UART::waitFor(const string &signal) {
             auto buf = new char[BUFFER_SIZE];
             int  len = uart_read_bytes(uart->port, buf, event.size, portMAX_DELAY);
             if (len < 0) CHECK(len); // will abort
-            ESP_LOGI(TAG, "read %d bytes", len);
+            ESP_LOGD(TAG, "read %d bytes", len);
 
             uart->mutex.lock();
             uart->buffer = buf;

+ 2 - 2
src/wifi/ap.cpp

@@ -1,6 +1,6 @@
-#include "kbf_wifi.h"
+#include "kbf/wifi.h"
 
-#include "kbf_assert.h"
+#include "kbf/macros.h"
 
 kbf::wifi::AP::AP(string ssid, string password) : ssid(std::move(ssid)), password(std::move(password)) {
     ESP_LOGI(TAG, "AP()");

+ 3 - 3
src/wifi/driver.cpp

@@ -1,4 +1,4 @@
-#include "kbf_wifi.h"
+#include "kbf/wifi.h"
 
 #include <utility>
 #include <memory>
@@ -12,8 +12,8 @@
 #include <esp_wifi.h>
 #include <nvs_flash.h>
 
-#include "kbf_assert.h"
-#include "kbf_nvs.h"
+#include "kbf/macros.h"
+#include "kbf/nvs.h"
 
 using std::shared_ptr;
 

+ 29 - 30
src/wifi/sta.cpp

@@ -1,27 +1,26 @@
-#include "kbf_wifi.h"
+#include "kbf/wifi.h"
 
-#include "kbf_assert.h"
-#include "kbf_nvs.h"
+#include "kbf/macros.h"
+#include "kbf/nvs.h"
 
+using namespace kbf;
 
-kbf::wifi::STA::STA() {
-    ESP_LOGI(TAG, "STA()");
-
+wifi::STA::STA() {
+    ESP_LOGD(TAG, "STA()");
     config.pmf_cfg = {true, false};
-
 }
 
-kbf::wifi::STA::~STA() {
-    ESP_LOGI(TAG, "~STA()");
+wifi::STA::~STA() {
+    ESP_LOGD(TAG, "~STA()");
     unregisterEventHandlers();
 }
 
-shared_ptr<kbf::wifi::STA> kbf::wifi::STA::create() {
+shared_ptr<wifi::STA> wifi::STA::create() {
     return shared_ptr<STA>(new STA());
 }
 
-void kbf::wifi::STA::registerEventHandlers() {
-    ESP_LOGI(TAG, "registerEventHandlers");
+void wifi::STA::registerEventHandlers() {
+    ESP_LOGD(TAG, "registerEventHandlers");
 
     CHECK(esp_event_handler_instance_register(
             WIFI_EVENT, WIFI_EVENT_STA_START, &handleStart, this, &startHandler));
@@ -36,8 +35,8 @@ void kbf::wifi::STA::registerEventHandlers() {
             IP_EVENT, IP_EVENT_STA_GOT_IP, &handleGotIp, this, &gotIpHandler));
 }
 
-void kbf::wifi::STA::unregisterEventHandlers() {
-    ESP_LOGI(TAG, "unregisterEventHandlers");
+void wifi::STA::unregisterEventHandlers() {
+    ESP_LOGD(TAG, "unregisterEventHandlers");
 
     CHECK(esp_event_handler_instance_unregister(WIFI_EVENT, WIFI_EVENT_STA_START, &startHandler));
     CHECK(esp_event_handler_instance_unregister(WIFI_EVENT, WIFI_EVENT_STA_STOP, &stopHandler));
@@ -53,7 +52,7 @@ void kbf::wifi::STA::unregisterEventHandlers() {
     CHECK(esp_event_handler_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, &handleGotIp));
 }
 
-void kbf::wifi::STA::connect(const string &ssid, const string &password, int maxRetryAttempts) {
+void wifi::STA::connect(const string &ssid, const string &password, int maxRetryAttempts) {
     ESP_LOGI(TAG, "connect()");
 
     wifi_config_t wifiConfig = {.sta = config};
@@ -62,7 +61,7 @@ void kbf::wifi::STA::connect(const string &ssid, const string &password, int max
     retryNum = 0;
     retryMax = maxRetryAttempts;
 
-    ESP_LOGI(TAG, "SSID: \"%s\"; pass: \"%s\"; maxRetry = %d", wifiConfig.sta.ssid, wifiConfig.sta.password,
+    ESP_LOGD(TAG, "SSID: \"%s\"; pass: \"%s\"; maxRetry = %d", wifiConfig.sta.ssid, wifiConfig.sta.password,
              maxRetryAttempts);
 
     // TODO check station_example_main.c; they use ESP_IF_WIFI_STA which doesn't compile in C++
@@ -70,40 +69,40 @@ void kbf::wifi::STA::connect(const string &ssid, const string &password, int max
     CHECK(esp_wifi_connect());
 }
 
-void kbf::wifi::STA::disconnect() {
+void wifi::STA::disconnect() {
     ESP_LOGI(TAG, "disconnect()");
     retryMax = 0;
     CHECK(esp_wifi_disconnect());
 }
 
-void kbf::wifi::STA::handleStart(void *arg, esp_event_base_t baseType, int32_t eventId, void *) {
-    ESP_LOGI(TAG, "handleStart()");
+void wifi::STA::handleStart(void *arg, esp_event_base_t baseType, int32_t eventId, void *) {
+    ESP_LOGD(TAG, "handleStart()");
     auto instance = static_cast<STA *>(arg);
     if (instance->onStart) instance->onStart();
 }
 
-void kbf::wifi::STA::handleStop(void *arg, esp_event_base_t baseType, int32_t eventId, void *) {
-    ESP_LOGI(TAG, "handleStop()");
+void wifi::STA::handleStop(void *arg, esp_event_base_t baseType, int32_t eventId, void *) {
+    ESP_LOGD(TAG, "handleStop()");
     auto instance = static_cast<STA *>(arg);
     if (instance->onStop) instance->onStop();
 }
 
-void kbf::wifi::STA::handleConnect(void *arg, esp_event_base_t baseType, int32_t eventId, void *) {
-    ESP_LOGI(TAG, "handleConnect()");
+void wifi::STA::handleConnect(void *arg, esp_event_base_t baseType, int32_t eventId, void *) {
+    ESP_LOGD(TAG, "handleConnect()");
     auto instance = static_cast<STA *>(arg);
     if (instance->onConnect) instance->onConnect();
 }
 
-void kbf::wifi::STA::handleDisconnect(void *arg, esp_event_base_t baseType, int32_t eventId, void *) {
-    ESP_LOGI(TAG, "handleDisconnect()");
+void wifi::STA::handleDisconnect(void *arg, esp_event_base_t baseType, int32_t eventId, void *) {
+    ESP_LOGD(TAG, "handleDisconnect()");
     auto instance = static_cast<STA *>(arg);
 
     if (instance->retryNum++ < instance->retryMax) {
         if (instance->onReconnecting && !instance->onReconnecting(instance->retryNum, instance->retryMax)) {
-            ESP_LOGI(TAG, "retry attempt cancelled");
+            ESP_LOGI(TAG, "reconnect attempt cancelled");
             if (instance->onDisconnect) instance->onDisconnect();
         } else {
-            ESP_LOGI(TAG, "retrying, attempt %d / %d", instance->retryNum, instance->retryMax);
+            ESP_LOGI(TAG, "reconnecting, attempt %d / %d", instance->retryNum, instance->retryMax);
             esp_wifi_connect();
         }
     } else {
@@ -112,12 +111,12 @@ void kbf::wifi::STA::handleDisconnect(void *arg, esp_event_base_t baseType, int3
     }
 }
 
-void kbf::wifi::STA::handleGotIp(void *arg, esp_event_base_t baseType, int32_t eventId, void *pEventData) {
-    ESP_LOGI(TAG, "handleGotIp()");
+void wifi::STA::handleGotIp(void *arg, esp_event_base_t baseType, int32_t eventId, void *pEventData) {
+    ESP_LOGD(TAG, "handleGotIp()");
     auto instance  = static_cast<STA *>(arg);
     auto eventData = static_cast<ip_event_got_ip_t *>(pEventData);
 
-    instance->m_ip = kbf::net::IP(eventData->ip_info.ip);
+    instance->m_ip = net::IP(eventData->ip_info.ip);
     if (instance->onIp) instance->onIp();
     instance->retryNum = 0;
 }

+ 3 - 4
test/test_http.cpp

@@ -3,10 +3,9 @@
 #include <atomic>
 
 #include "kbf.h"
-#include "kbf_wifi.h"
-#include "kbf_http.h"
-#include "http/server.h"
-#include "http/client.h"
+#include "kbf/wifi.h"
+#include "kbf/http/server.h"
+#include "kbf/http/client.h"
 
 using namespace kbf;
 

+ 7 - 5
test/test_net.cpp

@@ -1,19 +1,21 @@
 #include <unity.h>
 
-#include "kbf_net.h"
+#include "kbf/net.h"
+
+using namespace kbf;
 
 TEST_CASE("MAC address functions", "[kbf_net]") {
     uint8_t addr[] = {0, 0, 11, 128, 176, 255};
 
-    auto mac = kbf::net::MAC(addr);
+    auto mac = net::MAC(addr);
     TEST_ASSERT_EQUAL_STRING_MESSAGE("00:00:0B:80:B0:FF", mac.str().c_str(), "ctor / str()");
 
-    kbf::net::setMac(mac);
+    net::setMac(mac);
 
-    TEST_ASSERT_EQUAL_STRING_MESSAGE(mac.str().c_str(), kbf::net::getMac().str().c_str(), "getMac");
+    TEST_ASSERT_EQUAL_STRING_MESSAGE(mac.str().c_str(), net::getMac().str().c_str(), "getMac");
 }
 
 TEST_CASE("IP address functions", "[kbf_net]") {
-    auto ip = kbf::net::IP({2952898752});
+    auto ip = net::IP({2952898752});
     TEST_ASSERT_EQUAL_STRING_MESSAGE("192.168.1.176", ip.str().c_str(), "str()");
 }

+ 1 - 1
test/test_nvs.cpp

@@ -1,6 +1,6 @@
 #include <unity.h>
 
-#include <kbf_nvs.h>
+#include <kbf/nvs.h>
 
 TEST_CASE("NVS write/read numeric values", "[kbf_nvs]") {
     static constexpr const char *KEY = "kbf_nvs_test";

+ 1 - 1
test/test_spiffs.cpp

@@ -3,7 +3,7 @@
 #include <iostream>
 #include <fstream>
 
-#include "kbf_spiffs.h"
+#include "kbf/spiffs.h"
 
 using std::ifstream;
 using std::ofstream;

+ 1 - 1
test/test_task.cpp

@@ -3,7 +3,7 @@
 #include <atomic>
 
 #include "kbf.h"
-#include "kbf_task.h"
+#include "kbf/task.h"
 
 /** delay between cycles */
 #define KBF_TASK_TEST_DELAY 100

+ 1 - 2
test/test_uart.cpp

@@ -4,14 +4,13 @@
 #include <memory>
 
 #include "kbf.h"
-#include "kbf_uart.h"
+#include "kbf/uart.h"
 
 #define KBF_UART_TEST_ORIGINAL "Just some data."
 #define KBF_UART_TEST_FILTERED "Just_some_data."
 
 #define KBF_UART_TEST_WAIT_SIGNAL "signal"
 
-using std::make_shared;
 using std::shared_ptr;
 
 shared_ptr<kbf::UART> setupUart() {

+ 1 - 1
test/test_wifi.cpp

@@ -5,7 +5,7 @@
 #include <atomic>
 
 #include <kbf.h>
-#include <kbf_wifi.h>
+#include <kbf/wifi.h>
 
 using std::cout;
 using std::endl;