Skip to content

Commit

Permalink
Switch to new codestyles
Browse files Browse the repository at this point in the history
  • Loading branch information
DrA1ex committed Sep 26, 2024
1 parent 3b47dc1 commit b6c7e7d
Show file tree
Hide file tree
Showing 14 changed files with 217 additions and 216 deletions.
36 changes: 18 additions & 18 deletions src/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ void Application::begin() {

auto &sys_config = _bootstrap->config().sys_config;
_bootstrap->begin({
.mdns_name = sys_config.mdns_name,
.wifi_mode = sys_config.wifi_mode,
.wifi_ssid = sys_config.wifi_ssid,
.wifi_password = sys_config.wifi_password,
.wifi_connection_timeout = sys_config.wifi_max_connection_attempt_interval,
.mqtt_enabled = sys_config.mqtt,
.mqtt_host = sys_config.mqtt_host,
.mqtt_port = sys_config.mqtt_port,
.mqtt_user = sys_config.mqtt_user,
.mqtt_password = sys_config.mqtt_password,
});
.mdns_name = sys_config.mdns_name,
.wifi_mode = sys_config.wifi_mode,
.wifi_ssid = sys_config.wifi_ssid,
.wifi_password = sys_config.wifi_password,
.wifi_connection_timeout = sys_config.wifi_max_connection_attempt_interval,
.mqtt_enabled = sys_config.mqtt,
.mqtt_host = sys_config.mqtt_host,
.mqtt_port = sys_config.mqtt_port,
.mqtt_user = sys_config.mqtt_user,
.mqtt_password = sys_config.mqtt_password,
});

if (sys_config.rgb_mode) {
_led = std::make_unique<LedController>(
sys_config.led_r_pin, sys_config.led_g_pin, sys_config.led_b_pin);
sys_config.led_r_pin, sys_config.led_g_pin, sys_config.led_b_pin);
} else {
_led = std::make_unique<LedController>(sys_config.led_r_pin);
}
Expand Down Expand Up @@ -158,20 +158,20 @@ void Application::_app_loop() {
case AppState::INITIALIZATION: {
if (config().power) {
const auto factor = map16(
(millis() - _state_change_time) % sys_config().wifi_connect_flash_timeout,
sys_config().wifi_connect_flash_timeout,
PWM_MAX_VALUE
(millis() - _state_change_time) % sys_config().wifi_connect_flash_timeout,
sys_config().wifi_connect_flash_timeout,
PWM_MAX_VALUE
);

uint16_t brightness = _brightness() * cubic_wave16(factor, PWM_MAX_VALUE) / PWM_MAX_VALUE;
_led->set_brightness(brightness);
}
}
break;
break;

case AppState::TURNING_ON: {
uint16_t factor = std::min<unsigned long>(PWM_MAX_VALUE,
(millis() - _state_change_time) * PWM_MAX_VALUE / sys_config().power_change_timeout);
(millis() - _state_change_time) * PWM_MAX_VALUE / sys_config().power_change_timeout);
uint16_t brightness = (uint16_t) _brightness() * ease_cubic16(factor, PWM_MAX_VALUE) / PWM_MAX_VALUE;
_led->set_brightness(brightness);

Expand All @@ -181,7 +181,7 @@ void Application::_app_loop() {

case AppState::TURNING_OFF: {
uint16_t factor = PWM_MAX_VALUE - std::min<unsigned long>(PWM_MAX_VALUE,
(millis() - _state_change_time) * PWM_MAX_VALUE / sys_config().power_change_timeout);
(millis() - _state_change_time) * PWM_MAX_VALUE / sys_config().power_change_timeout);
uint16_t brightness = (uint16_t) _brightness() * ease_cubic16(factor, PWM_MAX_VALUE) / PWM_MAX_VALUE;
_led->set_brightness(brightness);

Expand Down
14 changes: 7 additions & 7 deletions src/app/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#include "constants.h"

MAKE_ENUM_AUTO(AppState, uint8_t,
UNINITIALIZED,
INITIALIZATION,
STAND_BY,
TURNING_ON,
TURNING_OFF
UNINITIALIZED,
INITIALIZATION,
STAND_BY,
TURNING_ON,
TURNING_OFF
);

typedef char ConfigString[CONFIG_STRING_SIZE];
Expand Down Expand Up @@ -55,15 +55,15 @@ struct __attribute ((packed)) NightModeConfig {
bool enabled = false;
uint16_t brightness = 10;
uint32_t start_time = 0;
uint32_t end_time = 10 * 60 * 60; // 22:00
uint32_t end_time = 10 * 60 * 60; // 22:00
uint16_t switch_interval = 15 * 60; // 15 minutes
};

struct __attribute ((packed)) Config {
bool power = true;
uint16_t brightness = 2048;

uint32_t color = ~0u; // All colors
uint32_t color = ~0u; // All colors
uint32_t calibration = ~0u; // No calibration

NightModeConfig night_mode{};
Expand Down
Loading

0 comments on commit b6c7e7d

Please sign in to comment.