@@ -10,6 +10,7 @@ import 'package:magic_epaper_app/util/epd/epd.dart';
1010import 'package:app_settings/app_settings.dart' ;
1111import 'package:magic_epaper_app/util/magic_epaper_firmware.dart' ;
1212import 'package:magic_epaper_app/util/nfc_settings_launcher.dart' ;
13+ import 'epd/driver/waveform.dart' ;
1314
1415class Protocol {
1516 final fw = MagicEpaperFirmware ();
@@ -45,14 +46,15 @@ class Protocol {
4546 Future <Uint8List > enableEnergyHarvesting (Uint8List tagId) async {
4647 return await _writeDynCfg (tagId, 0x02 , 0x01 );
4748 }
48-
49+
4950 // `pt_scan = true` means don't touch the outside pixels while refreshing
50- Future <Uint8List > _setPartialWindow (Uint8List tagId, int xsbank, int xebank, int ys, int ye, bool pt_scan) async {
51+ Future <Uint8List > _setPartialWindow (Uint8List tagId, int xsbank, int xebank,
52+ int ys, int ye, bool pt_scan) async {
5153 // FIXME: move these constants to a specific controller
5254 if (xsbank > 0x1d ) throw "Horizontal start channel bank must be <= 0x1D" ;
5355 if (xebank > 0x1d ) throw "Horizontal end channel bank must be <= 0x1D" ;
5456 if (xsbank >= xebank) throw "Start channel must be < End channel bank" ;
55-
57+
5658 if (ys > 0x1df ) throw "Horizontal start channel bank must be <= 0x1DF" ;
5759 if (ye > 0x1df ) throw "Horizontal end channel bank must be <= 0x1DF" ;
5860 if (ys >= ye) throw "Start channel must be < End channel bank" ;
@@ -65,117 +67,49 @@ class Protocol {
6567 int VRED70 = ye & 0xff ;
6668
6769 await _writeMsg (tagId, Uint8List .fromList ([fw.epdCmd, 0x90 ]));
68- return await _writeMsg (tagId, Uint8List .fromList ([fw.epdSend, HRST73 , HRED73 , VRST8 , VRST70 , VRED8 , VRED70 , pt_scan ? 1 : 0 ]));
70+ return await _writeMsg (
71+ tagId,
72+ Uint8List .fromList ([
73+ fw.epdSend,
74+ HRST73 ,
75+ HRED73 ,
76+ VRST8 ,
77+ VRST70 ,
78+ VRED8 ,
79+ VRED70 ,
80+ pt_scan ? 1 : 0
81+ ]));
6982 }
7083
7184 void _partialIn (Uint8List tagId) async {
85+ // FIXME:
7286 await _writeMsg (tagId, Uint8List .fromList ([fw.epdCmd, 0x91 ]));
7387 }
7488
7589 void _partialOut (Uint8List tagId) async {
90+ // FIXME:
7691 await _writeMsg (tagId, Uint8List .fromList ([fw.epdCmd, 0x92 ]));
7792 }
7893
79-
80- static const int GND = 0 ;
81- static const int VSH = 0x40 ;
82- static const int VSL = 0x80 ;
83- static const int VDHR = 0x60 ;
84-
85- static const int VCOM_LUT = 0x20 ;
86- static const int W2W_LUT = 0x21 ;
87- static const int B2W_LUT = 0x22 ;
88- static const int W2B_LUT = 0x23 ;
89- static const int B2B_LUT = 0x24 ;
90-
91- static const int PANEL_SETTING = 0x00 ;
92- static const int PLL_CONTROL = 0x30 ;
93-
94- Uint8List lut_vcom_quick = Uint8List .fromList ([
95- 0x01 , 0x00 , 10 , 0x00 , 0x00 , 0x01 , 0x00 ,
96- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
97- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
98- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
99- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
100- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
101-
102- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
103- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
104- ]);
105-
106- // white gates go white with VSL
107- Uint8List lut_ww_quick = Uint8List .fromList ([
108- 0x01 , VSL | 10 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 ,
109- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
110- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
111- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
112- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
113- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
114- ]);
115-
116- // red gates go white with VSL, go red with VSH
117- Uint8List lut_r_quick = Uint8List .fromList ([
118- 0x01 , VSL | 10 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 ,
119- 0x01 , 10 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 ,
120- 0x01 , VSH | 10 , 5 , 0x00 , 0x00 , 0x02 , 0x00 ,
121- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
122- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
123- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
124-
125- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
126- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
127- ]);
128-
129- // V*H will make white gates as black/red
130- Uint8List lut_w_quick = Uint8List .fromList ([
131- 0x01 , 10 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 ,
132- 0x01 , 10 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 ,
133- 0x01 , 10 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 ,
134- 0x00 , VSH | 2 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 ,
135- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
136- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
137-
138- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
139- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
140- ]);
141-
142- // black gates go black/red with VSH
143- Uint8List lut_b_quick = Uint8List .fromList ([
144- 0x01 , 10 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 ,
145- 0x01 , VSH | 12 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 ,
146- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
147- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
148- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
149- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
150-
151- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
152- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
153- ]);
154-
155- Future <void > _setlut (Uint8List tagId) async {
156- await _writeMsg (tagId, Uint8List .fromList ([fw.epdCmd, PLL_CONTROL ]));
94+ Future <void > _setlut (Uint8List tagId, Waveform waveform) async {
95+ await _writeMsg (
96+ tagId, Uint8List .fromList ([fw.epdCmd, epd.controller.pllControl]));
15797 await _writeMsg (tagId, Uint8List .fromList ([fw.epdSend, 0x01 ])); // 10hz
15898
159- await _writeMsg (tagId, Uint8List .fromList ([fw.epdCmd, VCOM_LUT ]));
160- await _writeMsg (tagId, Uint8List .fromList ([fw.epdSend, ...lut_vcom_quick]));
161-
162- await _writeMsg (tagId, Uint8List .fromList ([fw.epdCmd, W2W_LUT ]));
163- await _writeMsg (tagId, Uint8List .fromList ([fw.epdSend, ...lut_ww_quick]));
164-
165- await _writeMsg (tagId, Uint8List .fromList ([fw.epdCmd, B2W_LUT ]));
166- await _writeMsg (tagId, Uint8List .fromList ([fw.epdSend, ...lut_r_quick]));
167-
168- await _writeMsg (tagId, Uint8List .fromList ([fw.epdCmd, W2B_LUT ]));
169- await _writeMsg (tagId, Uint8List .fromList ([fw.epdSend, ...lut_w_quick]));
170-
171- await _writeMsg (tagId, Uint8List .fromList ([fw.epdCmd, B2B_LUT ]));
172- await _writeMsg (tagId, Uint8List .fromList ([fw.epdSend, ...lut_b_quick]));
99+ for (var lut in waveform.luts) {
100+ await _writeMsg (tagId, Uint8List .fromList ([fw.epdCmd, lut.cmd]));
101+ await _writeMsg (tagId, Uint8List .fromList ([fw.epdSend, ...lut.data]));
102+ }
173103 }
174104
175105 Future <void > _panelSetting (Uint8List tagId) async {
176- await _writeMsg (tagId, Uint8List .fromList ([fw.epdCmd, PANEL_SETTING ]));
106+ await _writeMsg (
107+ tagId, Uint8List .fromList ([fw.epdCmd, epd.controller.panelSetting]));
177108 // await _writeMsg(tagId, Uint8List.fromList([fw.epdSend, 0xCF, 0x8D])); // 480x240, built-in LUTs
178- await _writeMsg (tagId, Uint8List .fromList ([fw.epdSend, 0xEF , 0x8D ])); // 480x240, LUTs from register
109+ await _writeMsg (
110+ tagId,
111+ Uint8List .fromList (
112+ [fw.epdSend, 0xEF , 0x8D ])); // 480x240, LUTs from register
179113 }
180114
181115 Future <void > _sleep () async {
@@ -261,8 +195,10 @@ class Protocol {
261195 const Duration (seconds: 2 )); // waiting for the power supply stable
262196
263197 // await _setPartialWindow(id, 0, epd.width ~/ 8 - 1, 0, epd.height - 1, true);
198+
199+ // FIXME: take input from the UI to enable the waveform. The built-in waveform should be used by default
264200 await _panelSetting (id);
265- await _setlut (id);
201+ await _setlut (id, epd.controller.waveforms[ 0 ] );
266202
267203 final epdColors = epd.extractEpaperColorFrames (image);
268204 final transmissionLines = epd.controller.transmissionLines.iterator;
0 commit comments