Portrait Rotation

This commit is contained in:
2025-07-15 23:04:34 +02:00
parent b93597ee26
commit 66ee0040ba
7 changed files with 43 additions and 20 deletions

View File

@@ -120,6 +120,7 @@ public:
{
if (enabled && touch_x > x && touch_x < x + width && touch_y > y && touch_y < y + height)
{
Serial.printf("pressed as %d, %d: %s\n", touch_x, touch_y, this->label);
on_pressed(keypad, value);
}
}

View File

@@ -10,10 +10,10 @@
class Display : public LGFX
{
public:
void init()
void init(uint_fast8_t rotation)
{
LGFX::init();
setRotation(1);
setRotation(rotation);
setEpdMode(epd_mode_t::epd_quality);
fillScreen(TFT_WHITE);

View File

@@ -7,9 +7,9 @@
class Input
{
public:
Input(String value) : value{value}, old_value{value} {}
Input(String value, float x, float y) : value{value}, x{x}, y{y} {}
Input(String value, float x, float y, int width, int height) : value{value}, x{x}, y{y}, width{width}, height{height} {}
Input(LGFX *canvas, String value) : canvas{canvas}, value{value}, old_value{value} {}
Input(LGFX *canvas, String value, float x, float y) : canvas{canvas}, value{value}, x{x}, y{y} {}
Input(LGFX *canvas, String value, float x, float y, int width, int height) : canvas{canvas}, value{value}, x{x}, y{y}, width{width}, height{height} {}
~Input() = default;
@@ -72,7 +72,7 @@ public:
y = value;
}
void draw(LGFX *canvas)
void draw()
{
if (!dirty)
{

View File

@@ -13,7 +13,7 @@ class Keypad : public EventEmitter<int>
public:
Keypad(LGFX *canvas) : EventEmitter<int>(), canvas{canvas}
{
int BUTTON_SIZE = canvas->height() / BUTTON_ROWS;
int BUTTON_SIZE = canvas->width() / BUTTON_COLS;
width = BUTTON_SIZE * BUTTON_COLS;
for (int i = 0; i < BUTTON_COUNT; i++)
@@ -38,7 +38,7 @@ public:
enabled = false;
}
buttons.push_back(new KeypadButton(lbl, i, enabled, x, y, BUTTON_SIZE, BUTTON_SIZE, Keypad::on_button_pressed));
buttons.push_back(new KeypadButton(lbl, i, enabled, x, y + 120, BUTTON_SIZE, BUTTON_SIZE, Keypad::on_button_pressed));
}
}
@@ -51,6 +51,7 @@ public:
void update(tp_finger_t touch)
{
Serial.printf("touching: %d, %d\n", touch.x, touch.y);
for (int i = 0; i < BUTTON_COUNT; i++)
{
buttons[i]->update(this, touch.x, touch.y);

View File

@@ -53,7 +53,7 @@ void mqtt_callback(char *topic, byte *payload, unsigned int length)
state[0] = toupper(state[0]);
Serial.println(state);
status->set(state);
status->draw(&display);
status->draw();
keypad_state(!is_disarmed);
}
@@ -151,7 +151,7 @@ void p(int v)
if (input->length() >= 6)
{
// verify
input->draw(&display); // force one more redraw for the last character
input->draw(); // force one more redraw for the last character
submit(input->get_value());
input->clear();
}
@@ -160,12 +160,13 @@ void p(int v)
void setup()
{
M5.begin();
display.init();
touch = new Touch(M5.TP);
status = new Status("Loading");
Serial.println("Device Startup");
display.init(0);
touch = new Touch(M5.TP, 0);
status = new Status(&display, "Loading");
keypad = new Keypad(&display);
keypad->addListener("pressed", p);
input = new Input("", keypad->get_width(), 0, display.width() - keypad->get_width(), 115);
input = new Input(&display, "", 0, 5, display.width(), 115);
auto settings = new Settings();
@@ -187,13 +188,22 @@ void setup()
void loop()
{
M5.update();
mqtt->loop();
auto tap = touch->tap();
if (tap.has_value())
keypad->update(tap.value());
input->draw();
keypad->draw();
input->draw(&display);
status->draw(&display);
status->draw();
if (M5.BtnP.isPressed())
{
status->set("Restarting");
status->draw();
delay(10);
abort();
}
}

View File

@@ -7,7 +7,7 @@
class Status
{
public:
Status(String value) : value{value}
Status(LGFX *canvas, String value) : canvas{canvas}, value{value}
{
old_length = value.length();
}
@@ -21,7 +21,7 @@ public:
dirty = true;
}
void draw(LGFX *canvas)
void draw()
{
if (!dirty)
{

View File

@@ -7,7 +7,10 @@
class Touch
{
public:
Touch(GT911 TP) : TP{TP} {}
Touch(GT911 TP, uint_fast8_t rotation) : TP{TP}
{
TP.SetRotation(rotation);
}
std::optional<tp_finger_t> tap()
{
@@ -30,7 +33,15 @@ public:
}
touching = true;
return TP.readFinger(0);
auto f = TP.readFinger(0);
auto x = 540 - f.y;
auto y = f.x;
f.x = x;
f.y = y;
return f;
}
private: