-
Notifications
You must be signed in to change notification settings - Fork 0
/
hypercube.c
75 lines (58 loc) · 1.36 KB
/
hypercube.c
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
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <wiringPi.h>
#include "internals.h"
int register_cube[7][18]; /* soft copy used for reading before writing to the register */
int led_cube[5][5][5]; /* soft copy used for the game */
int player[1];
struct position {
int x;
int y;
int z;
}
void write_led(int led_value /* to write */, int x, int y, int z)
{
/* when we write to led we must:
- compute the register index then
- map onto register cube
- write in LED cube
- write block of register cube to shift register (if needed)
*/
int linearized = x + 5 * y + 25 * z;
assert(x < 5 && y < 5 && z < 5);
struct pair p = map_to_register_cube_index(linearized);
led_cube[x][y][z] = led_value;
if (led_value != register_cube[p.a][p.b]) {
write_shift_register(linearized);
}
}
enum state {
STATE_INITIALIZE=0,
MAIN,
};
void init_board()
{
int x,y,z;
memset(register_cube, 0, sizeof(register_cube));
write_led(0, 0,0,0);
/* only flushes one block if unitialized fix */
}
int main()
{
enum state s = STATE_INITIALIZE;
while (1)
{
switch (s)
{
case STATE_INITIALIZE:
init_board();
s = MAIN;
break;
case MAIN:
update_LED();
if () {
}
}
}
}