@@ -45,6 +45,36 @@ class Protocol {
4545 Future <Uint8List > enableEnergyHarvesting (Uint8List tagId) async {
4646 return await _writeDynCfg (tagId, 0x02 , 0x01 );
4747 }
48+
49+ // `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+ // FIXME: move these constants to a specific controller
52+ if (xsbank > 0x1d ) throw "Horizontal start channel bank must be <= 0x1D" ;
53+ if (xebank > 0x1d ) throw "Horizontal end channel bank must be <= 0x1D" ;
54+ if (xsbank >= xebank) throw "Start channel must be < End channel bank" ;
55+
56+ if (ys > 0x1df ) throw "Horizontal start channel bank must be <= 0x1DF" ;
57+ if (ye > 0x1df ) throw "Horizontal end channel bank must be <= 0x1DF" ;
58+ if (ys >= ye) throw "Start channel must be < End channel bank" ;
59+
60+ int HRST73 = xsbank << 3 ;
61+ int HRED73 = (xebank << 3 ) | 0x07 ;
62+ int VRST8 = (ys >> 8 ) & 1 ;
63+ int VRST70 = ys & 0xff ;
64+ int VRED8 = (ye >> 8 ) & 1 ;
65+ int VRED70 = ye & 0xff ;
66+
67+ 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 ]));
69+ }
70+
71+ void _partialIn (Uint8List tagId) async {
72+ await _writeMsg (tagId, Uint8List .fromList ([fw.epdCmd, 0x91 ]));
73+ }
74+
75+ void _partialOut (Uint8List tagId) async {
76+ await _writeMsg (tagId, Uint8List .fromList ([fw.epdCmd, 0x92 ]));
77+ }
4878
4979 Future <void > _sleep () async {
5080 await Future .delayed (const Duration (milliseconds: 20 ));
@@ -128,13 +158,17 @@ class Protocol {
128158 await Future .delayed (
129159 const Duration (seconds: 2 )); // waiting for the power supply stable
130160
161+ await _setPartialWindow (id, 0 , epd.width ~ / 8 - 1 , 0 , epd.height - 1 , true );
162+
131163 final epdColors = epd.extractEpaperColorFrames (image);
132164 final transmissionLines = epd.controller.transmissionLines.iterator;
133165 for (final c in epdColors) {
134166 transmissionLines.moveNext ();
135167 await writeFrame (id, c, transmissionLines.current);
136168 }
137169
170+ await _setPartialWindow (id, 0 , 15 , 0 , 200 , true );
171+ _partialIn (id);
138172 await _writeMsg (
139173 id, Uint8List .fromList ([fw.epdCmd, epd.controller.refresh]));
140174 await FlutterNfcKit .finish ();
0 commit comments