Skip to content

Commit 295aedf

Browse files
committed
Sense HAT experimentation
1 parent f78627d commit 295aedf

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

playpen/iot/sense_hat/sense.dart

+35-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,40 @@ final boxPixels = [
77
for (int y = 0; y <= 7; y++) Pixel(7, y, 0xFFFFFF),
88
];
99

10+
final flutterLightBlue = 0x0000FF;
11+
final flutterMediumBlue = 0x3333FF;
12+
final flutterDarkBlue = 0x6666FF;
13+
14+
final flutterLogo = [
15+
Pixel(0, 3, flutterLightBlue),
16+
Pixel(0, 4, flutterLightBlue),
17+
Pixel(1, 2, flutterLightBlue),
18+
Pixel(1, 3, flutterLightBlue),
19+
Pixel(2, 1, flutterLightBlue),
20+
Pixel(2, 2, flutterLightBlue),
21+
Pixel(3, 0, flutterLightBlue),
22+
Pixel(3, 1, flutterLightBlue),
23+
Pixel(3, 3, flutterLightBlue),
24+
Pixel(3, 4, flutterLightBlue),
25+
Pixel(4, 0, flutterLightBlue),
26+
Pixel(4, 1, flutterLightBlue),
27+
Pixel(4, 3, flutterLightBlue),
28+
Pixel(4, 4, flutterLightBlue),
29+
Pixel(5, 1, flutterMediumBlue),
30+
Pixel(5, 2, flutterMediumBlue),
31+
Pixel(5, 3, flutterMediumBlue),
32+
Pixel(6, 2, flutterDarkBlue),
33+
Pixel(6, 3, flutterDarkBlue),
34+
Pixel(7, 3, flutterDarkBlue),
35+
Pixel(7, 4, flutterDarkBlue),
36+
];
37+
1038
main() {
1139
// Zero out the test device file
1240
//File('test.bin').writeAsBytes(List.generate(64 * 2, (i) => 0));
1341
final buffer = FrameBuffer('test.bin');
14-
buffer.setPixels(boxPixels);
42+
buffer.resetPixels();
43+
buffer.setPixels(flutterLogo);
1544
// buffer.setPixel(1, 7, 255, 255, 255);
1645
}
1746

@@ -29,9 +58,13 @@ class FrameBuffer {
2958
writer.closeSync();
3059
}
3160

61+
void resetPixels() async {
62+
await setPixels(List.generate(64, (i) => Pixel(i % 8, (i ~/ 8), 0x000000)));
63+
}
64+
3265
void _setPixel(Pixel pixel, RandomAccessFile deviceFile) {
3366
final bytes = _createColourBytes(pixel.rgb);
34-
deviceFile.setPositionSync(((pixel.y * 8) + pixel.x) * 2);
67+
deviceFile.setPositionSync(((pixel.x * 8) + pixel.y) * 2);
3568
deviceFile.writeFromSync([upperByte(bytes), lowerByte(bytes)]);
3669
}
3770

0 commit comments

Comments
 (0)