forked from jmparatte/jm_LiquidCrystal_I2C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjm_LiquidCrystal_I2C.cpp
230 lines (179 loc) · 5.31 KB
/
jm_LiquidCrystal_I2C.cpp
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include <jm_LiquidCrystal_I2C.h>
// -----------------------------------------------------------------------------
int jm_LiquidCrystal_I2C::buf_u32( uint32_t u32 )
{
len = snprintf( buf, 12, "%lu", u32 );
return len;
}
int jm_LiquidCrystal_I2C::buf_s32( int32_t s32 )
{
if (s32)
len = snprintf( buf, 12, "%+li", s32 );
else
len = snprintf( buf, 12, "0" );
return len;
}
int jm_LiquidCrystal_I2C::buf_u32f( uint32_t u32, int nfrac )
{
buf_u32(u32);
if (len > nfrac) {
memmove( &buf[len-nfrac+1], &buf[len-nfrac], nfrac );
len++;
} else {
memmove( &buf[nfrac+1+1-len], &buf[0], len );
memset( &buf[0], '0', nfrac+1+1-len );
len = nfrac+1+1;
}
buf[len-nfrac-1] = '.';
return len;
}
int jm_LiquidCrystal_I2C::buf_s32f( int32_t value, int nfrac )
{
buf_u32f( (value<0?-value:+value), nfrac );
if (value) {
memmove( &buf[1], &buf[0], len );
buf[0] = sign(value)?'+':'-';
len++;
}
return len;
}
int jm_LiquidCrystal_I2C::buf_rjprint( int num ) // right justification print
{
return ( print_spaces( (num-len) >= 0 ? (num-len) : 0 ) + write( buf, len ) );
}
// -----------------------------------------------------------------------------
jm_LiquidCrystal_I2C::jm_LiquidCrystal_I2C() : fm_LiquidCrystal_I2C::fm_LiquidCrystal_I2C(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE)
{
}
// -----------------------------------------------------------------------------
void jm_LiquidCrystal_I2C::begin()
{
fm_LiquidCrystal_I2C::begin(20, 4, LCD_5x8DOTS);
}
void jm_LiquidCrystal_I2C::clr_screen()
{
clear();
}
void jm_LiquidCrystal_I2C::set_cursor( int col, int row )
{
setCursor(col, row);
}
// -----------------------------------------------------------------------------
int jm_LiquidCrystal_I2C::print_space()
{
return print(' ');
}
int jm_LiquidCrystal_I2C::print_spaces( int num )
{
for (int i=0; i<num; i++) print_space();
return num;
}
// -----------------------------------------------------------------------------
int jm_LiquidCrystal_I2C::print_sgn( int sgn )
{
return print( (sgn==+1) ? '+' : (sgn==-1) ? '-' : ' ' );
}
int jm_LiquidCrystal_I2C::print_sign( bool sign )
{
return print( sign ? '+' : '-' );
}
// -----------------------------------------------------------------------------
int jm_LiquidCrystal_I2C::print_u8( uint8_t value )
{
return print_u32( (uint32_t)value, 3 );
}
int jm_LiquidCrystal_I2C::print_u8( uint8_t value, int nprint )
{
return print_u32( (uint32_t)value, nprint );
}
// -----------------------------------------------------------------------------
int jm_LiquidCrystal_I2C::print_s8( int8_t value )
{
return print_s32( (int32_t)value, 3+1 );
}
int jm_LiquidCrystal_I2C::print_s8( int8_t value, int nprint )
{
return print_s32( (int32_t)value, nprint );
}
// -----------------------------------------------------------------------------
int jm_LiquidCrystal_I2C::print_u16( uint16_t value )
{
return print_u32( (uint32_t)value, 5 );
}
int jm_LiquidCrystal_I2C::print_u16( uint16_t value, int nprint )
{
return print_u32( (uint32_t)value, nprint );
}
// -----------------------------------------------------------------------------
int jm_LiquidCrystal_I2C::print_s16( int16_t value )
{
return print_s32( (int32_t)value, 5+1 );
}
int jm_LiquidCrystal_I2C::print_s16( int16_t value, int nprint )
{
return print_s32( (int32_t)value, nprint );
}
// -----------------------------------------------------------------------------
int jm_LiquidCrystal_I2C::print_u32( uint32_t value )
{
return print_u32( value, 10 );
}
int jm_LiquidCrystal_I2C::print_u32( uint32_t value, int nprint )
{
buf_u32( value );
return buf_rjprint( nprint );
}
// -----------------------------------------------------------------------------
int jm_LiquidCrystal_I2C::print_s32( int32_t value )
{
return print_s32( value, 10+1 );
}
int jm_LiquidCrystal_I2C::print_s32( int32_t value, int nprint )
{
buf_s32( value );
return buf_rjprint( nprint );
}
// -----------------------------------------------------------------------------
int jm_LiquidCrystal_I2C::print_h4( uint8_t value )
{
value &= 0x0F;
return print( value>=10 ? (char)('A'+value-10) : (char)('0'+value) );
}
int jm_LiquidCrystal_I2C::print_h8( uint8_t value )
{
return print_h4( value>>4 ) + print_h4( value>>0 );
}
int jm_LiquidCrystal_I2C::print_h16( uint16_t value )
{
return print_h8( (uint8_t)(value>>8) ) + print_h8( (uint8_t)(value>>0) );
}
int jm_LiquidCrystal_I2C::print_h24( uint32_t value )
{
return print_h8( (uint8_t)(value>>16) ) + print_h16( (uint16_t)(value>>0) );
}
int jm_LiquidCrystal_I2C::print_h32( uint32_t value )
{
return print_h16( (uint16_t)(value>>16) ) + print_h16( (uint16_t)(value>>0) );
}
// -----------------------------------------------------------------------------
int jm_LiquidCrystal_I2C::print_u32f( uint32_t value, int nfrac )
{
return print_u32f( value, nfrac, 10+1 );
}
int jm_LiquidCrystal_I2C::print_u32f( uint32_t value, int nfrac, int nprint )
{
buf_u32f( value, nfrac );
return buf_rjprint( nprint );
}
// -----------------------------------------------------------------------------
int jm_LiquidCrystal_I2C::print_s32f( int32_t value, int nfrac )
{
return print_s32f( value, nfrac, 10+1+1 );
}
int jm_LiquidCrystal_I2C::print_s32f( int32_t value, int nfrac, int nprint )
{
buf_s32f( value, nfrac );
return buf_rjprint( nprint );
}
// -----------------------------------------------------------------------------
// END.