feat: add main view
This commit is contained in:
parent
3b1ab0ee5e
commit
84832271ce
@ -1,7 +1,6 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include <input/encoder.hpp>
|
#include <input/encoder.hpp>
|
||||||
#include <ui/display.hpp>
|
|
||||||
#include <audio/tone_generator.hpp>
|
#include <audio/tone_generator.hpp>
|
||||||
|
|
||||||
#ifndef ANALAOG_OUTPUT_PIN
|
#ifndef ANALAOG_OUTPUT_PIN
|
||||||
@ -53,8 +52,6 @@ namespace ToneGenerator
|
|||||||
setFrequency(frequency);
|
setFrequency(frequency);
|
||||||
Serial.print("Frequency: ");
|
Serial.print("Frequency: ");
|
||||||
Serial.println(frequency);
|
Serial.println(frequency);
|
||||||
|
|
||||||
Display::setLabelText("Frequency: " + String(frequency) + "Hz");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setToneOn(bool on)
|
void setToneOn(bool on)
|
||||||
|
|||||||
@ -28,7 +28,6 @@ void setup()
|
|||||||
ToneGenerator::init();
|
ToneGenerator::init();
|
||||||
|
|
||||||
Serial.println("setup complete");
|
Serial.println("setup complete");
|
||||||
Display::setLabelText("Boot complete.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include <input/encoder.hpp>
|
#include <input/encoder.hpp>
|
||||||
|
#include <ui/views/main_view.hpp>
|
||||||
|
|
||||||
#ifndef SCREEN_WIDTH
|
#ifndef SCREEN_WIDTH
|
||||||
#define SCREEN_WIDTH 320
|
#define SCREEN_WIDTH 320
|
||||||
@ -16,16 +17,17 @@
|
|||||||
#define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8))
|
#define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8))
|
||||||
namespace Display
|
namespace Display
|
||||||
{
|
{
|
||||||
|
const uint8_t MAIN_VIEW = 1;
|
||||||
|
|
||||||
uint32_t draw_buf[DRAW_BUF_SIZE / 4];
|
uint32_t draw_buf[DRAW_BUF_SIZE / 4];
|
||||||
|
|
||||||
uint32_t getTime();
|
uint32_t getTime();
|
||||||
void handleLvglLogs(lv_log_level_t level, const char *buf);
|
void handleLvglLogs(lv_log_level_t level, const char *buf);
|
||||||
void handleUpdateValues(lv_timer_t *timer);
|
void handleUpdateValues(lv_timer_t *timer);
|
||||||
void handleEnterButton();
|
void setCurrentView(uint8_t view);
|
||||||
|
|
||||||
String label_text;
|
|
||||||
lv_obj_t *label;
|
|
||||||
lv_timer_t *update_values_timer;
|
lv_timer_t *update_values_timer;
|
||||||
|
uint8_t current_view = 0;
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
@ -40,10 +42,7 @@ namespace Display
|
|||||||
display = lv_tft_espi_create(SCREEN_HEIGHT, SCREEN_WIDTH, draw_buf, sizeof(draw_buf));
|
display = lv_tft_espi_create(SCREEN_HEIGHT, SCREEN_WIDTH, draw_buf, sizeof(draw_buf));
|
||||||
lv_display_set_rotation(display, LV_DISPLAY_ROTATION_90);
|
lv_display_set_rotation(display, LV_DISPLAY_ROTATION_90);
|
||||||
|
|
||||||
label = lv_label_create(lv_screen_active());
|
setCurrentView(MAIN_VIEW);
|
||||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
|
|
||||||
|
|
||||||
Encoder::onButtonRelease(handleEnterButton);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void update()
|
void update()
|
||||||
@ -51,11 +50,6 @@ namespace Display
|
|||||||
lv_timer_handler();
|
lv_timer_handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLabelText(String text)
|
|
||||||
{
|
|
||||||
label_text = text;
|
|
||||||
}
|
|
||||||
|
|
||||||
void handleLvglLogs(lv_log_level_t level, const char *buf)
|
void handleLvglLogs(lv_log_level_t level, const char *buf)
|
||||||
{
|
{
|
||||||
Serial.printf("LVGL: %s\r\n", buf);
|
Serial.printf("LVGL: %s\r\n", buf);
|
||||||
@ -66,16 +60,24 @@ namespace Display
|
|||||||
return esp_timer_get_time() / 1000;
|
return esp_timer_get_time() / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleUpdateValues(lv_timer_t *timer)
|
void setCurrentView(uint8_t view) {
|
||||||
{
|
current_view = view;
|
||||||
if (label != NULL && lv_label_get_text(label) != label_text.c_str())
|
lv_obj_t *parent = lv_screen_active();
|
||||||
{
|
lv_obj_clean(parent);
|
||||||
lv_label_set_text(label, label_text.c_str());
|
switch(view) {
|
||||||
|
case MAIN_VIEW:
|
||||||
|
MainView::render(parent);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleEnterButton()
|
void handleUpdateValues(lv_timer_t *timer)
|
||||||
{
|
{
|
||||||
setLabelText("Button pressed.");
|
switch (current_view)
|
||||||
|
{
|
||||||
|
case MAIN_VIEW:
|
||||||
|
MainView::update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
namespace Display {
|
namespace Display {
|
||||||
void init();
|
void init();
|
||||||
void update();
|
void update();
|
||||||
void setLabelText(String text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // DRUMZ_UI_DISPLAY_HPP
|
#endif // DRUMZ_UI_DISPLAY_HPP
|
||||||
41
src/ui/views/main_view.cpp
Normal file
41
src/ui/views/main_view.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <lvgl.h>
|
||||||
|
|
||||||
|
#include <input/encoder.hpp>
|
||||||
|
#include <audio/tone_generator.hpp>
|
||||||
|
|
||||||
|
namespace MainView
|
||||||
|
{
|
||||||
|
void handleEnterButton();
|
||||||
|
|
||||||
|
lv_obj_t *label;
|
||||||
|
String label_text;
|
||||||
|
int frequency = ToneGenerator::getFrequency();
|
||||||
|
|
||||||
|
void render(lv_obj_t *parent)
|
||||||
|
{
|
||||||
|
label = lv_label_create(lv_screen_active());
|
||||||
|
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
|
||||||
|
label_text = "Main view initialized.";
|
||||||
|
|
||||||
|
Encoder::onButtonPress(handleEnterButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
void update()
|
||||||
|
{
|
||||||
|
if (frequency != ToneGenerator::getFrequency())
|
||||||
|
{
|
||||||
|
frequency = ToneGenerator::getFrequency();
|
||||||
|
label_text = "Frequency: " + String(frequency) + "Hz";
|
||||||
|
}
|
||||||
|
if (label != NULL && lv_label_get_text(label) != label_text.c_str())
|
||||||
|
{
|
||||||
|
lv_label_set_text(label, label_text.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleEnterButton()
|
||||||
|
{
|
||||||
|
label_text = "Button pressed.";
|
||||||
|
}
|
||||||
|
}
|
||||||
12
src/ui/views/main_view.hpp
Normal file
12
src/ui/views/main_view.hpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include <lvgl.h>
|
||||||
|
|
||||||
|
#ifndef DRUMZ_UI_VIEWS_MAIN_VIEW_HPP
|
||||||
|
#define DRUMZ_UI_VIEWS_MAIN_VIEW_HPP
|
||||||
|
|
||||||
|
namespace MainView
|
||||||
|
{
|
||||||
|
void render(lv_obj_t *parent);
|
||||||
|
void update();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // DRUMZ_UI_VIEWS_MAIN_VIEW_HPP
|
||||||
Loading…
Reference in New Issue
Block a user