#include #include "pico/stdlib.h" extern "C" { #include "hardware/rtc.h" } #include "api.hpp" #include "init.hpp" #include "globals.hpp" void Api::init() { if (!m_init_done) { init_display(); m_init_done = 1; } } 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, g_user.oled_contrast); oledSetBackBuffer(&m_oled, m_ucBuffer); // Seems to be required to draw lines, rectangles… //oledSetTextWrap(&oled, true); } 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; } void Api::display_fill(unsigned char ucData, int bRender) { oledFill(&m_oled, ucData, bRender); } void Api::display_draw_line(int x1, int y1, int x2, int y2, int bRender) { oledDrawLine(&m_oled, x1, y1, x2, y2, 0); m_writebb_needed = true; } 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 } void Api::display_draw_ellipse(int iCenterX, int iCenterY, int32_t iRadiusX, int32_t iRadiusY, uint8_t ucColor, uint8_t bFilled) { oledEllipse(&m_oled, iCenterX, iCenterY, iRadiusX, iRadiusY, ucColor, bFilled); m_writebb_needed = true; } void Api::display_write_buffer(uint8_t *pBuffer) { oledDumpBuffer(&m_oled, pBuffer); } void Api::display_write_backbuffer() { if (m_writebb_needed) oledDumpBuffer(&m_oled, m_ucBuffer); m_writebb_needed = false; } int Api::display_write_pixel(int x, int y, unsigned char ucColor, int bRender) { return oledSetPixel(&m_oled, x, y, ucColor, bRender); } void Api::gui_popup_generic(std::string &title, std::string &body, int max_title_length, int max_body_length) { oledRectangle(&m_oled, 9,7, 119,63, 0, 1); // Background oledRectangle(&m_oled, 9,7, 119,63, 1, 0); // Popup border oledRectangle(&m_oled, 9,7, 119,16, 1, 1); // Title background, FIXME pixel bleeding m_writebb_needed = true; this->display_write_backbuffer(); // Display rectangle and anything else behind it (drawn before), could be moved after writing strings (but not done for debugging) // Truncate longer strings to avoid wasting time in for loop and drawing on OLED if (max_title_length > 13) max_title_length = 13; if (max_body_length > 78) max_body_length = 78; if (title.size() > max_title_length) title.resize(13); if (body.size() > max_body_length) body.resize(78)
#ifndef UI_SUMMARY_H
#define UI_SUMMARY_H

extern void cgit_print_summary();
extern void cgit_print_repo_readme(char *path);

#endif /* UI_SUMMARY_H */
hoices[current_index]); } while (m_button_last_pressed != BUTTON_SELECT); // Give back control to running app oledFill(&m_oled, 0, 1); m_interpret_button_press = true; return current_index; } bool Api::gui_footer_text(std::string text, int offset_x, int offset_row, bool invert, bool no_bg) { // Max chars per line for FONT_8x8 is 16 chars // Max chars per line for FONT_6x8 is 21 chars // Truncate longer text if (text.size() > 21) text.resize(21); // Choose most adapted font size int font; if (text.size() > 16) font = FONT_6x8; else font = FONT_8x8; if (!no_bg) { oledRectangle(&m_oled, 0,56-offset_row*8, 127,64-offset_row*8, invert, 1); m_writebb_needed = true; } oledWriteString(&m_oled, 0,offset_x,7-offset_row, text.c_str(), font, invert, 0); } bool Api::gui_header_text(std::string text, int offset_x, int offset_row, bool invert, bool no_bg) { // Max chars per line for FONT_8x8 is 16 chars // Max chars per line for FONT_6x8 is 21 chars // Truncate longer text if (text.size() > 21) text.resize(21); // Choose most adapted font size int font; if (text.size() > 16) font = FONT_6x8; else font = FONT_8x8; if (!no_bg) { oledRectangle(&m_oled, 0,0+offset_row*8, 127,8+offset_row*8, invert, 1); m_writebb_needed = true; } oledWriteString(&m_oled, 0,offset_x,0+offset_row, text.c_str(), font, invert, 0); } bool Api::performance_set(int perf) { return false; } bool Api::datetime_get(datetime_t *t) { return rtc_get_datetime(t); } bool Api::datetime_set(datetime_t *t) { return rtc_set_datetime(t); } uint Api::button_last_get() { return m_button_last_pressed; } void Api::button_last_set(uint gpio) { m_button_last_pressed = gpio; }