#include #include "global.h" #include "st7735.h" #include "Images/digi18x32.h" #include "monoimg.h" #include "bmfont.h" #include "asciifont.h" void ui_text_number18x32(uint32_t num, uint16_t x, uint16_t y, uint16_t color) { uint32_t tmp = num; uint32_t div = 1; uint8_t num_count = 0; while (tmp > 0) { tmp = tmp / 10; num_count ++; div = div * 10; } div = div / 10; if (div == 0) { mimg_Area area = mimg_get_tile_area(IMG_DIGI_18_32, 10, 1, 0); mimg_draw(ST7735_DrawPixel, x, y, color, IMG_DIGI_18_32, area); } else { while (div > 0) { tmp = (num / div) % 10; mimg_Area area = mimg_get_tile_area(IMG_DIGI_18_32, 10, 1, tmp); mimg_draw(ST7735_DrawPixel, x, y, color, IMG_DIGI_18_32, area); x = x + 18; div = div / 10; } } } void ui_text_number18x32_with_bg(uint32_t num, uint16_t x, uint16_t y, uint16_t color, uint16_t bg_color) { uint32_t tmp = num; uint32_t div = 1; uint8_t num_count = 0; while (tmp > 0) { tmp = tmp / 10; num_count ++; div = div * 10; } div = div / 10; if (div == 0) { mimg_Area area = mimg_get_tile_area(IMG_DIGI_18_32, 10, 1, 0); mimg_draw_with_bg(ST7735_DrawPixel, x, y, color, bg_color, IMG_DIGI_18_32, area); } else { while (div > 0) { tmp = (num / div) % 10; mimg_Area area = mimg_get_tile_area(IMG_DIGI_18_32, 10, 1, tmp); mimg_draw_with_bg(ST7735_DrawPixel, x, y, color, bg_color, IMG_DIGI_18_32, area); x = x + 18; div = div / 10; } } } // TODO: 绘制界面的函数 /* UI元素 */ void ui_com_main_border() { // border ST7735_FillRectangle(0, 0, ST7735_WIDTH, 1, ST7735_YELLOW); ST7735_FillRectangle(0, 17, ST7735_WIDTH, 1, ST7735_YELLOW); ST7735_FillRectangle(0, ST7735_HEIGHT - 34, ST7735_WIDTH, 1, ST7735_YELLOW); ST7735_FillRectangle(0, ST7735_HEIGHT - 1, ST7735_WIDTH, 1, ST7735_YELLOW); ST7735_FillRectangle(0, 0, 1, ST7735_HEIGHT, ST7735_YELLOW); ST7735_FillRectangle(ST7735_WIDTH - 1, 0, 1, ST7735_HEIGHT, ST7735_YELLOW); } void ui_com_title_bar(uint8_t clear, uint8_t *text, uint32_t bytes_len) { if (clear) { ST7735_FillRectangle(1, 1, ST7735_WIDTH - 2, 16, ST7735_BLACK); } uint16_t off_x = (ST7735_WIDTH - 2 - bmf_get_text_width(font_unifont_16x16, text, bytes_len)) / 2 + 1; bmf_draw_text(font_unifont_16x16, text, bytes_len, off_x, 1, ST7735_WIDTH - 2, 16, ST7735_YELLOW); } void ui_com_freq_digital(uint8_t clear) { // 5位数字, 即高32+2(小数点高度),宽90 uint16_t off_x = (ST7735_WIDTH - 90) / 2; uint16_t off_y = (ST7735_HEIGHT - 34 - 34 - 18) / 2 + 17; if (global_data.rf_mode == G_RF_MODE_AM) { uint16_t scale = 10000; uint32_t tmp = 0; if (clear) { ST7735_FillRectangle(off_x, off_y+32, 90, 2, ST7735_BLACK); // 清除小数点 } while (scale > 0) { if (clear) { ui_text_number18x32_with_bg(tmp, off_x, off_y, ST7735_COLOR565(0xFF, 0x7F, 0), ST7735_BLACK); } else { ui_text_number18x32(tmp, off_x, off_y, ST7735_COLOR565(0xFF, 0x7F, 0)); } off_x += 18; scale /= 10; } } else { uint16_t fm_freq = global_data.freq / 20; uint8_t fm_freq_float = (global_data.freq % 20) * 5; uint16_t scale = 100; uint16_t tmp = 0; if (clear) { ST7735_FillRectangle(off_x, off_y + 32, 18 * 3 - 1, 2, ST7735_BLACK); // 清除小数点 ST7735_FillRectangle(off_x + (18 * 3) + 1, off_y + 32, 18 * 2 - 1, 2, ST7735_BLACK); // 清除小数点 } while (scale > 0) { tmp = (fm_freq / scale) % 10; if (clear) { ui_text_number18x32_with_bg(tmp, off_x, off_y, ST7735_COLOR565(0xFF, 0x7F, 0), ST7735_BLACK); } else { ui_text_number18x32(tmp, off_x, off_y, ST7735_COLOR565(0xFF, 0x7F, 0)); } off_x += 18; scale /= 10; } scale = 10; while (scale > 0) { tmp = (fm_freq_float / scale) % 10; if (clear) { ui_text_number18x32_with_bg(tmp, off_x, off_y, ST7735_COLOR565(0xFF, 0x7F, 0), ST7735_BLACK); } else { ui_text_number18x32(tmp, off_x, off_y, ST7735_COLOR565(0xFF, 0x7F, 0)); } off_x += 18; scale /= 10; } } } void ui_com_fm_am(uint8_t clear) { uint16_t area_w = (ST7735_WIDTH - 90) / 2 - 1; uint16_t off_x = 1; uint16_t off_y = 34 + 32; if (clear) { ST7735_FillRectangle(off_x, off_y, area_w, 16, ST7735_BLACK); ST7735_FillRectangle(ST7735_WIDTH - area_w - 1 - 1, off_y, area_w, 16, ST7735_BLACK); } if (global_data.rf_mode == G_RF_MODE_AM) { off_x = (area_w - bmf_get_text_width(font_unifont_16x16, u8str("AM"), 2)) / 2; bmf_draw_text(font_unifont_16x16, u8str("AM"), 2, off_x, off_y, area_w, 16, ST7735_YELLOW); off_x = ST7735_WIDTH - area_w - 1 + (area_w - bmf_get_text_width(font_unifont_16x16, u8str("KHz"), 3)) / 2; bmf_draw_text(font_unifont_16x16, u8str("KHz"), 3, off_x, off_y, area_w, 16, ST7735_BLUE); } else { off_x = (area_w - bmf_get_text_width(font_unifont_16x16, u8str("FM"), 2)) / 2; bmf_draw_text(font_unifont_16x16, u8str("FM"), 2, off_x, off_y, area_w, 16, ST7735_GREEN); off_x = ST7735_WIDTH - area_w - 1 + (area_w - bmf_get_text_width(font_unifont_16x16, u8str("MHz"), 3)) / 2; bmf_draw_text(font_unifont_16x16, u8str("MHz"), 3, off_x, off_y, area_w, 16, ST7735_BLUE); } } void ui_com_progress_bar(uint8_t clear, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t border_color, uint16_t fill_color, uint32_t current, uint32_t total) { if (clear) { ST7735_FillRectangle(x, y, w, h, ST7735_BLACK); } // border ST7735_FillRectangle(x, y, w, 1, border_color); ST7735_FillRectangle(x, y + h - 1, w, 1, border_color); ST7735_FillRectangle(x, y, 1, h, border_color); ST7735_FillRectangle(x + w - 1, y, 1, h, border_color); // bar x += 1; y += 1; w -= 2; h -= 2; uint16_t bar_width = w * current / total; ST7735_FillRectangle(x, y, bar_width, h, fill_color); } void ui_com_vol_bar(uint8_t clear) { uint16_t off_x = 1; uint16_t off_y = ST7735_HEIGHT - 33; if (clear) { ST7735_FillRectangle(off_x, off_y, ST7735_WIDTH - 2, 16, ST7735_BLACK); } uint16_t color_skyblue = ST7735_COLOR565(0, 0x7F, 0xFF); // text, 32x16 off_x = off_x + (32 - bmf_get_text_width(font_unifont_16x16, u8str("VOL"), 3)) / 2; bmf_draw_text(font_unifont_16x16, u8str("VOL"), 3, off_x, off_y, 32, 16, color_skyblue); // bar off_x = 1 + 32; ui_com_progress_bar(clear, 33, off_y + 2, ST7735_WIDTH - 34 - 3, 13, ST7735_WHITE, color_skyblue, global_data.volumn, 16); } void ui_com_sig_bar(uint8_t clear) { uint16_t off_x = 1; uint16_t off_y = ST7735_HEIGHT - 17; if (clear) { ST7735_FillRectangle(off_x, off_y, ST7735_WIDTH - 2, 16, ST7735_BLACK); } // text, 32x16 off_x = off_x + (32 - bmf_get_text_width(font_unifont_16x16, u8str("SIG"), 3)) / 2; bmf_draw_text(font_unifont_16x16, u8str("SIG"), 3, off_x, off_y, 32, 16, ST7735_GREEN); // bar off_x = 1 + 32; ui_com_progress_bar(clear, 33, off_y + 1, ST7735_WIDTH - 34 - 3, 13, ST7735_WHITE, ST7735_GREEN, global_data.signal, 255); } /* 供外部调用的方法 */ void ui_screen_main() { ST7735_FillScreen(ST7735_BLACK); ui_com_main_border(); ui_com_title_bar(0, u8str("Radio"), 5); ui_com_fm_am(0); ui_com_freq_digital(0); ui_com_vol_bar(0); ui_com_sig_bar(0); }