forked from 400plus/400plus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
af_patterns.c
104 lines (79 loc) · 5.3 KB
/
af_patterns.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <vxworks.h>
#include "firmware.h"
#include "firmware/camera.h"
#include "main.h"
#include "macros.h"
#include "utils.h"
#include "intercom.h"
#include "af_patterns.h"
pattern_map_item_t pattern_map[] = {
{AF_PATTERN_CENTER, AF_PATTERN_SQUARE, AF_PATTERN_TOPHALF, AF_PATTERN_BOTTOMHALF, AF_PATTERN_LEFTHALF, AF_PATTERN_RIGHTHALF},
{AF_PATTERN_SQUARE, AF_PATTERN_HLINE, AF_PATTERN_TOPHALF, AF_PATTERN_BOTTOMHALF, AF_PATTERN_LEFTHALF, AF_PATTERN_RIGHTHALF},
{AF_PATTERN_TOP, AF_PATTERN_CENTER, AF_PATTERN_TOP, AF_PATTERN_TOPTRIANGLE, AF_PATTERN_TOPLEFT, AF_PATTERN_TOPRIGHT},
{AF_PATTERN_TOPTRIANGLE, AF_PATTERN_CENTER, AF_PATTERN_TOP, AF_PATTERN_TOPDIAMOND, AF_PATTERN_LEFTTRIANGLE, AF_PATTERN_RIGHTTRIANGLE},
{AF_PATTERN_TOPDIAMOND, AF_PATTERN_CENTER, AF_PATTERN_TOPTRIANGLE, AF_PATTERN_TOPHALF, AF_PATTERN_LEFTDIAMOND, AF_PATTERN_RIGHTDIAMOND},
{AF_PATTERN_TOPHALF, AF_PATTERN_CENTER, AF_PATTERN_TOPDIAMOND, AF_PATTERN_HLINE, AF_PATTERN_LEFTHALF, AF_PATTERN_RIGHTHALF},
{AF_PATTERN_BOTTOM, AF_PATTERN_CENTER, AF_PATTERN_BOTTOMTRIANGLE, AF_PATTERN_BOTTOM, AF_PATTERN_BOTTOMLEFT, AF_PATTERN_BOTTOMRIGHT},
{AF_PATTERN_BOTTOMTRIANGLE, AF_PATTERN_CENTER, AF_PATTERN_BOTTOMDIAMOND, AF_PATTERN_BOTTOM, AF_PATTERN_LEFTTRIANGLE, AF_PATTERN_RIGHTTRIANGLE},
{AF_PATTERN_BOTTOMDIAMOND, AF_PATTERN_CENTER, AF_PATTERN_BOTTOMHALF, AF_PATTERN_BOTTOMTRIANGLE, AF_PATTERN_LEFTDIAMOND, AF_PATTERN_RIGHTDIAMOND},
{AF_PATTERN_BOTTOMHALF, AF_PATTERN_CENTER, AF_PATTERN_HLINE, AF_PATTERN_BOTTOMDIAMOND, AF_PATTERN_LEFTHALF, AF_PATTERN_RIGHTHALF},
{AF_PATTERN_TOPLEFT, AF_PATTERN_CENTER, AF_PATTERN_TOP, AF_PATTERN_BOTTOMLEFT, AF_PATTERN_LEFT, AF_PATTERN_TOPRIGHT},
{AF_PATTERN_TOPRIGHT, AF_PATTERN_CENTER, AF_PATTERN_TOP, AF_PATTERN_BOTTOMRIGHT, AF_PATTERN_TOPLEFT, AF_PATTERN_RIGHT},
{AF_PATTERN_BOTTOMLEFT, AF_PATTERN_CENTER, AF_PATTERN_TOPLEFT, AF_PATTERN_BOTTOM, AF_PATTERN_LEFT, AF_PATTERN_BOTTOMRIGHT},
{AF_PATTERN_BOTTOMRIGHT, AF_PATTERN_CENTER, AF_PATTERN_TOPRIGHT, AF_PATTERN_BOTTOM, AF_PATTERN_BOTTOMLEFT, AF_PATTERN_RIGHT},
{AF_PATTERN_LEFT, AF_PATTERN_CENTER, AF_PATTERN_TOPLEFT, AF_PATTERN_BOTTOMLEFT, AF_PATTERN_LEFT, AF_PATTERN_LEFTTRIANGLE},
{AF_PATTERN_LEFTTRIANGLE, AF_PATTERN_CENTER, AF_PATTERN_TOPTRIANGLE, AF_PATTERN_BOTTOMTRIANGLE, AF_PATTERN_LEFT, AF_PATTERN_LEFTDIAMOND},
{AF_PATTERN_LEFTDIAMOND, AF_PATTERN_CENTER, AF_PATTERN_TOPDIAMOND, AF_PATTERN_BOTTOMDIAMOND, AF_PATTERN_LEFTTRIANGLE, AF_PATTERN_LEFTHALF},
{AF_PATTERN_LEFTHALF, AF_PATTERN_CENTER, AF_PATTERN_TOPHALF, AF_PATTERN_BOTTOMHALF, AF_PATTERN_LEFTDIAMOND, AF_PATTERN_VLINE},
{AF_PATTERN_RIGHT, AF_PATTERN_CENTER, AF_PATTERN_TOPRIGHT, AF_PATTERN_BOTTOMRIGHT, AF_PATTERN_RIGHTTRIANGLE, AF_PATTERN_RIGHT},
{AF_PATTERN_RIGHTTRIANGLE, AF_PATTERN_CENTER, AF_PATTERN_TOPTRIANGLE, AF_PATTERN_BOTTOMTRIANGLE, AF_PATTERN_RIGHTDIAMOND, AF_PATTERN_RIGHT},
{AF_PATTERN_RIGHTDIAMOND, AF_PATTERN_CENTER, AF_PATTERN_TOPDIAMOND, AF_PATTERN_BOTTOMDIAMOND, AF_PATTERN_RIGHTHALF, AF_PATTERN_RIGHTTRIANGLE},
{AF_PATTERN_RIGHTHALF, AF_PATTERN_CENTER, AF_PATTERN_TOPHALF, AF_PATTERN_BOTTOMHALF, AF_PATTERN_VLINE, AF_PATTERN_RIGHTDIAMOND},
{AF_PATTERN_HLINE, AF_PATTERN_VLINE, AF_PATTERN_TOPHALF, AF_PATTERN_BOTTOMHALF, AF_PATTERN_LEFTHALF, AF_PATTERN_RIGHTHALF},
{AF_PATTERN_VLINE, AF_PATTERN_ALL, AF_PATTERN_TOPHALF, AF_PATTERN_BOTTOMHALF, AF_PATTERN_LEFTHALF, AF_PATTERN_RIGHTHALF},
{AF_PATTERN_ALL, AF_PATTERN_CENTER, AF_PATTERN_TOPHALF, AF_PATTERN_BOTTOMHALF, AF_PATTERN_LEFTHALF, AF_PATTERN_RIGHTHALF},
{AF_PATTERN_NONE}
};
int afp_transformer (int pattern, direction_t direction);
void afp_enter() {
beep();
}
void afp_center () {
send_to_intercom(IC_SET_AF_POINT, afp_transformer(DPData.af_point, DIRECTION_CENTER));
}
void afp_top () {
send_to_intercom(IC_SET_AF_POINT, afp_transformer(DPData.af_point, DIRECTION_UP));
}
void afp_bottom () {
send_to_intercom(IC_SET_AF_POINT, afp_transformer(DPData.af_point, DIRECTION_DOWN));
}
void afp_left () {
send_to_intercom(IC_SET_AF_POINT, afp_transformer(DPData.af_point, DIRECTION_LEFT));
}
void afp_right () {
send_to_intercom(IC_SET_AF_POINT, afp_transformer(DPData.af_point, DIRECTION_RIGHT));
}
int afp_transformer (int pattern, direction_t direction) {
pattern_map_item_t *item;
// Loop over all items in the pattern map
for (item = pattern_map; item->pattern != AF_PATTERN_NONE; item++) {
// When we find an item matching the current pattern...
if (item->pattern == pattern) {
// ... we return the next pattern, according to the direction indicated
switch (direction) {
case DIRECTION_CENTER:
return item->next_center;
case DIRECTION_UP:
return item->next_top;
case DIRECTION_DOWN:
return item->next_bottom;
case DIRECTION_LEFT:
return item->next_left;
case DIRECTION_RIGHT:
return item->next_right;
}
}
}
// Just in case something goes wrong
return AF_PATTERN_CENTER;
}