altos/telelco: Add per-box RSSI display screen
[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 #define DEBUG   1
29
30 #if DEBUG
31 extern uint8_t  ao_lco_debug;
32 #define PRINTD(...) do { if (!ao_lco_debug) break; printf ("\r%5lu %s: ", (unsigned long) ao_tick_count, __func__); printf(__VA_ARGS__); flush(); } while(0)
33 #else
34 #define PRINTD(...) 
35 #endif
36
37 #if AO_LCO_DRAG
38 extern uint8_t  ao_lco_drag_race;       /* true when drag race mode enabled */
39 #endif
40
41 extern int8_t   ao_lco_pad;             /* Currently selected pad */
42 extern int16_t  ao_lco_box;             /* Currently selected box */
43
44 extern uint8_t  ao_lco_armed;           /* armed mode active */
45 extern uint8_t  ao_lco_firing;          /* fire button pressed */
46
47 extern struct ao_pad_query      ao_pad_query;   /* Last received QUERY from pad */
48
49 #ifdef AO_LCO_DRAG_RACE_BOX
50 #define AO_LCO_BOX_DRAG         0               /* Box number to enable drag race mode (old LCO bits) */
51 #define AO_LCO_BOX_FIRST        AO_LCO_BOX_DRAG
52 #else
53 # define AO_LCO_LCO_VOLTAGE     0               /* Box number to show LCO voltage */
54 # ifdef AO_LCO_HAS_INFO
55 #  define AO_LCO_INFO           -3
56 #  ifndef AO_LCO_BOX_FIRST
57 #   define AO_LCO_BOX_FIRST AO_LCO_INFO
58 #  endif
59 # endif
60 # ifdef AO_LCO_HAS_BACKLIGHT
61 #   define AO_LCO_BACKLIGHT     -2
62 #   ifndef AO_LCO_BOX_FIRST
63 #    define AO_LCO_BOX_FIRST AO_LCO_BACKLIGHT
64 #   endif
65 # endif
66 # ifdef AO_LCO_HAS_CONTRAST
67 #  define AO_LCO_CONTRAST       -1
68 #  ifndef AO_LCO_BOX_FIRST
69 #   define AO_LCO_BOX_FIRST     AO_LCO_CONTRAST
70 #  endif
71 # endif
72 # ifndef AO_LCO_BOX_FIRST
73 #  define AO_LCO_BOX_FIRST      AO_LCO_LCO_VOLTAGE
74 # endif
75 #endif
76 #define AO_LCO_PAD_VOLTAGE      0               /* Pad number to show box voltage */
77 #define AO_LCO_PAD_RSSI         -1              /* Pad number to show box RSSI */
78 #define AO_LCO_PAD_FIRST        AO_LCO_PAD_RSSI
79
80 static inline bool
81 ao_lco_box_pseudo(int16_t box)
82 {
83         switch (box) {
84 #ifdef AO_LCO_LCO_VOLTAGE
85         case AO_LCO_LCO_VOLTAGE:
86                 return true;
87 #endif
88 #ifdef AO_LCO_DRAG_RACE_BOX
89         case AO_LCO_BOX_DRAG:
90                 return true;
91 #endif
92 #ifdef AO_LCO_CONTRAST
93         case AO_LCO_CONTRAST:
94                 return true;
95 #endif
96 #ifdef AO_LCO_BACKLIGHT
97         case AO_LCO_BACKLIGHT:
98                 return true;
99 #endif
100 #ifdef AO_LCO_INFO
101         case AO_LCO_INFO:
102                 return true;
103 #endif
104         default:
105                 return false;
106         }
107 }
108
109 static inline bool
110 ao_lco_pad_pseudo(int8_t pad)
111 {
112         switch (pad) {
113         case AO_LCO_PAD_VOLTAGE:
114                 return true;
115         case AO_LCO_PAD_RSSI:
116                 return true;
117         default:
118                 return false;
119         }
120 }
121
122 extern int16_t  ao_lco_min_box, ao_lco_max_box;
123
124 #define AO_LCO_MASK_SIZE(n)     (((n) + 7) >> 3)
125 #define AO_LCO_MASK_ID(n)       ((n) >> 3)
126 #define AO_LCO_MASK_SHIFT(n)    ((n) & 7)
127
128 extern uint8_t  ao_lco_box_mask[AO_LCO_MASK_SIZE(AO_PAD_MAX_BOXES)];
129
130 #define AO_LCO_VALID_LAST       1
131 #define AO_LCO_VALID_EVER       2
132
133 extern uint8_t  ao_lco_valid[AO_PAD_MAX_BOXES];         /* AO_LCO_VALID bits per box */
134
135 /*
136  * Shared functions
137  */
138
139 void
140 ao_lco_igniter_status(void);
141
142 void
143 ao_lco_update(void);
144
145 uint8_t
146 ao_lco_pad_present(int16_t box, int8_t pad);
147
148 int8_t
149 ao_lco_pad_first(int16_t box);
150
151 void
152 ao_lco_set_pad(int8_t new_pad);
153
154 void
155 ao_lco_step_pad(int8_t dir);
156
157 void
158 ao_lco_set_box(int16_t new_box);
159
160 void
161 ao_lco_step_box(int8_t dir);
162
163 void
164 ao_lco_set_armed(uint8_t armed);
165
166 void
167 ao_lco_set_firing(uint8_t firing);
168
169 void
170 ao_lco_pretend(void);
171
172 void
173 ao_lco_toggle_drag(void);
174
175 void
176 ao_lco_search(void);
177
178 void
179 ao_lco_monitor(void);
180
181 extern int8_t                   ao_lco_drag_beep_count;
182
183 /* enable drag race mode */
184 void
185 ao_lco_drag_enable(void);
186
187 /* disable drag race mode */
188 void
189 ao_lco_drag_disable(void);
190
191 /* Handle drag beeps, return new delay */
192 AO_TICK_TYPE
193 ao_lco_drag_beep_check(AO_TICK_TYPE now, AO_TICK_TYPE delay);
194
195 /* Check if it's time to beep during drag race. Return new delay */
196 AO_TICK_TYPE
197 ao_lco_drag_warn_check(AO_TICK_TYPE now, AO_TICK_TYPE delay);
198
199 /* Request 'beeps' additional drag race beeps */
200 void
201 ao_lco_drag_add_beeps(int8_t beeps);
202
203 /* task function for beeping while arm is active */
204 void
205 ao_lco_arm_warn(void);
206
207 /*
208  * Provided by the hw-specific driver code
209  */
210
211 void
212 ao_lco_show_pad(uint8_t pad);
213
214 void
215 ao_lco_show_box(int16_t box);
216
217 void
218 ao_lco_show(void);
219
220 void
221 ao_lco_init(void);
222
223 uint8_t
224 ao_lco_box_present(int16_t box);
225
226 #ifdef AO_LCO_HAS_CONTRAST
227 void
228 ao_lco_set_contrast(int32_t contrast);
229
230 int32_t
231 ao_lco_get_contrast(void);
232 #endif
233
234 #ifdef AO_LCO_HAS_BACKLIGHT
235 void
236 ao_lco_set_backlight(int32_t backlight);
237
238 int32_t
239 ao_lco_get_backlight(void);
240 #endif
241
242 #ifdef AO_LCO_SEARCH_API
243
244 void
245 ao_lco_search_start(void);
246
247 void
248 ao_lco_search_box_check(int16_t box);
249
250 void
251 ao_lco_search_box_present(int16_t box);
252
253 void
254 ao_lco_search_done(void);
255
256 #endif /* AO_LCO_SEARCH_API */
257
258 #endif /* _AO_LCO_H_ */