At least: font code generator, exchange code support for color 128x128
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "SetTimeScreen.h"
|
||||
#include "SystemTime.h"
|
||||
@@ -36,6 +37,10 @@ SetTimeScreen::SetTimeScreen(BSP::DisplayDriver &display,
|
||||
, m_state(SetState::HOURS)
|
||||
, m_is_acked(false)
|
||||
, m_time()
|
||||
, m_font(default_font)
|
||||
, m_row_spacing((m_display.get_height() - m_font.height * 2) / 3)
|
||||
, m_row_0_y(m_row_spacing)
|
||||
, m_row_1_y(m_row_0_y + m_font.height + m_row_spacing + m_font.height)
|
||||
{}
|
||||
|
||||
ReturnCode SetTimeScreen::init()
|
||||
@@ -60,66 +65,92 @@ static char get_char_for_digit(uint8_t bcd_digit)
|
||||
}
|
||||
|
||||
void SetTimeScreen::display_number(uint32_t *x, uint32_t y,
|
||||
uint32_t tens, uint32_t ones, const struct font &f)
|
||||
uint32_t tens, uint32_t ones)
|
||||
{
|
||||
char time_str[3] = { 0 };
|
||||
time_str[0] = get_char_for_digit(tens);
|
||||
time_str[1] = get_char_for_digit(ones);
|
||||
time_str[2] = '\0';
|
||||
|
||||
m_display.string_at(x, y, time_str, &f);
|
||||
|
||||
m_display.string_at(x, y, time_str, &m_font);
|
||||
}
|
||||
|
||||
const char *SetTimeScreen::get_acknak_string()
|
||||
{
|
||||
if (!m_is_acked) {
|
||||
return "Cancel";
|
||||
} else {
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t SetTimeScreen::get_acknak_string_len()
|
||||
{
|
||||
std::size_t len = strlen(get_acknak_string());
|
||||
return len * m_font.width - 1;
|
||||
}
|
||||
|
||||
uint32_t SetTimeScreen::get_acknak_string_x_pos()
|
||||
{
|
||||
std::size_t len = strlen(get_acknak_string());
|
||||
return m_display.get_width() - len * m_font.width - 1;
|
||||
}
|
||||
|
||||
void SetTimeScreen::render_time()
|
||||
{
|
||||
uint32_t x = 0;
|
||||
uint32_t y = 32;
|
||||
const struct font &font = default_font;
|
||||
uint32_t width = m_display.get_width();
|
||||
uint32_t x = (width - m_font.width * 8) / 2;
|
||||
uint32_t y = m_row_spacing;
|
||||
|
||||
display_number(&x, y,
|
||||
m_time.get_hours_12_tens(), m_time.get_hours_12_ones(),
|
||||
font);
|
||||
m_time.get_hours_12_tens(), m_time.get_hours_12_ones());
|
||||
|
||||
m_display.string_at(&x, y, ":", &font);
|
||||
m_display.string_at(&x, y, ":", &m_font);
|
||||
|
||||
display_number(&x, y,
|
||||
m_time.get_minutes_tens(), m_time.get_minutes_ones(),
|
||||
font);
|
||||
m_time.get_minutes_tens(), m_time.get_minutes_ones());
|
||||
|
||||
m_display.string_at(&x, y, ":", &font);
|
||||
m_display.string_at(&x, y, ":", &m_font);
|
||||
|
||||
display_number(&x, y,
|
||||
m_time.get_seconds_tens(), m_time.get_seconds_ones(),
|
||||
font);
|
||||
m_time.get_seconds_tens(), m_time.get_seconds_ones());
|
||||
|
||||
y = m_row_1_y;
|
||||
x = 0;
|
||||
m_display.string_at(&x, y, m_time.get_is_pm() ? "PM" : "AM", &m_font);
|
||||
|
||||
x = get_acknak_string_x_pos();
|
||||
m_display.string_at(&x, y, get_acknak_string(), &m_font);
|
||||
|
||||
m_display.refresh();
|
||||
}
|
||||
|
||||
void SetTimeScreen::draw_line(uint32_t x, uint32_t y, uint32_t width)
|
||||
{
|
||||
for (uint32_t i = 0; i < width; i += 8) {
|
||||
m_display.set_byte(x + i, y, 0);
|
||||
m_display.set_byte(x + i, y + 1, 0);
|
||||
}
|
||||
m_display.draw_hline(x, y, width);
|
||||
m_display.draw_hline(x, y + 1, width);
|
||||
}
|
||||
|
||||
void SetTimeScreen::render_selection()
|
||||
{
|
||||
uint32_t font_width = default_font_width;
|
||||
uint32_t time_offset = (m_display.get_width()- m_font.width * 8) / 2;
|
||||
|
||||
switch (m_state) {
|
||||
case SetState::HOURS:
|
||||
draw_line(0, 64, font_width * 2);
|
||||
draw_line(time_offset, m_row_0_y + m_font.height, m_font.width * 2);
|
||||
break;
|
||||
case SetState::MINUTES:
|
||||
draw_line(font_width * 2, 64, font_width * 2);
|
||||
draw_line(time_offset + m_font.width * 3, m_row_0_y + m_font.height, m_font.width * 2);
|
||||
break;
|
||||
case SetState::SECONDS:
|
||||
draw_line(font_width * 4, 64, font_width * 2);
|
||||
draw_line(time_offset + m_font.width * 6, m_row_0_y + m_font.height, m_font.width * 2);
|
||||
break;
|
||||
case SetState::AM_PM:
|
||||
draw_line(0, m_row_1_y + m_font.height, m_font.width * 2);
|
||||
break;
|
||||
case SetState::ACK_NACK:
|
||||
draw_line(get_acknak_string_x_pos(), m_row_1_y + m_font.height, get_acknak_string_len());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user