e528c2ad22b313080717e0987f0c2298e901d210
[fw/altos] / src / drivers / ao_lco.h
1 /*
2  * Copyright © 2012 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #ifndef _AO_LCO_H_
20 #define _AO_LCO_H_
21
22 #include <ao_lco_func.h>
23
24 #ifndef AO_LCO_DRAG
25 #define AO_LCO_DRAG     1
26 #endif
27
28 #if AO_LCO_DRAG
29 #define AO_LCO_BOX_DRAG         0x1000
30 #endif
31
32 #define DEBUG   1
33
34 #if DEBUG
35 extern uint8_t  ao_lco_debug;
36 #define PRINTD(...) do { if (!ao_lco_debug) break; printf ("\r%5u %s: ", ao_tick_count, __func__); printf(__VA_ARGS__); flush(); } while(0)
37 #else
38 #define PRINTD(...) 
39 #endif
40
41 extern uint8_t  ao_lco_drag_race;       /* TRUE when drag race mode enabled */
42 extern uint8_t  ao_lco_pad;             /* Currently selected pad */
43 extern int16_t  ao_lco_box;             /* Currently selected box */
44
45 extern uint8_t  ao_lco_armed;
46 extern uint8_t  ao_lco_firing;
47
48 extern struct ao_pad_query      ao_pad_query;   /* Last received QUERY from pad */
49
50 #define AO_LCO_VALID_LAST       1
51 #define AO_LCO_VALID_EVER       2
52
53 #define AO_LCO_PAD_VOLTAGE      0               /* Pad number to show box voltage */
54
55 extern uint8_t  ao_lco_min_box, ao_lco_max_box;
56 extern uint8_t  ao_lco_selected[AO_PAD_MAX_BOXES];
57 extern uint8_t  ao_lco_valid[AO_PAD_MAX_BOXES];
58 extern uint8_t  ao_lco_channels[AO_PAD_MAX_BOXES];
59 extern uint16_t ao_lco_tick_offset[AO_PAD_MAX_BOXES];
60
61 #define AO_LCO_MASK_SIZE(n)     (((n) + 7) >> 3)
62 #define AO_LCO_MASK_ID(n)       ((n) >> 3)
63 #define AO_LCO_MASK_SHIFT(n)    ((n) & 7)
64
65 extern uint8_t  ao_lco_box_mask[AO_LCO_MASK_SIZE(AO_PAD_MAX_BOXES)];
66
67 /*
68  * Shared functions
69  */
70
71 void
72 ao_lco_igniter_status(void);
73
74 void
75 ao_lco_update(void);
76
77 uint8_t
78 ao_lco_pad_present(uint8_t box, uint8_t pad);
79
80 uint8_t
81 ao_lco_pad_first(uint8_t box);
82
83 void
84 ao_lco_set_pad(uint8_t new_pad);
85
86 void
87 ao_lco_step_pad(int8_t dir);
88
89 void
90 ao_lco_set_box(uint16_t new_box);
91
92 void
93 ao_lco_set_armed(uint8_t armed);
94
95 void
96 ao_lco_set_firing(uint8_t firing);
97
98 void
99 ao_lco_toggle_drag(void);
100
101 void
102 ao_lco_search(void);
103
104 void
105 ao_lco_monitor(void);
106
107 extern uint8_t                  ao_lco_drag_beep_count;
108
109 /* enable drag race mode */
110 void
111 ao_lco_drag_enable(void);
112
113 /* disable drag race mode */
114 void
115 ao_lco_drag_disable(void);
116
117 /* Handle drag beeps, return new delay */
118 uint16_t
119 ao_lco_drag_beep_check(uint16_t now, uint16_t delay);
120
121 /* Check if it's time to beep during drag race. Return new delay */
122 uint16_t
123 ao_lco_drag_warn_check(uint16_t now, uint16_t delay);
124
125 /* Request 'beeps' additional drag race beeps */
126 void
127 ao_lco_drag_add_beeps(uint8_t beeps);
128
129 /* task function for beeping while arm is active */
130 void
131 ao_lco_arm_warn(void);
132
133 /*
134  * Provided by the hw-specific driver code
135  */
136
137 void
138 ao_lco_show_pad(uint8_t pad);
139
140 void
141 ao_lco_show_box(uint16_t box);
142
143 void
144 ao_lco_show(void);
145
146 void
147 ao_lco_init(void);
148
149 uint8_t
150 ao_lco_box_present(uint16_t box);
151
152 #endif /* _AO_LCO_H_ */