-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdump32x32.cc
More file actions
86 lines (66 loc) · 1.81 KB
/
dump32x32.cc
File metadata and controls
86 lines (66 loc) · 1.81 KB
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
// -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
// Small example how to use the library.
// For more examples, look at demo-main.cc
//
// This code is public domain
// (but note, that the led-matrix library this depends on is GPL v2)
#include "led-matrix.h"
#include <unistd.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using rgb_matrix::GPIO;
using rgb_matrix::RGBMatrix;
using rgb_matrix::Canvas;
int main(int argc, char *argv[]) {
/*
* Set up GPIO pins. This fails when not running as root.
*/
GPIO io;
if (!io.Init())
return 1;
/*
* Set up the RGBMatrix. It implements a 'Canvas' interface.
*/
int rows = 32; // A 32x32 display. Use 16 when this is a 16x32 display.
int chain = 1; // Number of boards chained together.
int parallel = 1; // Number of chains in parallel (1..3). > 1 for plus or Pi2
int pwm = 8;
int delay = 10;
int c;
while ((c = getopt (argc, argv, "p:d:")) != -1)
switch (c) {
case 'p':
pwm = atoi(optarg);
break;
case 'd':
delay = atoi(optarg);
break;
default:
return 0;
}
RGBMatrix *matrix = new RGBMatrix(&io, rows, chain, parallel);
matrix->SetPWMBits(pwm);
printf("pwm bits: %d", matrix->pwmbits());
printf("pwm correction: %d", matrix->luminance_correct());
Canvas *canvas = matrix;
//canvas->Fill(0, 0, 255);
FILE *f = freopen(NULL, "rb", stdin);
unsigned char buf[3];
int bytes_read;
while(1) {
for(int y=0; y<32; y++) {
for(int x=0; x<32; x++) {
do {
bytes_read = fread(buf, 3, 1, f);
} while(bytes_read != 1);
canvas->SetPixel(x, y, buf[0], buf[1], buf[2]);
}
}
//vsync? suspend execution for microsecond intervals
usleep(delay);
}
canvas->Clear();
delete canvas;
return 0;
}