diff options
-rw-r--r-- | api.cpp | 8 | ||||
-rw-r--r-- | api.hpp | 3 | ||||
-rw-r--r-- | buttons.hpp | 9 | ||||
-rw-r--r-- | pico-watch.cpp | 5 |
4 files changed, 20 insertions, 5 deletions
@@ -18,7 +18,7 @@ void Api::init_display() { sleep_ms(500); // Wait for the OLED to settle oledInit(&m_oled, OLED_128x64, 0x3d, 0, 0, 1, SDA_PIN, SCL_PIN, RESET_PIN, 1000000L); oledFill(&m_oled, 0,1); - oledSetContrast(&m_oled, OLED_DEFAULT_CONTRAST); + oledSetContrast(&m_oled, g_user.oled_contrast); oledSetBackBuffer(&m_oled, m_ucBuffer); // Seems to be required to draw lines, rectangles… //oledSetTextWrap(&oled, true); } @@ -27,6 +27,10 @@ void Api::display_power(bool mode) { oledPower(&m_oled, mode); } +void Api::display_set_contrast(unsigned char contrast) { + oledSetContrast(&m_oled, contrast); +} + int Api::display_write_string(int iScrollX, int x, int y, const char *szMsg, int iSize, int bInvert, int bRender) { oledWriteString(&m_oled, iScrollX, x, y, szMsg, iSize, bInvert, 0); m_writebb_needed = true; @@ -41,7 +45,7 @@ void Api::display_draw_line(int x1, int y1, int x2, int y2, int bRender) { m_writebb_needed = true; } -void Api::display_draw_rectange(int x1, int y1, int x2, int y2, uint8_t ucColor, uint8_t bFilled) { +void Api::display_draw_rectange(int x1, int y1, int x2, int y2, uint8_t ucColor, uint8_t bFilled) { // FIXME: Fix typo oledRectangle(&m_oled, x1, y1, x2, y2, ucColor, bFilled); m_writebb_needed = true; // Write the back buffer, after experimentation, seems to be required when drawing this shape } @@ -39,6 +39,9 @@ class Api { void init(); // Control the display's power (on or off) void display_power(bool mode); + // Set the display's contrast. + // \param contrast Between 0 and 255 + void display_set_contrast(unsigned char contrast); int display_write_string(int iScrollX, int x, int y, const char *szMsg, int iSize, int bInvert, int bRender); void display_fill(unsigned char ucData, int bRender); void display_draw_line(int x1, int y1, int x2, int y2, int bRender); diff --git a/buttons.hpp b/buttons.hpp index e3efe43..a2c61c5 100644 --- a/buttons.hpp +++ b/buttons.hpp @@ -1,6 +1,6 @@ #ifndef __BUTTONS_H__ #define __BUTTONS_H__ -#include <stdio.h> +#include "init.hpp" // Init buttons used in conjuction with interrupts // All buttons are connected to ground. @@ -26,7 +26,14 @@ struct global_status { const int button_delay_time = 125; }; +struct user_settings { + unsigned char oled_contrast = OLED_DEFAULT_CONTRAST; + // In milliseconds + unsigned int sleep_delay = ENTER_SLEEP_DELAY; +}; + extern global_status g_s; +extern user_settings g_user; void init_buttons(); void gpio_interrupt_cb(uint gpio, uint32_t events); diff --git a/pico-watch.cpp b/pico-watch.cpp index 8673e33..f75317e 100644 --- a/pico-watch.cpp +++ b/pico-watch.cpp @@ -13,6 +13,7 @@ #include "apps/settings/main.hpp" global_status g_s; +user_settings g_user; Api app_api; #define NUMBER_OF_APPS 3 @@ -84,11 +85,11 @@ int app_bgrefresh(int app_id) { bool repeating_callback(struct repeating_timer *t) { // Enter shallow sleep mode when needed auto time_since_last_press = time_since_button_press(); - if (!g_s.is_sleeping && time_since_last_press > ENTER_SLEEP_DELAY) { + if (!g_s.is_sleeping && time_since_last_press > g_user.sleep_delay) { g_s.is_sleeping = true; app_api.performance_set(Api::perf_modes::ENTER_SHALLOW_SLEEP); app_api.display_power(false); - } else if (g_s.is_sleeping && time_since_last_press < ENTER_SLEEP_DELAY) { + } else if (g_s.is_sleeping && time_since_last_press < g_user.sleep_delay) { g_s.is_sleeping = false; app_api.performance_set(Api::perf_modes::EXIT_SHALLOW_SLEEP); app_api.display_power(true); |