diff --git a/nametag8_CH592/user/ui/menu_base.c b/nametag8_CH592/user/ui/menu_base.c index 058f60f..f427d42 100644 --- a/nametag8_CH592/user/ui/menu_base.c +++ b/nametag8_CH592/user/ui/menu_base.c @@ -29,7 +29,7 @@ void menu_tick() if ((menu == &menu_6) && (menu_idx == 5)) { // about > accelerometer // accelerometer page never flips ssd1306_set_flipmirror(0); - } else if (menu != &menu_none) { // nametag + } else if (menu != &menu_none) { // not nametag if (sysflags & SYS_OLED_ROTATE_X) { ssd1306_set_flipmirror(1); } else { diff --git a/nametag8_CH592/user/ui/menu_entry_0.c b/nametag8_CH592/user/ui/menu_entry_0.c index e8b27cf..ca34a0d 100644 --- a/nametag8_CH592/user/ui/menu_entry_0.c +++ b/nametag8_CH592/user/ui/menu_entry_0.c @@ -102,6 +102,35 @@ static void menu_none_print_error(uint8_t *err1, uint8_t *err2, uint8_t *err3) return; } +__HIGH_CODE +static int8_t rotate_copy(int8_t top, int8_t left, int8_t rot, uint8_t font_idx, uint8_t *txt) +{ + int8_t o, w; + + // set target buffer, need to do this before width calc + // as this will have the halfwidth bit set appropriately + ssd1306fb_set_target(&rotsrc); + + // get left drawing position, so the character is rendered centered + o = ssd1306fb_get_str_width(font_table[font_idx].font, txt, 1, 0); + w = ((rotsrc.width >> 1) - (o >> 1)); + + // clear buffers before work + ssd1306_cls(&rotdst); + ssd1306_cls(&rotsrc); + + // render and rotate + ssd1306fb_set_cursor(w, top); + ssd1306fb_draw_str(font_table[uconf.font_idx].font, txt, 0); + ssd1306fb_rotate(&rotsrc, &rotdst, rot); + + // copy dst buffer to oled buffer in correct position + ssd1306fb_set_target(&oled); + ssd1306fb_copy(left - w, 0, ROTATE_TARGET_WIDTH, ROTATE_TARGET_HEIGHT, rotdst.fb); + + return o; +} + __HIGH_CODE void menu_none_disp(uint8_t idx) { @@ -117,7 +146,7 @@ void menu_none_disp(uint8_t idx) uint8_t disp_mode; - char txt[6]; + char txt[6] = {0}; menu_none_init(); @@ -202,13 +231,11 @@ MENU_0_DISP_CHAR_ROTATE: ssd1306fb_set_color(SSD1306_STATE_SET_PIXEL); menu_none_set_halfwidth(&rotsrc); - txt[1] = 0; - for (i = 0; i < strlen(uconf.name); i++) { j = i; // change character order - if (uconf.nameconf & UCONF_NAME_DISP_MASK) { + if ((uconf.nameconf & UCONF_NAME_DISP_MASK) == UCONF_NAME_DISP_CHAR_ROTATE) { // this method is a bit jumpy, but works for now if (sysflags & SYS_OLED_REVERSE_CHARS) { j = strlen(uconf.name) - i - 1; @@ -217,26 +244,7 @@ MENU_0_DISP_CHAR_ROTATE: txt[0] = uconf.name[j]; - // set target buffer, need to do this before width calc - // as this will have the halfwidth bit set appropriately - ssd1306fb_set_target(&rotsrc); - - // get left drawing position, so the character is rendered centered - o = ssd1306fb_get_str_width(font_table[uconf.font_idx].font, txt, 1, 0); - w = ((rotsrc.width >> 1) - (o >> 1)); - - // clear buffers before work - ssd1306_cls(&rotdst); - ssd1306_cls(&rotsrc); - - // render and rotate - ssd1306fb_set_cursor(w, top); - ssd1306fb_draw_str(font_table[uconf.font_idx].font, txt, 0); - ssd1306fb_rotate(&rotsrc, &rotdst, rot); - - // copy dst buffer to oled buffer in correct position - ssd1306fb_set_target(&oled); - ssd1306fb_copy(left - w, 0, ROTATE_TARGET_WIDTH, ROTATE_TARGET_HEIGHT, rotdst.fb); + o = rotate_copy(top, left, rot, uconf.font_idx, txt); // update position of character based on spacing left += o + uconf.char_spacing;