simplify lcd display logic, one screen with 10 positions
This commit is contained in:
parent
6833b44f50
commit
a17d64bd11
@ -43,10 +43,12 @@ int main(void)
|
|||||||
last = date_time.time.sec;
|
last = date_time.time.sec;
|
||||||
if (last % 2 == 0) {
|
if (last % 2 == 0) {
|
||||||
watch_set_led_color(50, 0);
|
watch_set_led_color(50, 0);
|
||||||
watch_display_string(&watch, watch.main_display, " Hello");
|
watch_display_string(&watch, "0123456789", 0);
|
||||||
} else {
|
} else {
|
||||||
watch_set_led_color(0, 50);
|
watch_set_led_color(0, 50);
|
||||||
watch_display_string(&watch, watch.main_display, " there");
|
watch_display_string(&watch, "01", 0);
|
||||||
|
watch_display_string(&watch, "23", 2);
|
||||||
|
watch_display_string(&watch, "456789", 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,11 @@ const uint8_t Character_Set[] =
|
|||||||
void watch_enable_display(Watch *watch) {
|
void watch_enable_display(Watch *watch) {
|
||||||
if (watch->display_enabled) return;
|
if (watch->display_enabled) return;
|
||||||
|
|
||||||
static const uint64_t main_segmap[] = {
|
static const uint64_t segmap[] = {
|
||||||
|
0x4e4f0e8e8f8d4d0d, // Position 8
|
||||||
|
0xc8c4c4c8b4b4b0b, // Position 9
|
||||||
|
0xc049c00a49890949, // Position 6
|
||||||
|
0xc048088886874707, // Position 7
|
||||||
0xc053921252139352, // Position 0
|
0xc053921252139352, // Position 0
|
||||||
0xc054511415559594, // Position 1
|
0xc054511415559594, // Position 1
|
||||||
0xc057965616179716, // Position 2
|
0xc057965616179716, // Position 2
|
||||||
@ -124,41 +128,24 @@ void watch_enable_display(Watch *watch) {
|
|||||||
0xc043420203048382, // Position 4
|
0xc043420203048382, // Position 4
|
||||||
0xc045440506468584, // Position 5
|
0xc045440506468584, // Position 5
|
||||||
};
|
};
|
||||||
watch->main_display.num_chars = 6;
|
watch->num_chars = 10;
|
||||||
watch->main_display.chars = malloc(6);
|
watch->segment_map = &segmap[0];
|
||||||
watch->main_display.segment_map = &main_segmap[0];
|
|
||||||
|
|
||||||
static const uint64_t day_segmap[] = {
|
|
||||||
0xc049c00a49890949, // Position 6
|
|
||||||
0xc048088886874707, // Position 7
|
|
||||||
};
|
|
||||||
watch->day_display.num_chars = 2;
|
|
||||||
watch->day_display.chars = malloc(2);
|
|
||||||
watch->day_display.segment_map = &day_segmap[0];
|
|
||||||
|
|
||||||
static const uint64_t date_segmap[] = {
|
|
||||||
0x4e4f0e8e8f8d4d0d, // Position 8
|
|
||||||
0xc8c4c4c8b4b4b0b, // Position 9
|
|
||||||
};
|
|
||||||
watch->date_display.num_chars = 2;
|
|
||||||
watch->date_display.chars = malloc(2);
|
|
||||||
watch->date_display.segment_map = &date_segmap[0];
|
|
||||||
|
|
||||||
SEGMENT_LCD_0_init();
|
SEGMENT_LCD_0_init();
|
||||||
slcd_sync_enable(&SEGMENT_LCD_0);
|
slcd_sync_enable(&SEGMENT_LCD_0);
|
||||||
watch->display_enabled = true;
|
watch->display_enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void watch_display_pixel(Watch *watch, WatchDisplay display, uint8_t com, uint8_t seg) {
|
void watch_display_pixel(Watch *watch, uint8_t com, uint8_t seg) {
|
||||||
slcd_sync_seg_on(&SEGMENT_LCD_0, SLCD_SEGID(com, seg));
|
slcd_sync_seg_on(&SEGMENT_LCD_0, SLCD_SEGID(com, seg));
|
||||||
}
|
}
|
||||||
|
|
||||||
void watch_clear_pixel(Watch *watch, WatchDisplay display, uint8_t com, uint8_t seg) {
|
void watch_clear_pixel(Watch *watch, uint8_t com, uint8_t seg) {
|
||||||
slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(com, seg));
|
slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(com, seg));
|
||||||
}
|
}
|
||||||
|
|
||||||
void watch_display_character(Watch *watch, WatchDisplay display, uint8_t character, uint8_t position) {
|
void watch_display_character(Watch *watch, uint8_t character, uint8_t position) {
|
||||||
uint64_t segmap = display.segment_map[position];
|
uint64_t segmap = watch->segment_map[position];
|
||||||
uint64_t segdata = Character_Set[character - 0x20];
|
uint64_t segdata = Character_Set[character - 0x20];
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
@ -177,12 +164,12 @@ void watch_display_character(Watch *watch, WatchDisplay display, uint8_t charact
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void watch_display_string(Watch *watch, WatchDisplay display, char *string) {
|
void watch_display_string(Watch *watch, char *string, uint8_t position) {
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
while(string[i] != 0) {
|
while(string[i] != 0) {
|
||||||
watch_display_character(watch, display, string[i], i);
|
watch_display_character(watch, string[i], position + i);
|
||||||
i++;
|
i++;
|
||||||
if (i >= display.num_chars) break;
|
if (i >= watch->num_chars) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,17 +11,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "hpl_calendar.h"
|
#include "hpl_calendar.h"
|
||||||
|
|
||||||
typedef struct WatchDisplay {
|
|
||||||
uint8_t num_chars;
|
|
||||||
uint8_t* chars;
|
|
||||||
const uint64_t* segment_map;
|
|
||||||
} WatchDisplay;
|
|
||||||
|
|
||||||
typedef struct Watch {
|
typedef struct Watch {
|
||||||
struct WatchDisplay main_display; // 6 chars, main line.
|
|
||||||
struct WatchDisplay day_display; // 2 chars, alphanumeric-ish. top center.
|
|
||||||
struct WatchDisplay date_display; // 2 chars, only supports numbers 0-39. top right.
|
|
||||||
|
|
||||||
bool display_enabled;
|
bool display_enabled;
|
||||||
bool led_enabled;
|
bool led_enabled;
|
||||||
bool buzzer_enabled;
|
bool buzzer_enabled;
|
||||||
@ -30,13 +20,16 @@ typedef struct Watch {
|
|||||||
bool i2c_enabled;
|
bool i2c_enabled;
|
||||||
bool spi_enabled;
|
bool spi_enabled;
|
||||||
bool eic_enabled;
|
bool eic_enabled;
|
||||||
|
|
||||||
|
uint8_t num_chars;
|
||||||
|
const uint64_t* segment_map;
|
||||||
} Watch;
|
} Watch;
|
||||||
|
|
||||||
void watch_init(Watch *watch);
|
void watch_init(Watch *watch);
|
||||||
|
|
||||||
void watch_enable_display(Watch *watch);
|
void watch_enable_display(Watch *watch);
|
||||||
void watch_display_pixel(Watch *watch, WatchDisplay display, uint8_t com, uint8_t seg);
|
void watch_display_pixel(Watch *watch, uint8_t com, uint8_t seg);
|
||||||
void watch_display_string(Watch *watch, WatchDisplay display, char *string);
|
void watch_display_string(Watch *watch, char *string, uint8_t position);
|
||||||
|
|
||||||
void watch_enable_led(Watch *watch);
|
void watch_enable_led(Watch *watch);
|
||||||
void watch_disable_led(Watch *watch);
|
void watch_disable_led(Watch *watch);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user