summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--apps/tests/main.cpp24
-rw-r--r--apps/tests/main.hpp1
-rw-r--r--hal/ui/widget/base_widget.hpp25
-rw-r--r--hal/ui/widget/list_widget.cpp9
-rw-r--r--hal/ui/widget/list_widget.hpp9
-rw-r--r--init.hpp8
7 files changed, 73 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7825526..0f77300 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -44,6 +44,7 @@ add_executable(pico-watch
init.cpp
buttons.cpp
hal/api.cpp
+ hal/ui/widget/list_widget.cpp
apps/home_menu/main.cpp
apps/main_clock/main.cpp
apps/settings/main.cpp
diff --git a/apps/tests/main.cpp b/apps/tests/main.cpp
index e11f1dc..34e26ed 100644
--- a/apps/tests/main.cpp
+++ b/apps/tests/main.cpp
@@ -2,13 +2,37 @@
#include "pico/stdlib.h"
#include "main.hpp"
+#include "../../hal/ui/widget/list_widget.hpp"
+#define NUMBER_OF_SCREENS 2
BaseApp::AppReturnValues app_tests::render(Api *app_api) {
app_api->gui_header_text("App for testing APIs.");
+
+ switch (m_current_screen) {
+ case 0:
+ for (uint i = 0; i < 127*63; i++) {
+ int x = rand() % 128;
+ int y = rand() % 64;
+ app_api->display_write_pixel(x, y, rand() % 2, 0);
+ }
+ break;
+
+ case 1: {
+ ListWidget widget(app_api, {10, 10, 100, 50});
+ widget.paint();
+ break;
+ }
+
+ default:
+ break;
+ }
return AppReturnValues::OK;
}
BaseApp::AppReturnValues app_tests::btn_pressed(Api *app_api, uint gpio, unsigned long delta) {
+ if (gpio == BUTTON_MODE and ++m_current_screen > (NUMBER_OF_SCREENS-1))
+ m_current_screen = 0;
+
return AppReturnValues::OK;
}
diff --git a/apps/tests/main.hpp b/apps/tests/main.hpp
index 471c172..394a0cd 100644
--- a/apps/tests/main.hpp
+++ b/apps/tests/main.hpp
@@ -5,6 +5,7 @@
class app_tests : public BaseApp {
private:
+ int m_current_screen = 0;
AppAttributes app_attributes = {3, true};
public:
const AppAttributes& app_get_attributes() {
diff --git a/hal/ui/widget/base_widget.hpp b/hal/ui/widget/base_widget.hpp
new file mode 100644
index 0000000..4deabc3
--- /dev/null
+++ b/hal/ui/widget/base_widget.hpp
@@ -0,0 +1,25 @@
+#pragma once
+
+#include "../../api.hpp"
+#include "../../../init.hpp"
+
+class BaseWidget {
+ private:
+ // A pointer to the API is used by the paint method to draw the widget on-screen.
+ Api *m_app_api;
+
+ public:
+ // Widget geometry, in pixels
+ struct Geometry {
+ int x = 0; // top-left corner of widget
+ int y = 0; // top-left corner of widget
+ int width = 1;
+ int height = 1;
+ } m_geometry;
+
+ BaseWidget(Api *app_api, Geometry geometry) :
+ m_app_api{app_api},
+ m_geometry{geometry}
+ {}
+ virtual void paint(bool invert_colors = false) = 0;
+};
diff --git a/hal/ui/widget/list_widget.cpp b/hal/ui/widget/list_widget.cpp
new file mode 100644
index 0000000..5a759fe
--- /dev/null
+++ b/hal/ui/widget/list_widget.cpp
@@ -0,0 +1,9 @@
+#include "list_widget.hpp"
+
+ListWidget::ListWidget(Api *app_api, Geometry geometry) {
+ printf("On init: m_x=%d and x=%d", m_geometry.x, geometry.x);
+}
+
+void ListWidget::paint(bool invert_colors) {
+ m_app_api->display_draw_rectange(m_geometry.x, m_geometry.y, m_geometry.x+m_geometry.width, m_geometry.y+m_geometry.height, 1, 1);
+}
diff --git a/hal/ui/widget/list_widget.hpp b/hal/ui/widget/list_widget.hpp
new file mode 100644
index 0000000..27922f2
--- /dev/null
+++ b/hal/ui/widget/list_widget.hpp
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "base_widget.hpp"
+
+class ListWidget : private BaseWidget {
+ public:
+ ListWidget(Api *app_api, Geometry geometry);
+ void paint(bool invert_colors = false);
+};
diff --git a/init.hpp b/init.hpp
index 26b884f..c7d83df 100644
--- a/init.hpp
+++ b/init.hpp
@@ -1,5 +1,4 @@
-#ifndef __INIT_H__
-#define __INIT_H__
+#pragma once
// To modify the I2C port used, change the `#define I2C_PORT` in "oled/BitBang_I2C.c"
// Pin numbers are GPIO pins.
@@ -8,6 +7,9 @@
#define RESET_PIN -1
#define OLED_DEFAULT_CONTRAST 40
+#define OLED_WIDTH 128
+#define OLED_HEIGHT 64
+
// Initial date & time
// The idea is to have the compiler set the date at compile-time.
// DOTW: 0 is Sunday
@@ -27,5 +29,3 @@
void init_all();
// Init onboard RTC
void init_rtc();
-
-#endif \ No newline at end of file