-
Notifications
You must be signed in to change notification settings - Fork 1
/
FutabaMT.cpp
373 lines (350 loc) · 12 KB
/
FutabaMT.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
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#include "FutabaMT.h"
#define DODELAY __asm__("nop\n\t""nop\n\t")
//*************************************************************
uint8_t _znakHorni, _znakDolni;
byte charSetLength;
byte firstChar;
byte _znak7digit1, _znak7digit2 ;
byte _x,_temp;
char _numberDisp [7];
unsigned char _u,_iii,_ww,_pocitadlo, _pocitadlo2,_ee,_eex;
FutabaMT::FutabaMT()
{
charSetLength=43;
firstChar=48;
};
//----------------------------------------------------------------------------
void FutabaMT::Write (unsigned char dat)
{
for (_iii=0;_iii<8;_iii++)
{
PTClkLow;
if(dat & 0x01)
PTDinHigh;
else
PTDinLow;
dat >>= 1;
PTClkHigh;
DODELAY;
}
}
//----------------------------------------------------------------------------
void FutabaMT::Cmd (unsigned char cmd)
{
PTStbLow;
//DODELAY;
_x=cmd;
for (_iii=0;_iii<8;_iii++)
{
PTClkLow;
if(_x & 0x01)
PTDinHigh;
else
PTDinLow;
_x >>= 1;
PTClkHigh;
DODELAY;
}
PTStbHigh;
DODELAY;
}
//----------------------------------------------------------------------------
void FutabaMT::SetMem(unsigned char dat)
{
//------------rewritten cmd (_x)---------
PTStbLow;
_x=CMD2_DSC_WDDM_INC;
for (_iii=0;_iii<8;_iii++)
{
PTClkLow;
if(_x & 0x01)
PTDinHigh;
else
PTDinLow;
_x >>= 1;
PTClkHigh;
DODELAY;
}
PTStbHigh;
DODELAY;
//-----------
PTStbLow;
Write(CMD3_ASC);
for (_pocitadlo=0;_pocitadlo<=0x2f;_pocitadlo++)
{
Write(dat);
}
PTStbHigh;
DODELAY;
}
//----------------------------------------------------------------------------
void FutabaMT::Write3Digit(unsigned char digit, unsigned char s1,unsigned char s2,unsigned char s3)
{
Cmd( CMD2_DSC_WDDM_INC);
PTStbLow;
Write( CMD3_ASC | (digit * 3));
Write( s1); //SG1-SG4 SG5-SG8
Write( s2); //SG9-SG12 SG13-SG16
Write( s3 & 0x0f); //SG17-SG20
PTStbHigh;
DODELAY;
}
//----------------------------------------------------------------------------
void FutabaMT::Write2Digit(unsigned char digit, unsigned char s1,unsigned char s2)
{
Cmd( CMD2_DSC_WDDM_INC);
PTStbLow;
Write( CMD3_ASC | (digit * 3));
Write( s1); //SG1-SG4 SG5-SG8
Write( s2); //SG9-SG12 SG13-SG16
// Write( s3 & 0x0f); //SG17-SG20
PTStbHigh;
DODELAY;
}
//----------------------------------------------------------------------------
void FutabaMT::WriteADigit(unsigned char digit, unsigned char s1)
{
Cmd( CMD2_DSC_WDDM_INC);
PTStbLow;
Write( CMD3_ASC | (digit * 3 ));
Write( s1); //SG1-SG4 SG5-SG8
//Write( s2); //SG9-SG12 SG13-SG16
//Write( s3 & 0x0f); //SG17-SG20
PTStbHigh;
DODELAY;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void FutabaMT::WriteBDigit(unsigned char digit, unsigned char s2)
{
Cmd( CMD2_DSC_WDDM_INC);
PTStbLow;
Write( CMD3_ASC | (digit * 3 + 1));
//Write( s1); //SG1-SG4 SG5-SG8
Write( s2); //SG9-SG12 SG13-SG16
//Write( s3 & 0x0f); //SG17-SG20
PTStbHigh;
DODELAY;
}
//----------------------------------------------------------------------------
void FutabaMT::WriteCDigit(unsigned char digit, unsigned char s3)
{
Cmd( CMD2_DSC_WDDM_INC);
PTStbLow;
Write( CMD3_ASC | (digit * 3 + 2));
//Write( s1); //SG1-SG4 SG5-SG8
//Write( s2); //SG9-SG12 SG13-SG16
Write( s3 & 0x0f); //SG17-SG20
PTStbHigh;
DODELAY;
}
//----------------------------------------------------------------------------
void FutabaMT::WriteDisplayRam(unsigned char addr, unsigned char *data, unsigned char len)
{
Cmd( CMD2_DSC_WDDM_INC);
PTStbLow;
Write( CMD3_ASC | addr);
while(len--)
{
Write( *data++);
}
PTStbHigh;
DODELAY;
}
//----------------------------------------------------------------------------
void FutabaMT::Init()
{
pinMode(DIN_PIN, OUTPUT);
pinMode(CLK_PIN, OUTPUT);
pinMode(STB_PIN, OUTPUT);
pinMode(EN_PIN, OUTPUT);
digitalWrite(EN_PIN, HIGH); // enable the HV+Filament
delay(200);
PTStbHigh;
PTClkHigh;
PTDinHigh;
DODELAY;
SetMem(0x00);
Cmd(CMD1_DMSC_11_17);
Cmd(CMD3_DCC_04_16);
}
//----------------------------------------------------------------------------
void FutabaMT::PrintChar(unsigned char aaa, unsigned char bbb)
{
_temp=bbb-firstChar;
_znakHorni = _charSetUpper[_temp];
_znakDolni = _charSetLower[_temp];
Write2Digit(aaa,_znakHorni, _znakDolni);
}
//----------------------------------------------------------------------------
void FutabaMT::ClearNumDisp()
{
Write2Digit(5,0,0);
Write2Digit(6,0,0);
Write2Digit(7,0,0);
}
//----------------------------------------------------------------------------
void FutabaMT::PrintTxt5(const char *data)
{
const char *_p;
_p = data;
_pocitadlo=0;
while (*_p && _pocitadlo<=4) {
if (*_p==32) {
PrintChar(4-_pocitadlo,60);
_p++;_pocitadlo++;} // replace SPACE with some empty character
else {
PrintChar(4-_pocitadlo,*_p);
_p++;_pocitadlo++;
}
}
// fill empty spaces to the end of displayed txt
if (_pocitadlo<=4) {
for (_ee=_pocitadlo; _ee<=4; _ee++) {
PrintChar(4-_ee,60);
}
}
}
//----------------------------------------------------------------------------
void FutabaMT::DiscRotate(unsigned int pocet) // animace kolecka tam a zpet
{
for (_pocitadlo=1; _pocitadlo<=pocet; _pocitadlo++)
{ _temp=1;
for (_ww=0; _ww<=0x7; _ww++)
{ WriteADigit(8,_temp);
_temp=_temp << 1; _temp=_temp+1; delay(70);
}
_temp=255;
for (_ww=0; _ww<=0x7; _ww++)
{ WriteADigit(8,_temp);
_temp=_temp >> 1; delay(70);
}
WriteADigit(8,0x00);
delay(70);
}
}
//----------------------------------------------------------------------------
void FutabaMT::DiscValue(unsigned char pocet) // light one segment of circle
{
WriteADigit(8,pocet);
}
//----------------------------------------------------------------------------
void FutabaMT::StatusLeds(unsigned char pocet) // light some segments DVD/REC/HDD/REC etc.
{
WriteBDigit(8,pocet);
}
//----------------------------------------------------------------------------
void FutabaMT::Netwrk(unsigned char s1,unsigned char s2) // light some segments of Network circle
{
Write2Digit(10,s1,s2);
}
// -----------------------------------------------------------------------------
void FutabaMT::Dots(unsigned char s1,unsigned char s2) // light some segments of box with dots - 8+8 bits
{
Write2Digit(9,s1,s2);
}
// -----------------------------------------------------------------------------
void FutabaMT::DiscBar(unsigned int pocet) // light bar graph in circle
{
_temp=0;
if (pocet > 0 && pocet < 8) {
for (_ww=1; _ww<=pocet; _ww++)
{
_temp=_temp << 1; _temp=_temp+1;
}
WriteADigit(8,_temp);
}
}
//----------------------------------------------------------------------------
void FutabaMT::PrintNumbers(const char *data, bool colons)
{
const char *_p;
_p = data;
_pocitadlo2=0;
for (_ee=0; _ee<=6; _ee++) // copy input const string to normal array to allow manipulations
{
_numberDisp[_ee]=_p[_ee];
if(_numberDisp[_ee]==0 && _pocitadlo2==0) {_pocitadlo2=_ee;}
}
// trying to fomat digits to right
for (_ee=0; _ee<=(5-_pocitadlo2); _ee++)
{
for (_eex=0; _eex<5; _eex++) //rotate char 1 step right and fill zero from left
{
_numberDisp[5-_eex]=_numberDisp[5-_eex-1];
}
_numberDisp[0]=48;
} //now decode 6 digits into 3 separate weird Futaba registers, it is a mess....has to be done manually
_znak7digit1 = _charSetNumber[_numberDisp[0]-firstChar];
_znak7digit2 = _charSetNumber[_numberDisp[5]-firstChar];
Write2Digit(5,_znak7digit1, _znak7digit2);
_znak7digit1 = _charSetNumber[_numberDisp[1]-firstChar];
_znak7digit2 = _charSetNumber[_numberDisp[2]-firstChar];
if (colons) {_znak7digit1=_znak7digit1+128; _znak7digit2=_znak7digit2+128; } // if flag of lighting colons is TRUE
Write2Digit(7,_znak7digit1,_znak7digit2);
_znak7digit1 = _charSetNumber[_numberDisp[3]-firstChar];
_znak7digit2 = _charSetNumber[_numberDisp[4]-firstChar];
if (colons) {_znak7digit1=_znak7digit1+128; _znak7digit2=_znak7digit2+128; } // if flag of lighting colons is TRUE
Write2Digit(6,_znak7digit1, _znak7digit2);
}
//----------------------------------------------------------------------------
void FutabaMT::On_Auto()
{ WriteCDigit(6,1); }
//----------------------------------------------------------------------------
void FutabaMT::Off_Auto()
{ WriteCDigit(6,0); }
//----------------------------------------------------------------------------
void FutabaMT::On_Epg()
{ WriteCDigit(7,1); }
//----------------------------------------------------------------------------
void FutabaMT::Off_Epg()
{ WriteCDigit(7,0); }
//----------------------------------------------------------------------------
void FutabaMT::On_Trans()
{ WriteCDigit(5,1); }
//----------------------------------------------------------------------------
void FutabaMT::Off_Trans()
{ WriteCDigit(5,0); }
//----------------------------------------------------------------------------
void FutabaMT::On_Mail()
{ WriteCDigit(10,1); }
//----------------------------------------------------------------------------
void FutabaMT::Off_Mail()
{ WriteCDigit(10,0); }
//----------------------------------------------------------------------------
void FutabaMT::On_Rate()
{ WriteCDigit(3,1); }
//----------------------------------------------------------------------------
void FutabaMT::Off_Rate()
{ WriteCDigit(3,0); }
//----------------------------------------------------------------------------
void FutabaMT::On_Title()
{ WriteCDigit(4,1); }
//----------------------------------------------------------------------------
void FutabaMT::Off_Title()
{ WriteCDigit(4,0); }
//----------------------------------------------------------------------------
void FutabaMT::On_Chp()
{ WriteCDigit(2,1); }
//----------------------------------------------------------------------------
void FutabaMT::Off_Chp()
{ WriteCDigit(2,0); }
//----------------------------------------------------------------------------
void FutabaMT::On_Trk()
{ WriteCDigit(1,1); }
//----------------------------------------------------------------------------
void FutabaMT::Off_Trk()
{ WriteCDigit(1,0); }
//----------------------------------------------------------------------------
void FutabaMT::On_Ch()
{ WriteCDigit(0,1); }
//----------------------------------------------------------------------------
void FutabaMT::Off_Ch()
{ WriteCDigit(0,0); }
//----------------------------------------------------------------------------
void FutabaMT::On_Usb()
{ WriteCDigit(9,1); }
//----------------------------------------------------------------------------
void FutabaMT::Off_Usb()
{ WriteCDigit(9,0); }
//----------------------------------------------------------------------------