Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Apply style to all files #327

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions components/display_drivers/include/display_drivers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ struct Config {
command bits. */
bool reset_value{false}; /**< The value to set the reset pin to when resetting the display (low to
reset default). */
bool invert_colors{false}; /**< Whether to invert the colors on the display. */
bool invert_colors{false}; /**< Whether to invert the colors on the display. */
bool swap_color_order{false}; /**< Whether to swap the color order (RGB/BGR) on the display. */
int offset_x{0}; /**< X Gap / offset, in pixels. */
int offset_y{0}; /**< Y Gap / offset, in pixels. */
bool swap_xy{false}; /**< Swap row/column order. */
bool mirror_x{false}; /**< Mirror the display horizontally. */
bool mirror_y{false}; /**< Mirror the display vertically. */
bool mirror_portrait{false}; /**< Mirror the display in portrait mode. */
int offset_x{0}; /**< X Gap / offset, in pixels. */
int offset_y{0}; /**< Y Gap / offset, in pixels. */
bool swap_xy{false}; /**< Swap row/column order. */
bool mirror_x{false}; /**< Mirror the display horizontally. */
bool mirror_y{false}; /**< Mirror the display vertically. */
bool mirror_portrait{false}; /**< Mirror the display in portrait mode. */
};

/**
Expand Down
27 changes: 15 additions & 12 deletions components/esp-box/example/main/esp_box_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ extern "C" void app_main(void) {
// set the pixel buffer to be 50 lines high
static constexpr size_t pixel_buffer_size = box.lcd_width() * 50;
espp::Task::BaseConfig display_task_config = {
.name = "Display",
.stack_size_bytes = 6 * 1024,
.priority = 10,
.core_id = 0,
.name = "Display",
.stack_size_bytes = 6 * 1024,
.priority = 10,
.core_id = 0,
};
// initialize the LVGL display for the esp-box
if (!box.initialize_display(pixel_buffer_size, display_task_config)) {
Expand Down Expand Up @@ -100,14 +100,17 @@ extern "C" void app_main(void) {
lv_label_set_text(label_btn, LV_SYMBOL_REFRESH);
// center the text in the button
lv_obj_align(label_btn, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event_cb(btn, [](auto event) {
std::lock_guard<std::recursive_mutex> lock(lvgl_mutex);
clear_circles();
static auto rotation = LV_DISPLAY_ROTATION_0;
rotation = static_cast<lv_display_rotation_t>((static_cast<int>(rotation) + 1) % 4);
lv_display_t *disp = _lv_refr_get_disp_refreshing();
lv_disp_set_rotation(disp, rotation);
}, LV_EVENT_PRESSED, nullptr);
lv_obj_add_event_cb(
btn,
[](auto event) {
std::lock_guard<std::recursive_mutex> lock(lvgl_mutex);
clear_circles();
static auto rotation = LV_DISPLAY_ROTATION_0;
rotation = static_cast<lv_display_rotation_t>((static_cast<int>(rotation) + 1) % 4);
lv_display_t *disp = _lv_refr_get_disp_refreshing();
lv_disp_set_rotation(disp, rotation);
},
LV_EVENT_PRESSED, nullptr);

// disable scrolling on the screen (so that it doesn't behave weirdly when
// rotated and drawing with your finger)
Expand Down
3 changes: 2 additions & 1 deletion components/esp-box/src/esp-box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ bool EspBox::initialize_lcd() {
return true;
}

bool EspBox::initialize_display(size_t pixel_buffer_size, const espp::Task::BaseConfig &task_config, int update_period_ms) {
bool EspBox::initialize_display(size_t pixel_buffer_size, const espp::Task::BaseConfig &task_config,
int update_period_ms) {
if (!lcd_handle_) {
logger_.error(
"LCD not initialized, you must call initialize_lcd() before initialize_display()!");
Expand Down
13 changes: 7 additions & 6 deletions components/esp32-timer-cam/include/esp32-timer-cam.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class EspTimerCam : public BaseComponent {
/// @brief Initialize the LED
/// @param breathing_period The period of the LED breathing effect
/// @return True if the LED was successfully initialized, false otherwise
bool initialize_led(float breathing_period=3.5f);
bool initialize_led(float breathing_period = 3.5f);

/// @brief Start the LED breathing effect
void start_led_breathing();
Expand Down Expand Up @@ -207,7 +207,8 @@ class EspTimerCam : public BaseComponent {
static constexpr gpio_num_t internal_i2c_scl = GPIO_NUM_14;

// Battery
static constexpr float BATTERY_VOLTAGE_SCALE = 1.0f / 661.0f; // measured mV across divider to battery volts
static constexpr float BATTERY_VOLTAGE_SCALE =
1.0f / 661.0f; // measured mV across divider to battery volts
static constexpr gpio_num_t battery_hold_pin = GPIO_NUM_33; // NOTE: unused

// Camera
Expand Down Expand Up @@ -258,14 +259,14 @@ class EspTimerCam : public BaseComponent {

// Battery ADC
espp::AdcConfig battery_channel_{.unit = ADC_UNIT_1,
.channel = ADC_CHANNEL_2, // GPIO 38
.attenuation = ADC_ATTEN_DB_12};
.channel = ADC_CHANNEL_2, // GPIO 38
.attenuation = ADC_ATTEN_DB_12};

// NOTE: for some reason, I cannot use Continuous ADC in combination with
// esp32-camera...
espp::OneshotAdc adc_{{.unit = battery_channel_.unit,
.channels = {battery_channel_},
.log_level = espp::Logger::Verbosity::WARN}};
.channels = {battery_channel_},
.log_level = espp::Logger::Verbosity::WARN}};

}; // class EspTimerCam
} // namespace espp
47 changes: 20 additions & 27 deletions components/esp32-timer-cam/src/esp32-timer-cam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

using namespace espp;

EspTimerCam::EspTimerCam() : BaseComponent("EspTimerCam") {
}
EspTimerCam::EspTimerCam()
: BaseComponent("EspTimerCam") {}

////////////////////////
// LED //
Expand All @@ -20,7 +20,10 @@ bool EspTimerCam::initialize_led(float breathing_period) {
.channels = led_channels_,
.duty_resolution = LEDC_TIMER_10_BIT,
});
led_task_ = espp::Task::make_unique({.name = "breathe", .callback = std::bind(&EspTimerCam::led_task_callback, this, std::placeholders::_1, std::placeholders::_2)});
led_task_ = espp::Task::make_unique(
{.name = "breathe",
.callback = std::bind(&EspTimerCam::led_task_callback, this, std::placeholders::_1,
std::placeholders::_2)});
set_led_breathing_period(breathing_period);
return true;
}
Expand All @@ -30,9 +33,7 @@ void EspTimerCam::start_led_breathing() {
led_task_->start();
}

void EspTimerCam::stop_led_breathing() {
led_task_->stop();
}
void EspTimerCam::stop_led_breathing() { led_task_->stop(); }

bool EspTimerCam::set_led_brightness(float brightness) {
if (led_ == nullptr) {
Expand Down Expand Up @@ -70,23 +71,17 @@ bool EspTimerCam::set_led_breathing_period(float breathing_period) {
return true;
}

float EspTimerCam::get_led_breathing_period() {
return breathing_period_;
}
float EspTimerCam::get_led_breathing_period() { return breathing_period_; }

std::shared_ptr<espp::Led> EspTimerCam::led() {
return led_;
}
std::shared_ptr<espp::Led> EspTimerCam::led() { return led_; }

espp::Gaussian &EspTimerCam::gaussian() {
return gaussian_;
}
espp::Gaussian &EspTimerCam::gaussian() { return gaussian_; }

float EspTimerCam::led_breathe() {
auto now = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration<float>(now - breathing_start_).count();
float t = std::fmod(elapsed, breathing_period_) / breathing_period_;
return gaussian_(t);
auto now = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration<float>(now - breathing_start_).count();
float t = std::fmod(elapsed, breathing_period_) / breathing_period_;
return gaussian_(t);
}

bool EspTimerCam::led_task_callback(std::mutex &m, std::condition_variable &cv) {
Expand Down Expand Up @@ -121,15 +116,13 @@ bool EspTimerCam::initialize_rtc() {
return false;
}
rtc_ = std::make_shared<EspTimerCam::Rtc>(EspTimerCam::Rtc::Config{
.write = std::bind(&espp::I2c::write, &internal_i2c_, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3),
.write_then_read =
std::bind(&espp::I2c::write_read, &internal_i2c_, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, std::placeholders::_4, std::placeholders::_5),
.write = std::bind(&espp::I2c::write, &internal_i2c_, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3),
.write_then_read = std::bind(&espp::I2c::write_read, &internal_i2c_, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3,
std::placeholders::_4, std::placeholders::_5),
.log_level = espp::Logger::Verbosity::WARN});
return true;
}

std::shared_ptr<EspTimerCam::Rtc> EspTimerCam::rtc() {
return rtc_;
}
std::shared_ptr<EspTimerCam::Rtc> EspTimerCam::rtc() { return rtc_; }
3 changes: 2 additions & 1 deletion components/interrupt/include/interrupt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ class Interrupt : public BaseComponent {
// for printing the interrupt event using libfmt
template <> struct fmt::formatter<espp::Interrupt::Event> {
constexpr auto parse(format_parse_context &ctx) const { return ctx.begin(); }
template <typename FormatContext> auto format(const espp::Interrupt::Event &t, FormatContext &ctx) const {
template <typename FormatContext>
auto format(const espp::Interrupt::Event &t, FormatContext &ctx) const {
return fmt::format_to(ctx.out(), "Event{{gpio_num={}, active={}}}", t.gpio_num, t.active);
}
};
Expand Down
1 change: 0 additions & 1 deletion components/logger/include/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class Logger {
#endif // CONFIG_ESPP_LOGGER_ENABLE_CURSOR_COMMANDS
#endif // ESPP_LOGGER_CURSOR_COMMANDS_ENABLED


public:
/**
* Verbosity levels for the logger, in order of increasing priority.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,17 @@ extern "C" void app_main(void) {
lv_label_set_text(label_btn, LV_SYMBOL_REFRESH);
// center the text in the button
lv_obj_align(label_btn, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event_cb(btn, [](auto event) {
std::lock_guard<std::recursive_mutex> lock(lvgl_mutex);
clear_circles();
static auto rotation = LV_DISPLAY_ROTATION_0;
rotation = static_cast<lv_display_rotation_t>((static_cast<int>(rotation) + 1) % 4);
lv_display_t *disp = _lv_refr_get_disp_refreshing();
lv_disp_set_rotation(disp, rotation);
}, LV_EVENT_PRESSED, nullptr);
lv_obj_add_event_cb(
btn,
[](auto event) {
std::lock_guard<std::recursive_mutex> lock(lvgl_mutex);
clear_circles();
static auto rotation = LV_DISPLAY_ROTATION_0;
rotation = static_cast<lv_display_rotation_t>((static_cast<int>(rotation) + 1) % 4);
lv_display_t *disp = _lv_refr_get_disp_refreshing();
lv_disp_set_rotation(disp, rotation);
},
LV_EVENT_PRESSED, nullptr);

// disable scrolling on the screen (so that it doesn't behave weirdly when
// rotated and drawing with your finger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ bool MatouchRotaryDisplay::initialize_lcd() {
return true;
}

bool MatouchRotaryDisplay::initialize_display(size_t pixel_buffer_size, const espp::Task::BaseConfig &task_config, int update_period_ms) {
bool MatouchRotaryDisplay::initialize_display(size_t pixel_buffer_size,
const espp::Task::BaseConfig &task_config,
int update_period_ms) {
if (!lcd_handle_) {
logger_.error(
"LCD not initialized, you must call initialize_lcd() before initialize_display()!");
Expand Down
39 changes: 20 additions & 19 deletions components/t-dongle-s3/example/main/t_dongle_s3_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,26 @@ extern "C" void app_main(void) {
// initialize the button, which we'll use to cycle the rotation of the display
espp::Button button(espp::Button::Config{
.name = "Boot Button",
.interrupt_config = espp::Interrupt::PinConfig{
.gpio_num = GPIO_NUM_0,
.callback = [](const auto &event) {
if (event.active) {
// lock the display mutex
std::lock_guard<std::mutex> lock(lvgl_mutex);
static auto rotation = LV_DISPLAY_ROTATION_0;
rotation = static_cast<lv_display_rotation_t>((static_cast<int>(rotation) + 1) % 4);
fmt::print("Setting rotation to {}\n", (int)rotation);
lv_display_t *disp = _lv_refr_get_disp_refreshing();
lv_disp_set_rotation(disp, rotation);
}
},
.active_level = espp::Interrupt::ActiveLevel::LOW,
.interrupt_type = espp::Interrupt::Type::ANY_EDGE,
.pullup_enabled = false,
.pulldown_enabled = false
},
});
.interrupt_config =
espp::Interrupt::PinConfig{.gpio_num = GPIO_NUM_0,
.callback =
[](const auto &event) {
if (event.active) {
// lock the display mutex
std::lock_guard<std::mutex> lock(lvgl_mutex);
static auto rotation = LV_DISPLAY_ROTATION_0;
rotation = static_cast<lv_display_rotation_t>(
(static_cast<int>(rotation) + 1) % 4);
fmt::print("Setting rotation to {}\n", (int)rotation);
lv_display_t *disp = _lv_refr_get_disp_refreshing();
lv_disp_set_rotation(disp, rotation);
}
},
.active_level = espp::Interrupt::ActiveLevel::LOW,
.interrupt_type = espp::Interrupt::Type::ANY_EDGE,
.pullup_enabled = false,
.pulldown_enabled = false},
});

// set the LED to be red
espp::Hsv hsv(150.0f, 1.0f, 1.0f);
Expand Down
7 changes: 6 additions & 1 deletion components/t-dongle-s3/include/t-dongle-s3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ class TDongleS3 : public BaseComponent {
/// \param update_period_ms The update period of the display task
/// \return true if the display was successfully initialized, false otherwise
/// \note This will also allocate two full frame buffers in the SPIRAM
bool initialize_display(size_t pixel_buffer_size, const espp::Task::BaseConfig &task_config = {.name="Display", .stack_size_bytes=4096, .priority=10, .core_id=0}, int update_period_ms = 16);
bool initialize_display(size_t pixel_buffer_size,
const espp::Task::BaseConfig &task_config = {.name = "Display",
.stack_size_bytes = 4096,
.priority = 10,
.core_id = 0},
int update_period_ms = 16);

/// Get the width of the LCD in pixels
/// \return The width of the LCD in pixels
Expand Down
4 changes: 3 additions & 1 deletion components/t-dongle-s3/src/t-dongle-s3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ bool TDongleS3::initialize_lcd() {
return true;
}

bool TDongleS3::initialize_display(size_t pixel_buffer_size, const espp::Task::BaseConfig &task_config, int update_period_ms) {
bool TDongleS3::initialize_display(size_t pixel_buffer_size,
const espp::Task::BaseConfig &task_config,
int update_period_ms) {
if (!lcd_handle_) {
logger_.error(
"LCD not initialized, you must call initialize_lcd() before initialize_display()!");
Expand Down
39 changes: 20 additions & 19 deletions components/wrover-kit/example/main/wrover_kit_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,26 @@ extern "C" void app_main(void) {
// initialize the button, which we'll use to cycle the rotation of the display
espp::Button button(espp::Button::Config{
.name = "Boot Button",
.interrupt_config = espp::Interrupt::PinConfig{
.gpio_num = GPIO_NUM_0,
.callback = [](const auto &event) {
if (event.active) {
// lock the display mutex
std::lock_guard<std::mutex> lock(lvgl_mutex);
static auto rotation = LV_DISPLAY_ROTATION_0;
rotation = static_cast<lv_display_rotation_t>((static_cast<int>(rotation) + 1) % 4);
fmt::print("Setting rotation to {}\n", (int)rotation);
lv_display_t *disp = _lv_refr_get_disp_refreshing();
lv_disp_set_rotation(disp, rotation);
}
},
.active_level = espp::Interrupt::ActiveLevel::LOW,
.interrupt_type = espp::Interrupt::Type::ANY_EDGE,
.pullup_enabled = false,
.pulldown_enabled = false
},
});
.interrupt_config =
espp::Interrupt::PinConfig{.gpio_num = GPIO_NUM_0,
.callback =
[](const auto &event) {
if (event.active) {
// lock the display mutex
std::lock_guard<std::mutex> lock(lvgl_mutex);
static auto rotation = LV_DISPLAY_ROTATION_0;
rotation = static_cast<lv_display_rotation_t>(
(static_cast<int>(rotation) + 1) % 4);
fmt::print("Setting rotation to {}\n", (int)rotation);
lv_display_t *disp = _lv_refr_get_disp_refreshing();
lv_disp_set_rotation(disp, rotation);
}
},
.active_level = espp::Interrupt::ActiveLevel::LOW,
.interrupt_type = espp::Interrupt::Type::ANY_EDGE,
.pullup_enabled = false,
.pulldown_enabled = false},
});

// set the background color to black
lv_obj_t *bg = lv_obj_create(lv_screen_active());
Expand Down
7 changes: 6 additions & 1 deletion components/wrover-kit/include/wrover-kit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ class WroverKit : public BaseComponent {
/// \param update_period_ms The update period of the display task
/// \return true if the display was successfully initialized, false otherwise
/// \note This will also allocate two full frame buffers in the SPIRAM
bool initialize_display(size_t pixel_buffer_size, const espp::Task::BaseConfig &task_config = {.name="Display", .stack_size_bytes=4096, .priority=10, .core_id=0}, int update_period_ms = 16);
bool initialize_display(size_t pixel_buffer_size,
const espp::Task::BaseConfig &task_config = {.name = "Display",
.stack_size_bytes = 4096,
.priority = 10,
.core_id = 0},
int update_period_ms = 16);

/// Get the width of the LCD in pixels
/// \return The width of the LCD in pixels
Expand Down
4 changes: 3 additions & 1 deletion components/wrover-kit/src/wrover-kit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ bool WroverKit::initialize_lcd() {
return true;
}

bool WroverKit::initialize_display(size_t pixel_buffer_size, const espp::Task::BaseConfig &task_config, int update_period_ms) {
bool WroverKit::initialize_display(size_t pixel_buffer_size,
const espp::Task::BaseConfig &task_config,
int update_period_ms) {
if (!lcd_handle_) {
logger_.error(
"LCD not initialized, you must call initialize_lcd() before initialize_display()!");
Expand Down
Loading