display glass autodetection

This commit is contained in:
Joey Castillo
2025-03-08 13:43:11 -05:00
parent dce2187ec1
commit 138e91c6ef
10 changed files with 373 additions and 240 deletions

View File

@@ -29,75 +29,63 @@
#include <stdlib.h>
#include <math.h>
#ifdef USE_CUSTOM_LCD
static const uint32_t IndicatorSegments[] = {
SLCD_SEGID(0, 21), // WATCH_INDICATOR_SIGNAL
SLCD_SEGID(1, 21), // WATCH_INDICATOR_BELL
SLCD_SEGID(3, 21), // WATCH_INDICATOR_PM
SLCD_SEGID(2, 21), // WATCH_INDICATOR_24H
SLCD_SEGID(1, 0), // WATCH_INDICATOR_LAP
SLCD_SEGID(2, 0), // WATCH_INDICATOR_BATTERY
SLCD_SEGID(3, 0), // WATCH_INDICATOR_SLEEP
};
#else
static const uint32_t IndicatorSegments[] = {
SLCD_SEGID(0, 17), // WATCH_INDICATOR_SIGNAL
SLCD_SEGID(0, 16), // WATCH_INDICATOR_BELL
SLCD_SEGID(2, 17), // WATCH_INDICATOR_PM
SLCD_SEGID(2, 16), // WATCH_INDICATOR_24H
SLCD_SEGID(1, 10), // WATCH_INDICATOR_LAP
// Aliases for indicators unavailable on the original F-91W LCD
SLCD_SEGID(1, 10), // WATCH_INDICATOR_BATTERY (same as LAP)
SLCD_SEGID(4, 0), // WATCH_INDICATOR_SLEEP (does not exist, will set in SDATAL4 which is harmless)
};
#endif
uint32_t IndicatorSegments[7] = {0};
void watch_display_character(uint8_t character, uint8_t position) {
#ifdef USE_CUSTOM_LCD
if (character == 'R') character = 'r'; // We can't display uppercase R on this display.
else if (character == 'T' && position > 1 && position < 8) character = 't'; // lowercase t is the only option for these positions
#else
// special cases for positions 4 and 6
if (position == 4 || position == 6) {
if (character == '7') character = '&'; // "lowercase" 7
else if (character == 'A') character = 'a'; // A needs to be lowercase
else if (character == 'o') character = 'O'; // O needs to be uppercase
else if (character == 'L') character = '!'; // L needs to be in top half
else if (character == 'M' || character == 'm' || character == 'N') character = 'n'; // M and uppercase N need to be lowercase n
else if (character == 'c') character = 'C'; // C needs to be uppercase
else if (character == 'J') character = 'j'; // same
else if (character == 'v' || character == 'V' || character == 'U' || character == 'W' || character == 'w') character = 'u'; // bottom segment duplicated, so show in top half
if (watch_get_lcd_type() == WATCH_LCD_TYPE_CUSTOM) {
if (character == 'R') character = 'r'; // We can't display uppercase R on this display.
else if (character == 'T' && position > 1 && position < 8) character = 't'; // lowercase t is the only option for these positions
} else {
if (character == 'u') character = 'v'; // we can use the bottom segment; move to lower half
else if (character == 'j') character = 'J'; // same but just display a normal J
else if (character == '.') character = '_'; // we can use the bottom segment; make dot an underscore
// special cases for positions 4 and 6
if (position == 4 || position == 6) {
if (character == '7') character = '&'; // "lowercase" 7
else if (character == 'A') character = 'a'; // A needs to be lowercase
else if (character == 'o') character = 'O'; // O needs to be uppercase
else if (character == 'L') character = '!'; // L needs to be in top half
else if (character == 'M' || character == 'm' || character == 'N') character = 'n'; // M and uppercase N need to be lowercase n
else if (character == 'c') character = 'C'; // C needs to be uppercase
else if (character == 'J') character = 'j'; // same
else if (character == 'v' || character == 'V' || character == 'U' || character == 'W' || character == 'w') character = 'u'; // bottom segment duplicated, so show in top half
} else {
if (character == 'u') character = 'v'; // we can use the bottom segment; move to lower half
else if (character == 'j') character = 'J'; // same but just display a normal J
else if (character == '.') character = '_'; // we can use the bottom segment; make dot an underscore
}
if (position > 1) {
if (character == 'T') character = 't'; // uppercase T only works in positions 0 and 1
}
if (position == 1) {
if (character == 'a') character = 'A'; // A needs to be uppercase
else if (character == 'o') character = 'O'; // O needs to be uppercase
else if (character == 'i') character = 'l'; // I needs to be uppercase (use an l, it looks the same)
else if (character == 'n') character = 'N'; // N needs to be uppercase
else if (character == 'r') character = 'R'; // R needs to be uppercase
else if (character == 'd') character = 'D'; // D needs to be uppercase
else if (character == 'v' || character == 'V' || character == 'u') character = 'U'; // side segments shared, make uppercase
else if (character == 'b') character = 'B'; // B needs to be uppercase
else if (character == 'c') character = 'C'; // C needs to be uppercase
} else {
if (character == 'R') character = 'r'; // R needs to be lowercase almost everywhere
}
if (position == 0) {
watch_clear_pixel(0, 15); // clear funky ninth segment
} else {
if (character == 'I') character = 'l'; // uppercase I only works in position 0
}
}
if (position > 1) {
if (character == 'T') character = 't'; // uppercase T only works in positions 0 and 1
}
if (position == 1) {
if (character == 'a') character = 'A'; // A needs to be uppercase
else if (character == 'o') character = 'O'; // O needs to be uppercase
else if (character == 'i') character = 'l'; // I needs to be uppercase (use an l, it looks the same)
else if (character == 'n') character = 'N'; // N needs to be uppercase
else if (character == 'r') character = 'R'; // R needs to be uppercase
else if (character == 'd') character = 'D'; // D needs to be uppercase
else if (character == 'v' || character == 'V' || character == 'u') character = 'U'; // side segments shared, make uppercase
else if (character == 'b') character = 'B'; // B needs to be uppercase
else if (character == 'c') character = 'C'; // C needs to be uppercase
digit_mapping_t segmap;
uint8_t segdata;
/// TODO: This could be optimized by doing this check once and setting a pointer in watch_discover_lcd_type.
if (watch_get_lcd_type() == WATCH_LCD_TYPE_CUSTOM) {
segmap = Custom_LCD_Display_Mapping[position];
segdata = Custom_LCD_Character_Set[character - 0x20];
} else {
if (character == 'R') character = 'r'; // R needs to be lowercase almost everywhere
segmap = Classic_LCD_Display_Mapping[position];
segdata = Classic_LCD_Character_Set[character - 0x20];
}
if (position == 0) {
watch_clear_pixel(0, 15); // clear funky ninth segment
} else {
if (character == 'I') character = 'l'; // uppercase I only works in position 0
}
#endif
digit_mapping_t segmap = Watch_Display_Mapping[position];
uint8_t segdata = Watch_Character_Set[character - 0x20];
for (int i = 0; i < 8; i++) {
if (segmap.segment[i].value == segment_does_not_exist) {
@@ -126,8 +114,18 @@ void watch_display_character(uint8_t character, uint8_t position) {
void watch_display_character_lp_seconds(uint8_t character, uint8_t position) {
// Will only work for digits and for positions 8 and 9 - but less code & checks to reduce power consumption
digit_mapping_t segmap = Watch_Display_Mapping[position];
uint8_t segdata = Watch_Character_Set[character - 0x20];
digit_mapping_t segmap;
uint8_t segdata;
/// TODO: See optimization note above.
if (watch_get_lcd_type() == WATCH_LCD_TYPE_CUSTOM) {
segmap = Custom_LCD_Display_Mapping[position];
segdata = Custom_LCD_Character_Set[character - 0x20];
} else {
segmap = Classic_LCD_Display_Mapping[position];
segdata = Classic_LCD_Character_Set[character - 0x20];
}
for (int i = 0; i < 8; i++) {
if (segmap.segment[i].value == segment_does_not_exist) {
@@ -175,15 +173,15 @@ void watch_display_text(watch_position_t location, const char *string) {
break;
case WATCH_POSITION_BOTTOM:
{
#ifdef USE_CUSTOM_LCD
watch_clear_pixel(0, 22);
#endif
if (watch_get_lcd_type() == WATCH_LCD_TYPE_CUSTOM) {
watch_clear_pixel(0, 22);
}
int i = 0;
while (string[i] != 0) {
watch_display_character(string[i], 4 + i);
i++;
}
}
}
break;
case WATCH_POSITION_HOURS:
watch_display_character(string[0], 4);
@@ -209,67 +207,64 @@ void watch_display_text(watch_position_t location, const char *string) {
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
watch_display_string(string, 0);
#pragma GCC diagnostic pop
#ifdef USE_CUSTOM_LCD
watch_display_character(' ', 10);
#endif
if (watch_get_lcd_type() == WATCH_LCD_TYPE_CUSTOM) {
watch_display_character(' ', 10);
}
}
}
void watch_display_text_with_fallback(watch_position_t location, const char *string, const char *fallback) {
#ifdef USE_CUSTOM_LCD
(void)fallback;
switch (location) {
case WATCH_POSITION_TOP:
for (size_t i = 0; i < strlen(string); i++) {
if (i < 2) watch_display_character(string[i], i);
else if (i == 2) watch_display_character(string[i], 10);
else if (i < 5) watch_display_character(string[i], i - 1);
else break;
}
break;
case WATCH_POSITION_TOP_LEFT:
watch_display_character(string[0], 0);
if (string[1]) {
watch_display_character(string[1], 1);
} else {
return;
}
if (string[2]) {
// position 3 is at index 10 in the display mapping
watch_display_character(string[2], 10);
}
break;
case WATCH_POSITION_BOTTOM:
{
watch_clear_pixel(0, 22);
int i = 0;
int offset = 0;
size_t len = strlen(string);
if (len == 7 && string[0] == '1') {
watch_set_pixel(0, 22);
offset = 1;
i++;
}
while (string[i] != 0) {
if (4 + i - offset == 10) break;
watch_display_character(string[i], 4 + i - offset);
i++;
if (watch_get_lcd_type() == WATCH_LCD_TYPE_CUSTOM) {
switch (location) {
case WATCH_POSITION_TOP:
for (size_t i = 0; i < strlen(string); i++) {
if (i < 2) watch_display_character(string[i], i);
else if (i == 2) watch_display_character(string[i], 10);
else if (i < 5) watch_display_character(string[i], i - 1);
else break;
}
break;
case WATCH_POSITION_TOP_LEFT:
watch_display_character(string[0], 0);
if (string[1]) {
watch_display_character(string[1], 1);
} else {
return;
}
if (string[2]) {
// position 3 is at index 10 in the display mapping
watch_display_character(string[2], 10);
}
break;
case WATCH_POSITION_BOTTOM:
{
watch_clear_pixel(0, 22);
int i = 0;
int offset = 0;
size_t len = strlen(string);
if (len == 7 && string[0] == '1') {
watch_set_pixel(0, 22);
offset = 1;
i++;
}
while (string[i] != 0) {
if (4 + i - offset == 10) break;
watch_display_character(string[i], 4 + i - offset);
i++;
}
}
break;
case WATCH_POSITION_TOP_RIGHT:
case WATCH_POSITION_HOURS:
case WATCH_POSITION_MINUTES:
case WATCH_POSITION_SECONDS:
case WATCH_POSITION_FULL:
watch_display_text(location, string);
break;
}
break;
case WATCH_POSITION_TOP_RIGHT:
case WATCH_POSITION_HOURS:
case WATCH_POSITION_MINUTES:
case WATCH_POSITION_SECONDS:
case WATCH_POSITION_FULL:
watch_display_text(location, string);
break;
} else {
watch_display_text(location, fallback);
}
#else
(void)string;
watch_display_text(location, fallback);
#endif
}
void watch_display_float_with_best_effort(float value, const char *units) {
@@ -320,31 +315,31 @@ void watch_display_float_with_best_effort(float value, const char *units) {
}
void watch_set_colon(void) {
#ifdef USE_CUSTOM_LCD
watch_set_pixel(0, 0);
#else
watch_set_pixel(1, 16);
#endif
if (watch_get_lcd_type() == WATCH_LCD_TYPE_CUSTOM) {
watch_set_pixel(0, 0);
} else {
watch_set_pixel(1, 16);
}
}
void watch_clear_colon(void) {
#ifdef USE_CUSTOM_LCD
watch_clear_pixel(0, 0);
#else
watch_clear_pixel(1, 16);
#endif
if (watch_get_lcd_type() == WATCH_LCD_TYPE_CUSTOM) {
watch_clear_pixel(0, 0);
} else {
watch_clear_pixel(1, 16);
}
}
void watch_set_decimal_if_available(void) {
#ifdef USE_CUSTOM_LCD
watch_set_pixel(0, 14);
#endif
if (watch_get_lcd_type() == WATCH_LCD_TYPE_CUSTOM) {
watch_set_pixel(0, 14);
}
}
void watch_clear_decimal_if_available(void) {
#ifdef USE_CUSTOM_LCD
watch_clear_pixel(0, 14);
#endif
if (watch_get_lcd_type() == WATCH_LCD_TYPE_CUSTOM) {
watch_clear_pixel(0, 14);
}
}
void watch_set_indicator(watch_indicator_t indicator) {
@@ -371,3 +366,24 @@ void watch_clear_all_indicators(void) {
watch_clear_indicator(WATCH_INDICATOR_BATTERY);
watch_clear_indicator(WATCH_INDICATOR_SLEEP);
}
void _watch_update_indicator_segments(void) {
if (watch_get_lcd_type() == WATCH_LCD_TYPE_CUSTOM) {
IndicatorSegments[0] = SLCD_SEGID(0, 21); // WATCH_INDICATOR_SIGNAL
IndicatorSegments[1] = SLCD_SEGID(1, 21); // WATCH_INDICATOR_BELL
IndicatorSegments[2] = SLCD_SEGID(3, 21); // WATCH_INDICATOR_PM
IndicatorSegments[3] = SLCD_SEGID(2, 21); // WATCH_INDICATOR_24H
IndicatorSegments[4] = SLCD_SEGID(1, 0); // WATCH_INDICATOR_LAP
IndicatorSegments[5] = SLCD_SEGID(2, 0); // WATCH_INDICATOR_BATTERY
IndicatorSegments[6] = SLCD_SEGID(3, 0); // WATCH_INDICATOR_SLEEP
} else {
IndicatorSegments[0] = SLCD_SEGID(0, 17); // WATCH_INDICATOR_SIGNAL
IndicatorSegments[1] = SLCD_SEGID(0, 16); // WATCH_INDICATOR_BELL
IndicatorSegments[2] = SLCD_SEGID(2, 17); // WATCH_INDICATOR_PM
IndicatorSegments[3] = SLCD_SEGID(2, 16); // WATCH_INDICATOR_24H
IndicatorSegments[4] = SLCD_SEGID(1, 10); // WATCH_INDICATOR_LAP
// Aliases for indicators unavailable on the original F-91W LCD
IndicatorSegments[5] = SLCD_SEGID(1, 10); // WATCH_INDICATOR_BATTERY (same as LAP)
IndicatorSegments[6] = SLCD_SEGID(4, 0); // WATCH_INDICATOR_SLEEP (does not exist, will set in SDATAL4 which is harmless)
}
}

View File

@@ -42,11 +42,10 @@ typedef union digit_mapping_t {
uint64_t value;
} digit_mapping_t;
#ifdef USE_CUSTOM_LCD
// Custom extended LCD
// Character set is slightly different since we don't have to work around as much stuff.
static const uint8_t Watch_Character_Set[] =
static const uint8_t Custom_LCD_Character_Set[] =
{
0b00000000, // [space]
0b00000000, // ! (unused)
@@ -145,7 +144,7 @@ static const uint8_t Watch_Character_Set[] =
0b00000001, // ~
};
static const digit_mapping_t Watch_Display_Mapping[] = {
static const digit_mapping_t Custom_LCD_Display_Mapping[] = {
{
.segment = {
{ .address = { .com = 0, .seg = 19 } }, // 0A
@@ -281,10 +280,8 @@ static const digit_mapping_t Watch_Display_Mapping[] = {
},
};
#else
// Original famous Casio LCD
static const uint8_t Watch_Character_Set[] =
static const uint8_t Classic_LCD_Character_Set[] =
{
0b00000000, // [space]
0b01100000, // ! (L in the top half for positions 4 and 6)
@@ -383,7 +380,7 @@ static const uint8_t Watch_Character_Set[] =
0b00000001, // ~
};
static const digit_mapping_t Watch_Display_Mapping[] = {
static const digit_mapping_t Classic_LCD_Display_Mapping[] = {
// Positions 0 and 1 are the Weekday or Mode digits
{
.segment = {
@@ -508,7 +505,8 @@ static const digit_mapping_t Watch_Display_Mapping[] = {
},
},
};
#endif
void watch_display_character(uint8_t character, uint8_t position);
void watch_display_character_lp_seconds(uint8_t character, uint8_t position);
void _watch_update_indicator_segments(void);

View File

@@ -74,6 +74,25 @@ typedef enum {
WATCH_POSITION_SECONDS, ///< Display 2 characters in the seconds portion of the main line.
} watch_position_t;
/// an enum describing the possible LCD types
typedef enum {
WATCH_LCD_TYPE_UNKNOWN = 0, ///< Value at boot: unknown LCD
WATCH_LCD_TYPE_CLASSIC = 0b10101001, ///< The original famous F-91W LCD
WATCH_LCD_TYPE_CUSTOM = 0b01010110, ///< The custom Oddly Specific LCD
} watch_lcd_type_t;
/** @brief Determines the type of LCD being used by the watch.
* @return 0 for the original F-91W LCD, or 1 for the new custom LCD.
*/
void watch_discover_lcd_type(void);
/**
* @brief Gets the type of LCD being used by the watch.
* @return The type of LCD in use, or WATCH_LCD_TYPE_UNKNOWN if the display is unknown.
* The display type will be unknown if the watch is plugged into USB.
*/
watch_lcd_type_t watch_get_lcd_type(void);
/** @brief Enables the Segment LCD display.
* Call this before attempting to set pixels or display strings.
*/