summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt18
-rw-r--r--apps/home_menu.c88
-rw-r--r--apps/home_menu.cpp93
-rw-r--r--apps/home_menu.h15
-rw-r--r--apps/home_menu.hpp15
-rw-r--r--apps/main_clock.cpp (renamed from apps/main_clock.c)6
-rw-r--r--apps/main_clock.hpp (renamed from apps/main_clock.h)0
-rw-r--r--buttons.cpp (renamed from buttons.c)2
-rw-r--r--buttons.hpp (renamed from buttons.h)2
-rw-r--r--init.cpp (renamed from init.c)5
-rw-r--r--init.hpp (renamed from init.h)2
-rw-r--r--oled/ss_oled.h8
-rw-r--r--pico-watch.cpp (renamed from pico-watch.c)18
13 files changed, 142 insertions, 130 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0b9aa59..758ac2d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,15 +28,15 @@ target_link_libraries(Oled pico_stdlib hardware_i2c)
# Main code
add_executable(pico-watch
- pico-watch.c
- init.c
- init.h
- buttons.c
- buttons.h
- apps/home_menu.c
- apps/home_menu.h
- apps/main_clock.c
- apps/main_clock.h
+ pico-watch.cpp
+ init.cpp
+ init.hpp
+ buttons.cpp
+ buttons.hpp
+ apps/home_menu.cpp
+ apps/home_menu.hpp
+ apps/main_clock.cpp
+ apps/main_clock.hpp
)
pico_set_program_name(pico-watch "pico-watch")
diff --git a/apps/home_menu.c b/apps/home_menu.c
deleted file mode 100644
index b7c15b0..0000000
--- a/apps/home_menu.c
+++ /dev/null
@@ -1,88 +0,0 @@
-#include <stdio.h>
-#include "pico/stdlib.h"
-#include "hardware/rtc.h"
-#include "pico/util/datetime.h"
-#include "../oled/ss_oled.h"
-
-#include "home_menu.h"
-#include "../buttons.h"
-
-extern void app_switch(int old_appid, int new_appid);
-
-#define NUMBER_OF_APPS 2
-
-char* APPS_NAME[NUMBER_OF_APPS][12] = {"Home", "Clock"};
-
-void title_str(char *buf, uint buf_size, const datetime_t *t) {
- snprintf(buf,
- buf_size,
- "%d:%02d Home Menu",
- t->hour,
- t->min,
- t->sec);
-};
-
-void show_title(SSOLED *oled) {
- char datetime_buf[256];
- char *datetime_str = &datetime_buf[0];
- datetime_t t;
- rtc_get_datetime(&t);
-
- // title with time
- title_str(datetime_str, sizeof(datetime_buf), &t);
- oledWriteString(oled, 0,0,0, datetime_str, FONT_8x8, 0, 1);
-}
-
-// Rendering of app
-int home_menu_render(SSOLED *oled, char *data, uint data_size) {
- show_title(oled);
- oledWriteString(oled, 0,0,2, &data[0], FONT_6x8, 0, 1);
- oledWriteString(oled, 0,5,3, APPS_NAME[data[1]][0], FONT_12x16, 0, 1); // FIXME: The name does not update, it seems that the second string is empty… but data[1]'s content is correct, as BUTTON_SELECT switches to the correct app.
- return 0;
-}
-
-// Interpret button inputs
-int home_menu_btnpressed(SSOLED *oled, char *data, uint data_size, uint gpio) {
- switch (gpio) {
- case BUTTON_HOME:
- data[0] = 'H'; break;
- case BUTTON_SELECT:
- data[0] = 'S';
- app_switch(0, data[1]);
- break;
- case BUTTON_MODE:
- data[0] = 'M'; break;
- case BUTTON_DOWN:
- data[0] = 'D';
- data[1]--;
- break;
- case BUTTON_UP:
- data[0] = 'U';
- data[1]++;
- break;
- default:
- data[0] = '?';
- }
- if (data[1] > NUMBER_OF_APPS-1) {
- data[1] = NUMBER_OF_APPS-1; data[0] = '>';
- } else if (data[1] < NUMBER_OF_APPS-1) {
- data[1] = 0; data[0] = '<';
- }
- return 0;
-}
-
-// Initlisation of the app.
-int home_menu_init(SSOLED *oled, char *data, uint data_size) {
- data[1] = 0;
- return 0; // return 1 when function not implemented
-}
-
-// Processor intensive operations and functions related to drawing to the screen should only be done when the app is in_foreground(=1). This function is only called when the app is init.
-int home_menu_bgrefresh(SSOLED *oled, char *data, uint data_size, char in_foreground) {
- return 1;
-}
-
-// Destruction of app, deinitlisation should be done here. This is only called if the app's APPS_DESTROY_ON_EXIT is set to 1. When it is not a "service" app.
-int home_menu_destroy(SSOLED *oled, char *data, uint data_size) {
- return 1;
-}
diff --git a/apps/home_menu.cpp b/apps/home_menu.cpp
new file mode 100644
index 0000000..30caed0
--- /dev/null
+++ b/apps/home_menu.cpp
@@ -0,0 +1,93 @@
+#include <stdio.h>
+#include "pico/stdlib.h"
+extern "C" {
+#include "hardware/rtc.h"
+}
+#include "pico/util/datetime.h"
+#include "../oled/ss_oled.h"
+
+#include "home_menu.hpp"
+#include "../buttons.hpp"
+
+extern void app_switch(int old_appid, int new_appid);
+extern bool rtc_get_datetime(datetime_t *t);
+
+#define NUMBER_OF_APPS 2
+
+namespace app_home_menu {
+ const char* APPS_NAME[NUMBER_OF_APPS][12] = {"Home", "Clock"};
+
+ void title_str(char *buf, uint buf_size, const datetime_t *t) {
+ snprintf(buf,
+ buf_size,
+ "%d:%02d Home Menu",
+ t->hour,
+ t->min,
+ t->sec);
+ };
+
+ void show_title(SSOLED *oled) {
+ char datetime_buf[256];
+ char *datetime_str = &datetime_buf[0];
+ datetime_t t;
+ rtc_get_datetime(&t);
+
+ // title with time
+ title_str(datetime_str, sizeof(datetime_buf), &t);
+ oledWriteString(oled, 0,0,0, datetime_str, FONT_8x8, 0, 1);
+ }
+
+ // Rendering of app
+ int render(SSOLED *oled, char *data, uint data_size) {
+ show_title(oled);
+ oledWriteString(oled, 0,0,2, &data[0], FONT_6x8, 0, 1);
+ oledWriteString(oled, 0,5,3, const_cast<char*>(APPS_NAME[data[1]][0]), FONT_12x16, 0, 1); // FIXME: The name does not update, it seems that the second string is empty… but data[1]'s content is correct, as BUTTON_SELECT switches to the correct app.
+ return 0;
+ }
+
+ // Interpret button inputs
+ int btnpressed(SSOLED *oled, char *data, uint data_size, uint gpio) {
+ switch (gpio) {
+ case BUTTON_HOME:
+ data[0] = 'H'; break;
+ case BUTTON_SELECT:
+ data[0] = 'S';
+ app_switch(0, data[1]);
+ break;
+ case BUTTON_MODE:
+ data[0] = 'M'; break;
+ case BUTTON_DOWN:
+ data[0] = 'D';
+ data[1]--;
+ break;
+ case BUTTON_UP:
+ data[0] = 'U';
+ data[1]++;
+ break;
+ default:
+ data[0] = '?';
+ }
+ if (data[1] > NUMBER_OF_APPS-1) {
+ data[1] = NUMBER_OF_APPS-1; data[0] = '>';
+ } else if (data[1] < NUMBER_OF_APPS-1) {
+ data[1] = 0; data[0] = '<';
+ }
+ return 0;
+ }
+
+ // Initlisation of the app.
+ int init(SSOLED *oled, char *data, uint data_size) {
+ data[1] = 0;
+ return 0; // return 1 when function not implemented
+ }
+
+ // Processor intensive operations and functions related to drawing to the screen should only be done when the app is in_foreground(=1). This function is only called when the app is init.
+ int bgrefresh(SSOLED *oled, char *data, uint data_size, char in_foreground) {
+ return 1;
+ }
+
+ // Destruction of app, deinitlisation should be done here. This is only called if the app's APPS_DESTROY_ON_EXIT is set to 1. When it is not a "service" app.
+ int destroy(SSOLED *oled, char *data, uint data_size) {
+ return 1;
+ }
+}
diff --git a/apps/home_menu.h b/apps/home_menu.h
deleted file mode 100644
index 507e818..0000000
--- a/apps/home_menu.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef __HOME_MENU_H__
-#define __HOME_MENU_H__
-
-#include "pico/util/datetime.h"
-#include "../oled/ss_oled.h"
-
-void show_title(SSOLED *oled);
-
-int home_menu_init(SSOLED *oled, char *data, uint data_size);
-int home_menu_render(SSOLED *oled, char *data, uint data_size);
-int home_menu_btnpressed(SSOLED *oled, char *data, uint data_size, uint gpio);
-int home_menu_bgrefresh(SSOLED *oled, char *data, uint data_size, char in_foreground);
-int home_menu_destroy(SSOLED *oled, char *data, uint data_size);
-
-#endif \ No newline at end of file
diff --git a/apps/home_menu.hpp b/apps/home_menu.hpp
new file mode 100644
index 0000000..bd648d3
--- /dev/null
+++ b/apps/home_menu.hpp
@@ -0,0 +1,15 @@
+#ifndef __HOME_MENU_H__
+#define __HOME_MENU_H__
+
+#include "pico/util/datetime.h"
+#include "../oled/ss_oled.h"
+
+namespace app_home_menu {
+ int init(SSOLED *oled, char *data, uint data_size);
+ int render(SSOLED *oled, char *data, uint data_size);
+ int btnpressed(SSOLED *oled, char *data, uint data_size, uint gpio);
+ int bgrefresh(SSOLED *oled, char *data, uint data_size, char in_foreground);
+ int destroy(SSOLED *oled, char *data, uint data_size);
+}
+
+#endif
diff --git a/apps/main_clock.c b/apps/main_clock.cpp
index 547057e..9dfee0f 100644
--- a/apps/main_clock.c
+++ b/apps/main_clock.cpp
@@ -1,11 +1,13 @@
#include <stdio.h>
#include "pico/stdlib.h"
+extern "C" {
#include "hardware/rtc.h"
+}
#include "pico/util/datetime.h"
#include "../oled/ss_oled.h"
-#include "main_clock.h"
-#include "../buttons.h"
+#include "main_clock.hpp"
+#include "../buttons.hpp"
// Time as string
// Adapted from pico-sdk/scr/common/pico_util/datetime.c
diff --git a/apps/main_clock.h b/apps/main_clock.hpp
index 70d9755..70d9755 100644
--- a/apps/main_clock.h
+++ b/apps/main_clock.hpp
diff --git a/buttons.c b/buttons.cpp
index 3a71d9c..8ba7b81 100644
--- a/buttons.c
+++ b/buttons.cpp
@@ -1,7 +1,7 @@
#include <stdio.h>
#include "pico/stdlib.h"
-#include "buttons.h"
+#include "buttons.hpp"
// From pico-watch.c:
extern int app_btnpressed(int app_id, uint gpio);
extern void app_switch(int old_appid, int new_appid);
diff --git a/buttons.h b/buttons.hpp
index 756c849..43d2d25 100644
--- a/buttons.h
+++ b/buttons.hpp
@@ -10,8 +10,6 @@
#define BUTTON_MODE 19
#define BUTTON_DOWN 20
#define BUTTON_UP 21
-unsigned long button_time;
-const int button_delayTime;
void init_buttons();
void gpio_interrupt_cb(uint gpio, uint32_t events);
diff --git a/init.c b/init.cpp
index c8a2db3..11d38a6 100644
--- a/init.c
+++ b/init.cpp
@@ -1,10 +1,13 @@
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/i2c.h"
+extern "C" {
#include "hardware/rtc.h"
+}
#include "oled/ss_oled.h"
-#include "init.h"
+#include "init.hpp"
+SSOLED oled;
void init_display() {
oledInit(&oled, OLED_128x64, 0x3d, 0, 0, 1, SDA_PIN, SCL_PIN, RESET_PIN, 1000000L);
diff --git a/init.h b/init.hpp
index a14646e..f63187f 100644
--- a/init.h
+++ b/init.hpp
@@ -7,7 +7,7 @@
#define SCL_PIN 7
#define RESET_PIN -1
#define OLED_DEFAULT_CONTRAST 40
-SSOLED oled;
+extern SSOLED oled;
// Initial date & time
// The idea is to have the compiler set the date at compile-time.
diff --git a/oled/ss_oled.h b/oled/ss_oled.h
index f7e303c..fe6f399 100644
--- a/oled/ss_oled.h
+++ b/oled/ss_oled.h
@@ -1,5 +1,8 @@
#ifndef __SS_OLED_H__
#define __SS_OLED_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
#include "BitBang_I2C.h"
@@ -206,6 +209,7 @@ void oledRectangle(SSOLED *pOLED, int x1, int y1, int x2, int y2, uint8_t ucColo
#if defined(_LINUX_) && defined(__cplusplus)
}
#endif // _LINUX_
-
+#ifdef __cplusplus
+}
+#endif
#endif // __SS_OLED_H__
-
diff --git a/pico-watch.c b/pico-watch.cpp
index 37dcd35..d7b84af 100644
--- a/pico-watch.c
+++ b/pico-watch.cpp
@@ -5,20 +5,20 @@
#include "pico/util/datetime.h"
#include "oled/ss_oled.h"
-#include "init.h"
-#include "buttons.h"
-#include "apps/main_clock.h"
-#include "apps/home_menu.h"
+#include "init.hpp"
+#include "buttons.hpp"
+#include "apps/main_clock.hpp"
+#include "apps/home_menu.hpp"
int current_app = 0;
#define NUMBER_OF_APPS 2
#define APP_DATA_BUFFER_LEN 256
-int (*APPS_FUNC_INIT[NUMBER_OF_APPS])(SSOLED *oled, char *data, uint data_size) = {home_menu_init, main_clock_init};
-int (*APPS_FUNC_RENDER[NUMBER_OF_APPS])(SSOLED *oled, char *data, uint data_size) = {home_menu_render, main_clock_render};
-int (*APPS_FUNC_BTNPRESS[NUMBER_OF_APPS])(SSOLED *oled, char *data, uint data_size, uint gpio) = {home_menu_btnpressed, main_clock_btnpressed};
-int (*APPS_FUNC_BGREFRESH[NUMBER_OF_APPS])(SSOLED *oled, char *data, uint data_size, char in_foreground) = {home_menu_bgrefresh, main_clock_bgrefresh};
-int (*APPS_FUNC_DESTROY[NUMBER_OF_APPS])(SSOLED *oled, char *data, uint data_size) = {home_menu_destroy, main_clock_destroy};
+int (*APPS_FUNC_INIT[NUMBER_OF_APPS])(SSOLED *oled, char *data, uint data_size) = {app_home_menu::init, main_clock_init};
+int (*APPS_FUNC_RENDER[NUMBER_OF_APPS])(SSOLED *oled, char *data, uint data_size) = {app_home_menu::render, main_clock_render};
+int (*APPS_FUNC_BTNPRESS[NUMBER_OF_APPS])(SSOLED *oled, char *data, uint data_size, uint gpio) = {app_home_menu::btnpressed, main_clock_btnpressed};
+int (*APPS_FUNC_BGREFRESH[NUMBER_OF_APPS])(SSOLED *oled, char *data, uint data_size, char in_foreground) = {app_home_menu::bgrefresh, main_clock_bgrefresh};
+int (*APPS_FUNC_DESTROY[NUMBER_OF_APPS])(SSOLED *oled, char *data, uint data_size) = {app_home_menu::destroy, main_clock_destroy};
char APPS_DATA[NUMBER_OF_APPS][APP_DATA_BUFFER_LEN];
int APPS_DESTROY_ON_EXIT[NUMBER_OF_APPS] = {0, 1};
int APPS_IS_INIT[NUMBER_OF_APPS] = {0, 0}; // Only run in background if init