-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLCD1in8.ts
executable file
·274 lines (247 loc) · 10.4 KB
/
LCD1in8.ts
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
let GUI_BACKGROUND_COLOR = LCD_COLOR.WHITE
let FONT_BACKGROUND_COLOR = LCD_COLOR.WHITE
let FONT_FOREGROUND_COLOR = LCD_COLOR.BLACK
//% weight=20 color=#436EEE icon="\uf108"
namespace LCD1IN8{
function Swop_AB(Point1: number, Point2: number): void {
let Temp = 0;
Temp = Point1;
Point1 = Point2;
Point2 = Temp;
}
//% blockId=LCD_Init
//% blockGap=8
//% block="LCD1IN8 Init"
//% shim=LCD1IN8::LCD_Init
//% weight=200
export function LCD_Init(): void {
return;
}
//% blockId=LCD_Clear
//% blockGap=8
//% block="Clear screen and cache"
//% shim=LCD1IN8::LCD_Clear
//% weight=195
export function LCD_Clear(): void {
return;
}
//% blockId=LCD_Filling
//% blockGap=8
//% block="Filling Color %Color"
//% shim=LCD1IN8::LCD_Filling
//% weight=194
export function LCD_Filling(Color: number): void {
return;
}
//% blockId=LCD_Display
//% blockGap=8
//% block="Send display data"
//% shim=LCD1IN8::LCD_Display
//% weight=190
export function LCD_Display(): void {
return;
}
//% blockId=LCD_DisplayWindows
//% blockGap=8
//% block="Show Windows display data |Xstart %Xstart|Ystart %Ystart|Xend %Xend|Yend %Yend "
//% shim=LCD1IN8::LCD_DisplayWindows
//% Xstart.min=1 Xstart.max=160 Ystart.min=1 Ystart.max=128
//% Xend.min=1 Xend.max=160 Yend.min=1 Yend.max=128
//% weight=189
export function LCD_DisplayWindows(Xstart: number, Ystart: number, Xend: number, Yend: number): void {
return;
}
//% blockId=Get_Color
//% blockGap=8
//% block="%Color"
//% weight=185
export function Get_Color(Color: LCD_COLOR): number {
return Color;
}
//% blockId=LCD_SetBL
//% blockGap=8
//% block="Set back light level %Lev"
//% Lev.min=0 Lev.max=10
//% shim=LCD1IN8::LCD_SetBL
//% weight=180
export function LCD_SetBL(Lev: number): void {
return;
}
//% blockId=DrawPoint
//% blockGap=8
//% block="Draw Point|x %x|y %y|Color %Color|Point Size %Dot"
//% x.min=1 x.max=160 y.min=1 y.max=128
//% Color.min=0 Color.max=65535
//% shim=LCD1IN8::DrawPoint
//% weight=150
export function DrawPoint(x: number, y: number, Color: number, Dot: DOT_PIXEL): void {
return;
}
//% blockId=DrawLine
//% blockGap=8
//% block="Draw Line|Xstart %Xstart|Ystart %Ystart|Xend %Xend|Yend %Yend|Color %Color|Line width %Line_width|Line Style %Line_Style"
//% Xstart.min=1 Xstart.max=160 Ystart.min=1 Ystart.max=128
//% Xend.min=1 Xend.max=160 Yend.min=1 Yend.max=128
//% Color.min=0 Color.max=65535
//% weight=140
export function DrawLine(Xstart: number, Ystart: number, Xend: number, Yend: number, Color: number, Line_width: DOT_PIXEL, Line_Style: LINE_STYLE): void {
if (Xstart > Xend)
Swop_AB(Xstart, Xend);
if (Ystart > Yend)
Swop_AB(Ystart, Yend);
let Xpoint = Xstart;
let Ypoint = Ystart;
let dx = Xend - Xstart >= 0 ? Xend - Xstart : Xstart - Xend;
let dy = Yend - Ystart <= 0 ? Yend - Ystart : Ystart - Yend;
// Increment direction, 1 is positive, -1 is counter;
let XAddway = Xstart < Xend ? 1 : -1;
let YAddway = Ystart < Yend ? 1 : -1;
//Cumulative error
let Esp = dx + dy;
let Line_Style_Temp = 0;
for (; ;) {
Line_Style_Temp++;
//Painted dotted line, 2 point is really virtual
if (Line_Style == LINE_STYLE.LINE_DOTTED && Line_Style_Temp % 3 == 0) {
DrawPoint(Xpoint, Ypoint, GUI_BACKGROUND_COLOR, Line_width);
Line_Style_Temp = 0;
} else {
DrawPoint(Xpoint, Ypoint, Color, Line_width);
}
if (2 * Esp >= dy) {
if (Xpoint == Xend) break;
Esp += dy
Xpoint += XAddway;
}
if (2 * Esp <= dx) {
if (Ypoint == Yend) break;
Esp += dx;
Ypoint += YAddway;
}
}
}
//% blockId=DrawRectangle
//% blockGap=8
//% block="Draw Rectangle|Xstart2 %Xstart2|Ystart2 %Ystart2|Xend2 %Xend2|Yend2 %Yend2|Color %Color|Filled %Filled |Line width %Dot_Pixel"
//% Xstart2.min=1 Xstart2.max=160 Ystart2.min=1 Ystart2.max=128
//% Xend2.min=1 Xend2.max=160 Yend2.min=1 Yend2.max=128
//% Color.min=0 Color.max=65535
//% weight=130
export function DrawRectangle(Xstart2: number, Ystart2: number, Xend2: number, Yend2: number, Color: number, Filled: DRAW_FILL, Dot_Pixel: DOT_PIXEL): void {
if (Xstart2 > Xend2)
Swop_AB(Xstart2, Xend2);
if (Ystart2 > Yend2)
Swop_AB(Ystart2, Yend2);
let Ypoint = 0;
if (Filled) {
for(Ypoint = Ystart2; Ypoint < Yend2; Ypoint++) {
DrawLine(Xstart2, Ypoint, Xend2, Ypoint, Color, Dot_Pixel, LINE_STYLE.LINE_SOLID);
}
} else {
DrawLine(Xstart2, Ystart2, Xend2, Ystart2, Color, Dot_Pixel, LINE_STYLE.LINE_SOLID);
DrawLine(Xstart2, Ystart2, Xstart2, Yend2, Color, Dot_Pixel, LINE_STYLE.LINE_SOLID);
DrawLine(Xend2, Yend2, Xend2, Ystart2, Color, Dot_Pixel, LINE_STYLE.LINE_SOLID);
DrawLine(Xend2, Yend2, Xstart2, Yend2, Color, Dot_Pixel, LINE_STYLE.LINE_SOLID);
}
}
//% blockId=DrawCircle
//% blockGap=8
//% block="Draw Circle|X_Center %X_Center|Y_Center %Y_Center|Radius %Radius|Color %Color|Filled %Draw_Fill|Line width %Dot_Pixel"
//% X_Center.min=1 X_Center.max=160 Y_Center.min=1 Y_Center.max=128
//% Radius.min=0 Radius.max=160
//% Color.min=0 Color.max=65535
//% weight=120
export function DrawCircle(X_Center: number, Y_Center: number, Radius: number, Color: number, Draw_Fill: DRAW_FILL, Dot_Pixel: DOT_PIXEL): void {
//Draw a circle from(0, R) as a starting point
let XCurrent = 0;
let YCurrent = Radius;
//Cumulative error,judge the next point of the logo
let Esp = 3 - (Radius << 1);
let sCountY = 0;
if (Draw_Fill == DRAW_FILL.DRAW_FULL) {//DrawPoint(Xpoint, Ypoint, GUI_BACKGROUND_COLOR, Line_width);
while (XCurrent <= YCurrent) { //Realistic circles
for (sCountY = XCurrent; sCountY <= YCurrent; sCountY++) {
DrawPoint(X_Center + XCurrent, Y_Center + sCountY, Color, DOT_PIXEL.DOT_PIXEL_1); //1
DrawPoint(X_Center - XCurrent, Y_Center + sCountY, Color, DOT_PIXEL.DOT_PIXEL_1); //2
DrawPoint(X_Center - sCountY, Y_Center + XCurrent, Color, DOT_PIXEL.DOT_PIXEL_1); //3
DrawPoint(X_Center - sCountY, Y_Center - XCurrent, Color, DOT_PIXEL.DOT_PIXEL_1); //4
DrawPoint(X_Center - XCurrent, Y_Center - sCountY, Color, DOT_PIXEL.DOT_PIXEL_1); //5
DrawPoint(X_Center + XCurrent, Y_Center - sCountY, Color, DOT_PIXEL.DOT_PIXEL_1); //6
DrawPoint(X_Center + sCountY, Y_Center - XCurrent, Color, DOT_PIXEL.DOT_PIXEL_1); //7
DrawPoint(X_Center + sCountY, Y_Center + XCurrent, Color, DOT_PIXEL.DOT_PIXEL_1);
}
if (Esp < 0)
Esp += 4 * XCurrent + 6;
else {
Esp += 10 + 4 * (XCurrent - YCurrent);
YCurrent--;
}
XCurrent++;
}
} else { //Draw a hollow circle
while (XCurrent <= YCurrent) {
DrawPoint(X_Center + XCurrent, Y_Center + YCurrent, Color, Dot_Pixel); //1
DrawPoint(X_Center - XCurrent, Y_Center + YCurrent, Color, Dot_Pixel); //2
DrawPoint(X_Center - YCurrent, Y_Center + XCurrent, Color, Dot_Pixel); //3
DrawPoint(X_Center - YCurrent, Y_Center - XCurrent, Color, Dot_Pixel); //4
DrawPoint(X_Center - XCurrent, Y_Center - YCurrent, Color, Dot_Pixel); //5
DrawPoint(X_Center + XCurrent, Y_Center - YCurrent, Color, Dot_Pixel); //6
DrawPoint(X_Center + YCurrent, Y_Center - XCurrent, Color, Dot_Pixel); //7
DrawPoint(X_Center + YCurrent, Y_Center + XCurrent, Color, Dot_Pixel); //0
if (Esp < 0)
Esp += 4 * XCurrent + 6;
else {
Esp += 10 + 4 * (XCurrent - YCurrent);
YCurrent--;
}
XCurrent++;
}
}
}
//% shim=LCD1IN8::DisChar_1207
function DisChar_1207(Xchar: number, Ychar: number, Char_Offset: number, Color: number): void {
return;
}
//% blockId=DisString
//% blockGap=8
//% block="Show String|X %Xchar|Y %Ychar|char %ch|Color %Color"
//% Xchar.min=1 Xchar.max=160 Ychar.min=1 Ychar.max=128
//% Color.min=0 Color.max=65535
//% weight=100
export function DisString(Xchar: number, Ychar: number, ch: string, Color: number): void {
let Xpoint = Xchar;
let Ypoint = Ychar;
let Font_Height = 12;
let Font_Width = 7;
let ch_len = ch.length;
let i = 0;
for(i = 0; i < ch_len; i++) {
let ch_asicc = ch.charCodeAt(i) - 32;//NULL = 32
let Char_Offset = ch_asicc * Font_Height;
// let Char_Offset = ch_asicc * Font_Height *(Font_Width/8 +(Font_Width%8?1:0));
if((Xpoint + Font_Width) > 160) {
Xpoint = Xchar;
Ypoint += Font_Height;
}
// If the Y direction is full, reposition to(Xstart, Ystart)
if((Ypoint + Font_Height) > 128) {
Xpoint = Xchar;
Ypoint = Ychar;
}
DisChar_1207(Xpoint, Ypoint, Char_Offset, Color);
//The next word of the abscissa increases the font of the broadband
Xpoint += Font_Width;
}
}
//% blockId=DisNumber
//% blockGap=8
//% block="Show number|X %Xnum|Y %Ynum|number %num|Color %Color"
//% Xnum.min=1 Xnum.max=160 Ynum.min=1 Ynum.max=128
//% Color.min=0 Color.max=65535
//% weight=100
export function DisNumber(Xnum: number, Ynum: number, num: number, Color: number): void {
let Xpoint = Xnum;
let Ypoint = Ynum;
DisString(Xnum, Ynum, num + "", Color);
}
}