From ed32a6d2fd0c2544ef753aa9e827660e56ff7d59 Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Sat, 24 Mar 2018 18:00:38 +0100 Subject: [PATCH] Add peak indicators to the bar graph --- hcs12ss59t.c | 38 +++++++++++++++++++++++++++++++++++++- hcs12ss59t.h | 3 ++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/hcs12ss59t.c b/hcs12ss59t.c index f1c2e6e..94614b5 100644 --- a/hcs12ss59t.c +++ b/hcs12ss59t.c @@ -168,7 +168,24 @@ const char hcs12ss59t_bar_styles[2][5][2] = { {0x40, 0x20}, // 2 {0x40, 0x30}, // 3 {0x40, 0x38} // 4 + } +}; + +const char hcs12ss59t_tick_styles[2][5][2] = { + { + {0x80, 0x00}, // 1 + {0x00, 0x80}, // 2 + {0x00, 0x01}, // 3 + {0x00, 0x02}, // 4 + {0x04, 0x00} // 5 }, + { + {0x40, 0x00}, // 1 + {0x00, 0x20}, // 2 + {0x00, 0x10}, // 3 + {0x00, 0x08}, // 4 + {0x08, 0x00} // 5 + } }; /** @@ -176,7 +193,8 @@ const char hcs12ss59t_bar_styles[2][5][2] = { * @param top Top progress bar value. 0 - HCS12SS59T_NUMDIGITS * 5 * @param bottom Bottom progress bar value. 0 - HCS12SS59T_NUMDIGITS * 5 */ -void hcs12ss59t_set_progress(int top, int bottom) +void hcs12ss59t_set_progress_peak(uint8_t top, uint8_t bottom, + uint8_t peak_top, uint8_t peak_bottom) { char charconf[HCS12SS59T_NUMDIGITS * 2]; int full; @@ -189,12 +207,30 @@ void hcs12ss59t_set_progress(int top, int bottom) top = HCS12SS59T_NUMDIGITS * 5; if (bottom > HCS12SS59T_NUMDIGITS * 5) bottom = HCS12SS59T_NUMDIGITS * 5; + if (peak_top > HCS12SS59T_NUMDIGITS * 5) + peak_top = HCS12SS59T_NUMDIGITS * 5; + if (peak_bottom > HCS12SS59T_NUMDIGITS * 5) + peak_bottom = HCS12SS59T_NUMDIGITS * 5; // Clear memory for (ptr = charconf; ptr < charconf + HCS12SS59T_NUMDIGITS * 2; ++ptr) { *ptr = 0; } + // Calculate ticks + if (peak_top != 0) { + peak_top--; + ptr = charconf + ((peak_top / 5) * 2); + *(ptr++) |= hcs12ss59t_tick_styles[0][peak_top % 5][0]; + *ptr |= hcs12ss59t_tick_styles[0][peak_top % 5][1]; + } + if (peak_bottom != 0) { + peak_bottom--; + ptr = charconf + ((peak_bottom / 5) * 2); + *(ptr++) |= hcs12ss59t_tick_styles[1][peak_bottom % 5][0]; + *ptr |= hcs12ss59t_tick_styles[1][peak_bottom % 5][1]; + } + // Calculate top memory for (row = 0; row < 2; ++row) { if (row == 0) { diff --git a/hcs12ss59t.h b/hcs12ss59t.h index 0e5a4b7..53b4ddb 100644 --- a/hcs12ss59t.h +++ b/hcs12ss59t.h @@ -53,7 +53,8 @@ void hcs12ss59t_set_buffer(char *data); void hcs12ss59t_set_brightness(char brightness); void hcs12ss59t_set_lights(char lights); void hcs12ss59t_set_character(int addr, char *data, int nchar); -void hcs12ss59t_set_progress(int top, int bottom); +void hcs12ss59t_set_progress_peak(uint8_t top, uint8_t bottom, uint8_t peak_top, uint8_t peak_bottom); +#define hcs12ss59t_set_progress(top,bottom) hcs12ss59t_set_progress_peak(top, bottom, 0, 0) void hcs12ss59t_en_progress(); /* Low level functions */