Fix UI Drawing

This commit is contained in:
Jan-Henrik 2019-10-22 21:54:33 +02:00
parent 91fd3e4302
commit 77d8c2d97e
3 changed files with 86 additions and 85 deletions

View file

@ -1,10 +1,10 @@
#include "display.h" #include "display.h"
#include "gpio.h" #include "gpio.h"
#include "spi_mode.h"
#include "stmlib/system/system_clock.h" #include "stmlib/system/system_clock.h"
#include "stmlib/utils/random.h" #include "stmlib/utils/random.h"
#include <stm32f37x_conf.h> #include <stm32f37x_conf.h>
#include <u8g2.h> #include <u8g2.h>
#include "spi_mode.h"
using namespace stmlib; using namespace stmlib;
@ -64,7 +64,6 @@ void Display::Init()
InitGLib(); InitGLib();
} }
uint8_t u8x8_stm32_gpio_and_delay(U8X8_UNUSED u8x8_t* u8x8, uint8_t u8x8_stm32_gpio_and_delay(U8X8_UNUSED u8x8_t* u8x8,
U8X8_UNUSED uint8_t msg, U8X8_UNUSED uint8_t arg_int, U8X8_UNUSED uint8_t msg, U8X8_UNUSED uint8_t arg_int,
U8X8_UNUSED void* arg_ptr) U8X8_UNUSED void* arg_ptr)

View file

@ -56,12 +56,12 @@ void TIM2_IRQHandler(void)
TIM_ClearITPendingBit(TIM2, TIM_IT_Update); TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
// this will get called with 192 kHz (foof) // this will get called with 192 kHz (foof)
// we want to reduce the amount of times the ui gets polled to 1kHz // we want to reduce the amount of times the ui gets polled to 500 Hz
// which still is a lot (60fps would be enough tbh) // which still is a lot (60fps would be enough tbh)
static uint8_t count = 0; static uint8_t count = 0;
count++; count++;
if (count % 192 == 0) { if (count % (192 * 2) == 0) {
ui.Flush(); ui.Flush();
count = 0; count = 0;
} }

View file

@ -12,7 +12,7 @@ const char part_names[4][2] = { "A", "B", "C", "D" };
void UI::Update() void UI::Update()
{ {
u8g2_ClearBuffer(display.u8g2());
switch (current_menu) { switch (current_menu) {
case MENU_PART_1: case MENU_PART_1:
case MENU_PART_2: case MENU_PART_2:
@ -25,20 +25,22 @@ void UI::Update()
break; break;
} }
display.Swap();
} }
void UI::DrawHeader() void UI::DrawHeader()
{ {
u8g2_SetFont(display.u8g2(), u8g2_font_6x12_tf);
for (int i = 0; i < PART_COUNT; i++) { for (int i = 0; i < PART_COUNT; i++) {
u8g2_SetFontMode(display.u8g2(), 1); u8g2_SetFontMode(display.u8g2(), 1);
u8g2_SetDrawColor(display.u8g2(), 1); u8g2_SetDrawColor(display.u8g2(), 1);
if (current_menu == i) if (current_menu == i)
u8g2_DrawBox(display.u8g2(), i * (DISPLAY_WIDTH / PART_COUNT), 0, (DISPLAY_WIDTH / PART_COUNT), HEADER_HEIGHT); u8g2_DrawBox(display.u8g2(), i * (DISPLAY_WIDTH / PART_COUNT), 0, (DISPLAY_WIDTH / PART_COUNT) - 1, HEADER_HEIGHT);
else else
u8g2_DrawFrame(display.u8g2(), i * (DISPLAY_WIDTH / PART_COUNT), 0, (DISPLAY_WIDTH / PART_COUNT), HEADER_HEIGHT); u8g2_DrawFrame(display.u8g2(), i * (DISPLAY_WIDTH / PART_COUNT), 0, (DISPLAY_WIDTH / PART_COUNT) - 1, HEADER_HEIGHT);
u8g2_SetDrawColor(display.u8g2(), 2); u8g2_SetDrawColor(display.u8g2(), 2);
u8g2_DrawStr(display.u8g2(), i * (DISPLAY_WIDTH / PART_COUNT) + 2, 2, part_names[i]); u8g2_DrawStr(display.u8g2(), i * (DISPLAY_WIDTH / PART_COUNT) + 5, 2 + 10, part_names[i]);
u8g2_SetDrawColor(display.u8g2(), 1); u8g2_SetDrawColor(display.u8g2(), 1);
} }
} }