-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdigits.c
127 lines (94 loc) · 2.66 KB
/
digits.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* digits.c
*
* Модуль для отрисовки цифр часов и анимации переходов
*
* Author: Погребняк Дмитрий (Pogrebnyak Dmitry, http://aterlux.ru/)
*/
#include "digits.h"
#include "digits_font.h"
#include "display.h"
#include <avr/pgmspace.h>
static uint8_t digits_font;
void digits_select_font (uint8_t font)
{
if (font < DIGITS_FONTS_COUNT)
{
digits_font = font;
}
}
uint8_t digits_current_font ()
{
return digits_font;
}
uint8_t digit_output (uint8_t d, uint8_t x)
{
if (x >= DISPLAY_Width)
{
return 1;
}
// if (d >= DIGITS_SYMBOLS_PER_FONT)
// {
// return display_fill_region (0, x, DIGITS_BLOCKS_PER_SYMBOL, DIGITS_COLS_PER_BLOCK, 0, 0);
// }
PGM_VOID_P pblocks = &digits_fonts[digits_font][d];
uint8_t w = (x > (DISPLAY_Width - DIGITS_COLS_PER_BLOCK)) ? (DISPLAY_Width - x) : DIGITS_COLS_PER_BLOCK;
for (uint8_t y = 0; y < DIGITS_BLOCKS_PER_SYMBOL; ++y)
{
PGM_VOID_P pdata = &digits_datablocks[pgm_read_byte(pblocks++)];
uint8_t offsetY = y << 3; // y * 8
for (uint8_t i = 0; i < w; ++i)
{
uint8_t col = pgm_read_byte(pdata++);
uint8_t offsetX = x + i;
for(uint8_t row = 0; row < 8; ++row)
{
display_DrawPixel (offsetX, offsetY + row, col & 1);
col >>= 1;
}
}
}
return 1;
}
uint8_t digit_output_inv (uint8_t d, uint8_t x)
{
if (x >= DISPLAY_Width)
{
return 1;
}
// if (d >= DIGITS_SYMBOLS_PER_FONT)
// {
// return display_fill_region (0, x, DIGITS_BLOCKS_PER_SYMBOL, DIGITS_COLS_PER_BLOCK, 0, 0);
// }
PGM_VOID_P pblocks = &digits_fonts[digits_font][d];
uint8_t w = (x > (DISPLAY_Width - DIGITS_COLS_PER_BLOCK)) ? (DISPLAY_Width - x) : DIGITS_COLS_PER_BLOCK;
for (uint8_t y = 0; y < DIGITS_BLOCKS_PER_SYMBOL; ++y)
{
PGM_VOID_P pdata = &digits_datablocks[pgm_read_byte(pblocks++)];
uint8_t offsetY = y << 3; // y * 8
for (uint8_t i = 0; i < w; ++i)
{
uint8_t col = ~(pgm_read_byte(pdata++));
uint8_t offsetX = x + i;
for(uint8_t row = 0; row < 8; ++row)
{
display_DrawPixel (offsetX, offsetY + row, col & 1);
col >>= 1;
}
}
}
return 1;
}
uint8_t two_digits (uint8_t num, uint8_t* p_buf, uint8_t leading_zero)
{
uint8_t r = num / 100;
uint8_t d = (num % 100) / 10;
if ((d == 0) && !leading_zero)
{
d = DIGIT_EMPTY;
}
num %= 10;
*(p_buf++) = d;
*p_buf = num;
return r;
}