Skip to content

Commit

Permalink
chore: Reformat all files to c standard
Browse files Browse the repository at this point in the history
  • Loading branch information
jniebuhr committed Dec 19, 2024
1 parent 880140e commit 9a1d1cf
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 72 deletions.
4 changes: 3 additions & 1 deletion lib/NimBLEComm/src/NimBLEClientController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ void NimBLEClientController::scan() {

void NimBLEClientController::registerTempReadCallback(const temp_read_callback_t &callback) { tempReadCallback = callback; }

void NimBLEClientController::registerRemoteErrorCallback(const remote_err_callback_t &callback) { remoteErrorCallback = callback; }
void NimBLEClientController::registerRemoteErrorCallback(const remote_err_callback_t &callback) {
remoteErrorCallback = callback;
}

bool NimBLEClientController::connectToServer() {
Serial.println("Connecting to advertised device");
Expand Down
12 changes: 9 additions & 3 deletions lib/NimBLEComm/src/NimBLEServerController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,17 @@ void NimBLEServerController::sendError(int errorCode) {
}
}

void NimBLEServerController::registerTempControlCallback(const temp_control_callback_t &callback) { tempControlCallback = callback; }
void NimBLEServerController::registerTempControlCallback(const temp_control_callback_t &callback) {
tempControlCallback = callback;
}

void NimBLEServerController::registerPumpControlCallback(const pump_control_callback_t &callback) { pumpControlCallback = callback; }
void NimBLEServerController::registerPumpControlCallback(const pump_control_callback_t &callback) {
pumpControlCallback = callback;
}

void NimBLEServerController::registerValveControlCallback(const pin_control_callback_t &callback) { valveControlCallback = callback; }
void NimBLEServerController::registerValveControlCallback(const pin_control_callback_t &callback) {
valveControlCallback = callback;
}

void NimBLEServerController::registerAltControlCallback(const pin_control_callback_t &callback) { altControlCallback = callback; }

Expand Down
12 changes: 4 additions & 8 deletions lib/OTA/src/GitHubOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include "semver_extensions.h"
#include <ArduinoJson.h>

GitHubOTA::GitHubOTA(const String &version, const String &release_url, const String &firmware_name, const String &filesystem_name) {
GitHubOTA::GitHubOTA(const String &version, const String &release_url, const String &firmware_name,
const String &filesystem_name) {
ESP_LOGV("GitHubOTA", "GitHubOTA(version: %s, firmware_name: %s, fetch_url_via_redirect: %d)\n", version.c_str(),
firmware_name.c_str(), fetch_url_via_redirect);

Expand Down Expand Up @@ -44,10 +45,7 @@ String GitHubOTA::getCurrentVersion() const {
return String(_latest_version.major) + "." + String(_latest_version.minor) + "." + _latest_version.patch;
}


bool GitHubOTA::isUpdateAvailable() const {
return update_required(_latest_version, _version);
}
bool GitHubOTA::isUpdateAvailable() const { return update_required(_latest_version, _version); }

void GitHubOTA::update() {
const char *TAG = "update";
Expand Down Expand Up @@ -76,9 +74,7 @@ void GitHubOTA::update() {
ESP_LOGI(TAG, "No updates found\n");
}

void GitHubOTA::setReleaseUrl(const String& release_url) {
this->_release_url = release_url;
}
void GitHubOTA::setReleaseUrl(const String &release_url) { this->_release_url = release_url; }

HTTPUpdateResult GitHubOTA::update_firmware(const String &url) {
const char *TAG = "update_firmware";
Expand Down
4 changes: 3 additions & 1 deletion lib/OTA/src/GitHubOTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "semver.h"

enum class OTAPhase { DISPLAY_FIRMWARE, DISPLAY_FS, CONTROLLER_FS };

extern const uint8_t x509_crt_imported_bundle_bin_start[] asm("_binary_x509_crt_bundle_start");

class GitHubOTA {
Expand All @@ -17,7 +19,7 @@ class GitHubOTA {
bool isUpdateAvailable() const;
String getCurrentVersion() const;
void update();
void setReleaseUrl(const String& release_url);
void setReleaseUrl(const String &release_url);

private:
HTTPUpdate Updater;
Expand Down
4 changes: 2 additions & 2 deletions lib/OTA/src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "semver_extensions.h"
#include <ArduinoJson.h>

String get_updated_base_url_via_redirect(WiFiClientSecure& wifi_client, String& release_url) {
String get_updated_base_url_via_redirect(WiFiClientSecure &wifi_client, String &release_url) {
const char *TAG = "get_updated_base_url_via_redirect";

String location = get_redirect_location(wifi_client, release_url);
Expand All @@ -26,7 +26,7 @@ String get_updated_base_url_via_redirect(WiFiClientSecure& wifi_client, String&
return base_url;
}

String get_redirect_location(WiFiClientSecure& wifi_client, String& initial_url) {
String get_redirect_location(WiFiClientSecure &wifi_client, String &initial_url) {
const char *TAG = "get_redirect_location";
ESP_LOGV(TAG, "initial_url: %s\n", initial_url.c_str());

Expand Down
4 changes: 2 additions & 2 deletions lib/OTA/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

using Updater = HTTPUpdate;

String get_updated_base_url_via_redirect(WiFiClientSecure& wifi_client, String& release_url);
String get_redirect_location(WiFiClientSecure& wifi_client, String& initial_url);
String get_updated_base_url_via_redirect(WiFiClientSecure &wifi_client, String &release_url);
String get_redirect_location(WiFiClientSecure &wifi_client, String &initial_url);

void print_update_result(Updater updater, HTTPUpdateResult result, const char *TAG);

Expand Down
3 changes: 3 additions & 0 deletions scripts/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

find src lib \( -iname '*.h' -o -iname '*.c' -o -iname '*.cpp' \) ! -path './src/display/ui/**/*' ! -path './src/display/drivers/**/*' | xargs clang-format -i
4 changes: 1 addition & 3 deletions src/controller/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ void thermal_runaway_shutdown() {
serverController.sendError(ERROR_CODE_RUNAWAY);
}

void control_heater(int out) {
analogWrite(HEATER_PIN, out);
}
void control_heater(int out) { analogWrite(HEATER_PIN, out); }

void control_pump() {
unsigned long currentMillis = millis();
Expand Down
18 changes: 9 additions & 9 deletions src/controller/main.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#ifndef MAIN_H
#define MAIN_H

#include "NimBLEServerController.h"
#include <Arduino.h>
#include <SPI.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <SPI.h>
#include "NimBLEServerController.h"

// GPIO Pin Definitions
#define HEATER_PIN 14
#define PUMP_PIN 9
#define VALVE_PIN 10
#define ALT_PIN 11
#define MAX6675_SCK_PIN 6
#define MAX6675_CS_PIN 7
#define HEATER_PIN 14
#define PUMP_PIN 9
#define VALVE_PIN 10
#define ALT_PIN 11
#define MAX6675_SCK_PIN 6
#define MAX6675_CS_PIN 7
#define MAX6675_MISO_PIN 4

constexpr size_t TEMP_UPDATE_INTERVAL_MS = 1000;
Expand Down Expand Up @@ -48,4 +48,4 @@ void thermal_runaway_shutdown(void);
void start_pid_autotune(void);
void stop_pid_autotune(void);

#endif //MAIN_H
#endif // MAIN_H
34 changes: 16 additions & 18 deletions src/display/core/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include "../plugins/mDNSPlugin.h"
#include "../ui/ui.h"
#include "constants.h"
#include <SPIFFS.h>
#include <WiFiClient.h>
#include <ctime>
#include <SPIFFS.h>

Controller::Controller()
: timer(nullptr), mode(MODE_BREW), currentTemp(0), activeUntil(0), grindActiveUntil(0), lastPing(0), lastProgress(0),
Expand Down Expand Up @@ -99,12 +99,8 @@ void Controller::setupWifi() {
Serial.println(WiFi.localIP());
}

pluginManager->on("ota:update:start", [this](Event const &) {
this->updating = true;
});
pluginManager->on("ota:update:end", [this](Event const &) {
this->updating = false;
});
pluginManager->on("ota:update:start", [this](Event const &) { this->updating = true; });
pluginManager->on("ota:update:end", [this](Event const &) { this->updating = false; });

pluginManager->trigger("controller:wifi:connect", "AP", isApConnection ? 1 : 0);
}
Expand Down Expand Up @@ -233,14 +229,14 @@ void Controller::updateUiActive() const {
void Controller::updateUiSettings() {
int16_t setTemp = getTargetTemp();
const int16_t angleRange = 3160;
double percentage = ((double)setTemp) / ((double) MAX_TEMP);
int16_t angle = (percentage * ((double) angleRange)) - angleRange / 2;
lv_img_set_angle(ui_BrewScreen_tempTarget,angle);
lv_img_set_angle(ui_StatusScreen_tempTarget,angle);
lv_img_set_angle(ui_MenuScreen_tempTarget,angle);
lv_img_set_angle(ui_SteamScreen_tempTarget,angle);
lv_img_set_angle(ui_WaterScreen_tempTarget,angle);
lv_img_set_angle(ui_GrindScreen_tempTarget,angle);
double percentage = ((double)setTemp) / ((double)MAX_TEMP);
int16_t angle = (percentage * ((double)angleRange)) - angleRange / 2;
lv_img_set_angle(ui_BrewScreen_tempTarget, angle);
lv_img_set_angle(ui_StatusScreen_tempTarget, angle);
lv_img_set_angle(ui_MenuScreen_tempTarget, angle);
lv_img_set_angle(ui_SteamScreen_tempTarget, angle);
lv_img_set_angle(ui_WaterScreen_tempTarget, angle);
lv_img_set_angle(ui_GrindScreen_tempTarget, angle);

lv_label_set_text_fmt(ui_StatusScreen_targetTemp, "%d°C", settings.getTargetBrewTemp());
lv_label_set_text_fmt(ui_BrewScreen_targetTemp, "%d°C", settings.getTargetBrewTemp());
Expand Down Expand Up @@ -300,13 +296,15 @@ void Controller::updateStandby() {
char time[6];
strftime(time, 6, "%H:%M", &timeinfo);
lv_label_set_text(ui_StandbyScreen_time, time);
lv_obj_clear_flag(ui_StandbyScreen_time, LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(ui_StandbyScreen_time, LV_OBJ_FLAG_HIDDEN);
}
} else {
lv_obj_add_flag(ui_StandbyScreen_time, LV_OBJ_FLAG_HIDDEN);
}
clientController.isConnected() ? lv_obj_clear_flag(ui_StandbyScreen_bluetoothIcon, LV_OBJ_FLAG_HIDDEN) : lv_obj_add_flag(ui_StandbyScreen_bluetoothIcon, LV_OBJ_FLAG_HIDDEN);
!isApConnection && WiFi.status() == WL_CONNECTED ? lv_obj_clear_flag(ui_StandbyScreen_wifiIcon, LV_OBJ_FLAG_HIDDEN) : lv_obj_add_flag(ui_StandbyScreen_wifiIcon, LV_OBJ_FLAG_HIDDEN);
clientController.isConnected() ? lv_obj_clear_flag(ui_StandbyScreen_bluetoothIcon, LV_OBJ_FLAG_HIDDEN)
: lv_obj_add_flag(ui_StandbyScreen_bluetoothIcon, LV_OBJ_FLAG_HIDDEN);
!isApConnection &&WiFi.status() == WL_CONNECTED ? lv_obj_clear_flag(ui_StandbyScreen_wifiIcon, LV_OBJ_FLAG_HIDDEN)
: lv_obj_add_flag(ui_StandbyScreen_wifiIcon, LV_OBJ_FLAG_HIDDEN);
}

void Controller::activate() {
Expand Down
3 changes: 1 addition & 2 deletions src/display/core/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "Settings.h"
#include <WiFi.h>


class Controller {
public:
Controller();
Expand All @@ -30,7 +29,7 @@ class Controller {
bool isActive() const;
bool isGrindActive() const;
bool isUpdating() const;
Settings& getSettings() { return settings; }
Settings &getSettings() { return settings; }

// Event callback methods
void updateLastAction();
Expand Down
9 changes: 3 additions & 6 deletions src/display/core/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ struct EventDataEntry {

EventDataEntry() = default;

EventDataEntry(const String &k, int value)
: key(k), type(EventDataType::EVENT_TYPE_INT), intValue(value) {}
EventDataEntry(const String &k, int value) : key(k), type(EventDataType::EVENT_TYPE_INT), intValue(value) {}

EventDataEntry(const String &k, float value)
: key(k), type(EventDataType::EVENT_TYPE_FLOAT), floatValue(value) {}
EventDataEntry(const String &k, float value) : key(k), type(EventDataType::EVENT_TYPE_FLOAT), floatValue(value) {}

EventDataEntry(const String &k, const String &value)
: key(k), type(EventDataType::EVENT_TYPE_STRING), stringValue(value) {}
EventDataEntry(const String &k, const String &value) : key(k), type(EventDataType::EVENT_TYPE_STRING), stringValue(value) {}
};

using EventData = std::vector<EventDataEntry>;
Expand Down
16 changes: 8 additions & 8 deletions src/display/core/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include "Plugin.h"

#include <functional>
#include <vector>
#include <string>
#include <map>
#include <string>
#include <vector>

using EventCallback = std::function<void(Event &)>;

Expand All @@ -18,17 +18,17 @@ class PluginManager {
void setup(Controller *controller);
void loop();

void on(const String& eventId, const EventCallback &callback);
void on(const String &eventId, const EventCallback &callback);

Event trigger(const String& eventId);
Event trigger(const String& eventId, const String& key, const String &value);
Event trigger(const String& eventId, const String& key, int value);
Event trigger(const String& eventId, const String& key, float value);
Event trigger(const String &eventId);
Event trigger(const String &eventId, const String &key, const String &value);
Event trigger(const String &eventId, const String &key, int value);
Event trigger(const String &eventId, const String &key, float value);
void trigger(Event &event);

private:
bool initialized = false;
std::vector<Plugin*> plugins;
std::vector<Plugin *> plugins;
std::map<std::string, std::vector<EventCallback>> listeners = {};
};

Expand Down
5 changes: 3 additions & 2 deletions src/display/plugins/HomekitPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ void HomekitPlugin::clearAction() { actionRequired = false; }
void HomekitPlugin::setup(Controller *controller, PluginManager *pluginManager) {
this->controller = controller;

pluginManager->on("controller:wifi:connect", [this](Event & event) {
pluginManager->on("controller:wifi:connect", [this](Event &event) {
int apMode = event.getInt("AP");
if (apMode) return;
if (apMode)
return;
homeSpan.setHostNameSuffix("");
homeSpan.setPortNum(HOMESPAN_PORT);
homeSpan.begin(Category::Thermostats, DEVICE_NAME, this->controller->getSettings().getMdnsName().c_str());
Expand Down
3 changes: 1 addition & 2 deletions src/display/plugins/WebUIPlugin.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "WebUIPlugin.h"
#include "../core/Controller.h"
#include "../ui/ui.h"
#include <ArduinoJson.h>
#include <AsyncJson.h>
#include <SPIFFS.h>
#include "../ui/ui.h"

WebUIPlugin::WebUIPlugin() : server(80) {}

Expand Down Expand Up @@ -47,7 +47,6 @@ void WebUIPlugin::start() {
Serial.print("OTA server started");
}


void WebUIPlugin::handleOTA(AsyncWebServerRequest *request) {

if (request->method() == HTTP_POST) {
Expand Down
7 changes: 4 additions & 3 deletions src/display/plugins/WebUIPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#define ELEGANTOTA_USE_ASYNC_WEBSERVER 1

#include "../core/Plugin.h"
#include <ESPAsyncWebServer.h>
#include "GitHubOTA.h"
#include <ESPAsyncWebServer.h>

constexpr size_t UPDATE_CHECK_INTERVAL = 5 * 60 * 1000;

Expand All @@ -16,10 +16,11 @@ class WebUIPlugin : public Plugin {
WebUIPlugin();
void setup(Controller *controller, PluginManager *pluginManager) override;
void loop() override;

private:
void start();
String processTemplate(const String& var);
String processOTATemplate(const String& var);
String processTemplate(const String &var);
String processOTATemplate(const String &var);

void handleOTA(AsyncWebServerRequest *request);
void handleSettings(AsyncWebServerRequest *request);
Expand Down
3 changes: 2 additions & 1 deletion src/display/plugins/mDNSPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ void mDNSPlugin::setup(Controller *controller, PluginManager *pluginManager) {
}
void mDNSPlugin::start(Event const &event) const {
const int apMode = event.getInt("AP");
if (apMode) return;
if (apMode)
return;
if (!MDNS.begin(controller->getSettings().getMdnsName().c_str())) {
Serial.println("Error setting up MDNS responder!");
}
Expand Down
2 changes: 1 addition & 1 deletion src/display/plugins/mDNSPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class mDNSPlugin : public Plugin {
void loop() override {};

private:
void start(Event const & event) const;
void start(Event const &event) const;

Controller *controller = nullptr;
};
Expand Down

0 comments on commit 9a1d1cf

Please sign in to comment.