Skip to content

Commit

Permalink
Partial display update, more SAO stuff, update PAX graphics library
Browse files Browse the repository at this point in the history
  • Loading branch information
renzenicolai committed Apr 29, 2023
1 parent 9df0e24 commit d9ae922
Show file tree
Hide file tree
Showing 10 changed files with 469 additions and 138 deletions.
2 changes: 2 additions & 0 deletions components/gui-toolkit/include/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ typedef struct menu {
menu_item_t* firstItem;
size_t length;
size_t position;
size_t prev_pos;
float entry_height;
float text_height;
pax_buf_t* icon;
Expand Down Expand Up @@ -68,6 +69,7 @@ pax_buf_t* menu_get_icon(menu_t* menu, size_t position);
void menu_debug(menu_t* menu);
void menu_render(pax_buf_t* pax_buffer, menu_t* menu, float position_x, float position_y, float width, float height);
void menu_render_grid(pax_buf_t* buffer, menu_t* menu, float position_x, float position_y, float width, float height);
void menu_render_grid_changes(pax_buf_t* buffer, menu_t* menu, float position_x, float position_y, float width, float height);

#ifdef __cplusplus
}
Expand Down
66 changes: 65 additions & 1 deletion components/gui-toolkit/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ menu_t* menu_alloc(const char* title, float entry_height, float text_height) {
menu->firstItem = NULL;
menu->length = 0;
menu->position = 0;
menu->prev_pos = 0;
menu->entry_height = (entry_height > 0) ? entry_height : 20;
menu->text_height = (text_height > 0) ? text_height : (entry_height - 2);
menu->icon = NULL;
Expand Down Expand Up @@ -168,6 +169,7 @@ bool menu_remove_item(menu_t* menu, size_t position) {
bool menu_navigate_to(menu_t* menu, size_t position) {
if (menu == NULL) return false;
if (menu->length < 1) return false;
menu->prev_pos = menu->position;
menu->position = position;
if (menu->position >= menu->length) menu->position = menu->length - 1;
return true;
Expand All @@ -176,6 +178,7 @@ bool menu_navigate_to(menu_t* menu, size_t position) {
void menu_navigate_previous(menu_t* menu) {
if (menu == NULL) return;
if (menu->length < 1) return;
menu->prev_pos = menu->position;
menu->position--;
if (menu->position > menu->length) {
menu->position = menu->length - 1;
Expand All @@ -185,6 +188,7 @@ void menu_navigate_previous(menu_t* menu) {
void menu_navigate_next(menu_t* menu) {
if (menu == NULL) return;
if (menu->length < 1) return;
menu->prev_pos = menu->position;
menu->position = (menu->position + 1) % menu->length;
}

Expand All @@ -203,6 +207,7 @@ void menu_navigate_next_row(menu_t* menu) {
size_t menu_get_position(menu_t* menu) { return menu->position; }

void menu_set_position(menu_t* menu, size_t position) {
menu->prev_pos = menu->position;
menu->position = position;
if (menu->length < 1) {
menu->position = 0;
Expand Down Expand Up @@ -337,7 +342,7 @@ void menu_render_grid(pax_buf_t* pax_buffer, menu_t* menu, float position_x, flo
size_t max_items = entry_count_x * entry_count_y;

pax_noclip(pax_buffer);

render_header(pax_buffer, position_x, position_y, width, header_height, text_height, menu->titleColor, menu->titleBgColor, menu->icon, menu->title);

pax_outline_rect(pax_buffer, menu->borderColor, position_x, position_y, width, height);
Expand Down Expand Up @@ -385,3 +390,62 @@ void menu_render_grid(pax_buf_t* pax_buffer, menu_t* menu, float position_x, flo

pax_noclip(pax_buffer);
}

void menu_render_grid_changes(pax_buf_t* pax_buffer, menu_t* menu, float position_x, float position_y, float width, float height) {
const pax_font_t* font = pax_font_saira_regular;
float header_height = menu->entry_height;
float margin_x = menu->grid_margin_x;
float margin_y = menu->grid_margin_y;
int entry_count_x = menu->grid_entry_count_x;
int entry_count_y = menu->grid_entry_count_y;
float entry_width = (width - (margin_x * (entry_count_x + 1))) / entry_count_x;
float entry_height = (height - header_height - (margin_y * (entry_count_y + 1))) / entry_count_y;
float text_height = menu->text_height;
size_t max_items = entry_count_x * entry_count_y;

pax_noclip(pax_buffer);

size_t item_offset = 0;
if (menu->position >= max_items) {
item_offset = menu->position - max_items + 1;
}

for (int step = 0; step < 2; step++) {
size_t index = step ? menu->position : menu->prev_pos;
menu_item_t* item = _menu_find_item(menu, index);
if (item == NULL) {
printf("Render error: item is NULL at %u\n", index);
break;
}

size_t position = index - item_offset;

float item_position_x = position_x + margin_x + ((position % entry_count_x) * (entry_width + margin_x));
float item_position_y = position_y + margin_y + ((position / entry_count_x) * (entry_height + margin_y)) + header_height;

float icon_size = (item->icon != NULL) ? 33 : 0;
float text_offset = ((entry_height - text_height - icon_size) / 2) + icon_size + 1;

pax_vec1_t text_size = pax_text_size(font, text_height, item->label);
if (index == menu->position) {
pax_simple_rect(pax_buffer, menu->selectedItemColor, item_position_x, item_position_y, entry_width, entry_height);
pax_clip(pax_buffer, item_position_x, item_position_y, entry_width, entry_height);
pax_draw_text(pax_buffer, menu->bgTextColor, font, text_height, item_position_x + ((entry_width - text_size.x) / 2), item_position_y + text_offset,
item->label);
} else {
pax_simple_rect(pax_buffer, menu->bgColor, item_position_x, item_position_y, entry_width, entry_height);
pax_clip(pax_buffer, item_position_x, item_position_y, entry_width, entry_height);
pax_draw_text(pax_buffer, menu->fgColor, font, text_height, item_position_x + ((entry_width - text_size.x) / 2), item_position_y + text_offset,
item->label);
}

if (item->icon != NULL) {
pax_clip(pax_buffer, item_position_x + ((entry_width - icon_size) / 2), item_position_y, icon_size, icon_size);
pax_draw_image(pax_buffer, item->icon, item_position_x + ((entry_width - icon_size) / 2), item_position_y);
}

pax_noclip(pax_buffer);
}

pax_noclip(pax_buffer);
}
2 changes: 1 addition & 1 deletion components/mch2022-bsp
Submodule mch2022-bsp updated 1 files
+8 −1 hardware.c
2 changes: 1 addition & 1 deletion components/pax-codecs
Submodule pax-codecs updated 3 files
+3 −0 .gitignore
+51 −0 Standalone.mk
+14 −11 src/pax_codecs.c
2 changes: 1 addition & 1 deletion components/pax-graphics
Submodule pax-graphics updated 84 files
+1 −0 .gitignore
+3 −0 .gitmodules
+27 −15 CMakeLists.txt
+23 −0 ESP_IDF.cmake
+19 −17 LICENSE
+31 −5 README.md
+38 −0 Standalone.cmake
+12 −0 Standalone.mk
+34 −0 checklist.md
+2 −3 component.mk
+126 −432 docs/README.md
+490 −0 docs/c/README.md
+1 −1 docs/c/codecs.md
+32 −32 docs/c/colors.md
+195 −0 docs/c/drawing.md
+ docs/c/images/getting_started_i_background.jpg
+ docs/c/images/getting_started_i_circle.jpg
+ docs/c/images/getting_started_i_text.jpg
+ docs/c/images/matrices.xcf
+ docs/c/images/matrices_apply.png
+ docs/c/images/matrices_initial.png
+ docs/c/images/matrices_pop.png
+ docs/c/images/matrices_push.png
+ docs/c/images/matrices_reset.png
+60 −60 docs/c/matrices.md
+368 −0 docs/c/misc.md
+94 −93 docs/c/setup.md
+115 −0 docs/c/shaders.md
+374 −0 docs/cpp/README.md
+258 −0 docs/cpp/buffer.md
+489 −0 docs/cpp/drawing.md
+142 −0 docs/cpp/matrix.md
+1 −0 docs/cpp/shaders.md
+0 −0 docs/cpp/shapes.md
+65 −0 docs/cpp/textbox.md
+0 −113 docs/drawing.md
+146 −0 docs/pixelformat.md
+0 −62 docs/shaders.md
+89 −0 docs/supported-platforms.md
+2 −2 library.properties
+48 −0 pack_headers.py
+43 −0 precalc.py
+28 −0 src/PAX_Graphics.h
+849 −0 src/cpp/pax_cxx.cpp
+502 −0 src/cpp/pax_cxx.hpp
+396 −0 src/cpp/pax_cxx_shape.cpp
+171 −0 src/cpp/pax_cxx_shape.hpp
+372 −0 src/cpp/pax_cxx_text.cpp
+283 −0 src/cpp/pax_cxx_text.hpp
+ src/fonts/Permanent Marker.pax_font
+ src/fonts/Saira Condensed.pax_font
+ src/fonts/Saira Regular.pax_font
+ src/fonts/Sky mono.pax_font
+ src/fonts/Sky.pax_font
+1,034 −1,630 src/fonts/font_bitmap_permanentmarker.c
+36 −4,912 src/fonts/font_bitmap_sairacondensed.c
+81 −81 src/fonts/font_bitmap_sairaregular.c
+18 −18 src/fonts/font_bitmap_sky.c
+107 −0 src/helpers/pax_dh_generic_rect.h
+141 −69 src/helpers/pax_dh_mcr_shaded.c
+34 −21 src/helpers/pax_dh_mcr_unshaded.c
+267 −67 src/helpers/pax_dh_shaded.c
+113 −32 src/helpers/pax_dh_unshaded.c
+51 −0 src/helpers/pax_mcr_dummy.c
+40 −33 src/helpers/pax_mcr_esp32.c
+269 −0 src/helpers/pax_mcr_pthread.c
+197 −0 src/helpers/precalculated.c
+32 −8 src/pax_config.h
+16 −16 src/pax_fonts.c
+4 −83 src/pax_fonts.h
+837 −392 src/pax_gfx.c
+287 −62 src/pax_gfx.h
+347 −13 src/pax_internal.h
+3 −3 src/pax_matrix.c
+715 −0 src/pax_matrix.h
+537 −0 src/pax_setters.c
+95 −43 src/pax_shaders.c
+25 −12 src/pax_shaders.h
+633 −87 src/pax_shapes.c
+87 −20 src/pax_shapes.h
+694 −81 src/pax_text.c
+39 −11 src/pax_text.h
+223 −82 src/pax_types.h
+1 −0 src/pthreadqueue
103 changes: 103 additions & 0 deletions main/include/sao_eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,108 @@ typedef struct _SAO {
uint8_t driver_data_length;
} SAO;

typedef struct __attribute__((__packed__)) _sao_binary_header {
uint8_t magic[4];
uint8_t name_length;
uint8_t driver_name_length;
uint8_t driver_data_length;
uint8_t number_of_drivers; // 0 indicates a single driver
} sao_binary_header_t;

// Storage driver
// Note: this driver can also be used as driver for SAOs with basic LED and button IO

#define SAO_DRIVER_STORAGE_NAME "storage"

typedef struct __attribute__((__packed__)) _sao_driver_storage_data {
uint8_t flags; // A combination of one or more flag bits
uint8_t address; // I2C address of the data EEPROM (0x50 when using main EEPROM, usually 0x51 when using a separate data EEPROM)
uint8_t size_exp; // For example 15 for 32 kbit
uint8_t page_size_exp; // For example 6 for 64 bytes
uint8_t data_offset; // In pages, needed to skip header
uint8_t reserved; // Reserved, set to 0
} sao_driver_storage_data_t;

#define SAO_DRIVER_STORAGE_FLAG_IO1_LED (1 << 0)
#define SAO_DRIVER_STORAGE_FLAG_IO2_LED (1 << 1)
#define SAO_DRIVER_STORAGE_FLAG_IO1_BUTTON (1 << 2)
#define SAO_DRIVER_STORAGE_FLAG_IO2_BUTTON (1 << 3)
#define SAO_DRIVER_STORAGE_FLAG_IO1_INTERRUPT (1 << 3)
#define SAO_DRIVER_STORAGE_FLAG_IO2_INTERRUPT (1 << 4)

// Neopixel driver

#define SAO_DRIVER_NEOPIXEL_NAME "neopixel"

enum SAO_DRIVER_NEOPIXEL_COLOR_ORDER {
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_RGB = 0,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_GBG = 1,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_GRB = 2,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_GBR = 3,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_BRG = 4,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_BGR = 5,

SAO_DRIVER_NEOPIXEL_COLOR_ORDER_WRGB = 6,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_WRBG = 7,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_WGRB = 8,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_WGBR = 9,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_WBRG = 10,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_WBGR = 11,

SAO_DRIVER_NEOPIXEL_COLOR_ORDER_RWGB = 12,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_RWBG = 13,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_RGWB = 14,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_RGBW = 15,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_RBWG = 16,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_RBGW = 17,

SAO_DRIVER_NEOPIXEL_COLOR_ORDER_GWRB = 18,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_GWBR = 19,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_GRWB = 20,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_GRBW = 21,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_GBWR = 22,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_GBRW = 23,

SAO_DRIVER_NEOPIXEL_COLOR_ORDER_BWRG = 24,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_BWGR = 25,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_BRWG = 26,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_BRGW = 27,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_BGWR = 28,
SAO_DRIVER_NEOPIXEL_COLOR_ORDER_BGRW = 29,
};

typedef struct __attribute__((__packed__)) _sao_driver_neopixel_data {
uint16_t length; // Length in LEDs
uint8_t color_order; // One of the values defined in the color order enum
uint8_t reserved; // Reserved, set to 0
} sao_driver_neopixel_data_t;

// SSD1306 driver

#define SAO_DRIVER_SSD1306_NAME "ssd1306"

typedef struct __attribute__((__packed__)) _sao_driver_ssd1306_data {
uint8_t address; // I2C address of the SSD1306 OLED (usually 0x3C)
uint8_t height; // 32 or 64, in pixels
uint8_t reserved; // Reserved, set to 0
} sao_driver_ssd1306_data_t;

// NTAG NFC driver

#define SAO_DRIVER_NTAG_NAME "ntag"

typedef struct __attribute__((__packed__)) _sao_driver_ntag_data {
uint8_t address; // I2C address of the NTAG IC (usually 0x55)
uint8_t size_exp; // 10 (1k) for NT3H2111 or 11 (2k) for NT3H2211
uint8_t reserved; // Reserved, set to 0
} sao_driver_ntag_data_t;

// App link driver

#define SAO_DRIVER_APP_NAME "app"
// data is a string containing the slug name of the app, null terminated

esp_err_t sao_identify(SAO* sao);
esp_err_t sao_write_raw(size_t offset, uint8_t* buffer, size_t buffer_length);
esp_err_t sao_format(const char* name, const char* driver, const uint8_t* driver_data, uint8_t driver_data_length, const char* driver2,
const uint8_t* driver2_data, uint8_t driver2_data_length);
Loading

0 comments on commit d9ae922

Please sign in to comment.