LibDriver AS3935
Loading...
Searching...
No Matches
driver_as3935_basic.c
Go to the documentation of this file.
1
36
37#include "driver_as3935_basic.h"
38
39static as3935_handle_t gs_handle;
40
49{
50 if (as3935_irq_handler(&gs_handle) != 0)
51 {
52 return 1;
53 }
54
55 return 0;
56}
57
69 void (*callback)(uint8_t type))
70{
71 uint8_t res;
72 uint8_t cap;
73
74 /* link interface function */
86 DRIVER_AS3935_LINK_RECEIVE_CALLBACK(&gs_handle, callback);
87
88 /* set the interface */
89 res = as3935_set_interface(&gs_handle, interface);
90 if (res != 0)
91 {
92 as3935_interface_debug_print("as3935: set interface failed.\n");
93
94 return 1;
95 }
96
97 /* set addr pin */
98 res = as3935_set_addr_pin(&gs_handle, addr_pin);
99 if (res != 0)
100 {
101 as3935_interface_debug_print("as3935: set addr pin failed.\n");
102
103 return 1;
104 }
105
106 /* as3935 initialization */
107 res = as3935_init(&gs_handle);
108 if (res != 0)
109 {
110 as3935_interface_debug_print("as3935: init failed.\n");
111
112 return 1;
113 }
114
115 /* power on */
116 res = as3935_set_power_down(&gs_handle, AS3935_BOOL_FALSE);
117 if (res != 0)
118 {
119 as3935_interface_debug_print("as3935: set power down failed.\n");
120 (void)as3935_deinit(&gs_handle);
121
122 return 1;
123 }
124
125 /* reset default */
126 res = as3935_reset_default(&gs_handle);
127 if (res != 0)
128 {
129 as3935_interface_debug_print("as3935: reset default failed.\n");
130 (void)as3935_deinit(&gs_handle);
131
132 return 1;
133 }
134
135 /* delay 10ms */
137
138 /* set calibrate rc osc */
139 res = as3935_set_calibrate_rc_osc(&gs_handle);
140 if (res != 0)
141 {
142 as3935_interface_debug_print("as3935: set calibrate rc osc failed.\n");
143 (void)as3935_deinit(&gs_handle);
144
145 return 1;
146 }
147
148 /* enable system rc osc display on irq */
150 if (res != 0)
151 {
152 as3935_interface_debug_print("as3935: set system rc osc display on irq failed.\n");
153 (void)as3935_deinit(&gs_handle);
154
155 return 1;
156 }
157
158 /* delay 2ms */
160
161 /* disable system rc osc display on irq */
163 if (res != 0)
164 {
165 as3935_interface_debug_print("as3935: set system rc osc display on irq failed.\n");
166 (void)as3935_deinit(&gs_handle);
167
168 return 1;
169 }
170
171 /* disable lc osc display on irq */
173 if (res != 0)
174 {
175 as3935_interface_debug_print("as3935: set lc osc display on irq failed.\n");
176 (void)as3935_deinit(&gs_handle);
177
178 return 1;
179 }
180
181 /* disable timer rc osc display on irq */
183 if (res != 0)
184 {
185 as3935_interface_debug_print("as3935: set timer rc osc display on irq failed.\n");
186 (void)as3935_deinit(&gs_handle);
187
188 return 1;
189 }
190
191 /* clear statistics */
193 if (res != 0)
194 {
195 as3935_interface_debug_print("as3935: set clear statistics failed.\n");
196 (void)as3935_deinit(&gs_handle);
197
198 return 1;
199 }
200
201 /* clear statistics */
203 if (res != 0)
204 {
205 as3935_interface_debug_print("as3935: set clear statistics failed.\n");
206 (void)as3935_deinit(&gs_handle);
207
208 return 1;
209 }
210
211 /* clear statistics */
213 if (res != 0)
214 {
215 as3935_interface_debug_print("as3935: set clear statistics failed.\n");
216 (void)as3935_deinit(&gs_handle);
217
218 return 1;
219 }
220
221 /* set default afe gain */
223 if (res != 0)
224 {
225 as3935_interface_debug_print("as3935: set afe gain boost failed.\n");
226 (void)as3935_deinit(&gs_handle);
227
228 return 1;
229 }
230
231 /* set default noise floor level */
233 if (res != 0)
234 {
235 as3935_interface_debug_print("as3935: set noise floor level failed.\n");
236 (void)as3935_deinit(&gs_handle);
237
238 return 1;
239 }
240
241 /* set default watchdog threshold */
243 if (res != 0)
244 {
245 as3935_interface_debug_print("as3935: set watchdog threshold failed.\n");
246 (void)as3935_deinit(&gs_handle);
247
248 return 1;
249 }
250
251 /* set default lightning min number */
253 if (res != 0)
254 {
255 as3935_interface_debug_print("as3935: set lightning min number failed.\n");
256 (void)as3935_deinit(&gs_handle);
257
258 return 1;
259 }
260
261 /* set default spike rejection */
263 if (res != 0)
264 {
265 as3935_interface_debug_print("as3935: set spike rejection failed.\n");
266 (void)as3935_deinit(&gs_handle);
267
268 return 1;
269 }
270
271 /* set default frequency division ration */
273 if (res != 0)
274 {
275 as3935_interface_debug_print("as3935: set frequency division ration failed.\n");
276 (void)as3935_deinit(&gs_handle);
277
278 return 1;
279 }
280
281 /* set default mask disturber */
283 if (res != 0)
284 {
285 as3935_interface_debug_print("as3935: set mask disturber failed.\n");
286 (void)as3935_deinit(&gs_handle);
287
288 return 1;
289 }
290
291 /* convert cap */
293 if (res != 0)
294 {
295 as3935_interface_debug_print("as3935: internal tuning capacitor convert to register failed.\n");
296 (void)as3935_deinit(&gs_handle);
297
298 return 1;
299 }
300
301 /* set internal tuning capacitor */
302 res = as3935_set_internal_tuning_capacitor(&gs_handle, cap);
303 if (res != 0)
304 {
305 as3935_interface_debug_print("as3935: set internal tuning capacitor failed.\n");
306 (void)as3935_deinit(&gs_handle);
307
308 return 1;
309 }
310
311 return 0;
312}
313
322{
323 /* power down */
324 if (as3935_set_power_down(&gs_handle, AS3935_BOOL_TRUE) != 0)
325 {
326 return 1;
327 }
328
329 /* deinit */
330 if (as3935_deinit(&gs_handle) != 0)
331 {
332 return 1;
333 }
334
335 return 0;
336}
337
347{
348 /* read */
349 if (as3935_read_single_lightning_energy(&gs_handle, energy) != 0)
350 {
351 return 1;
352 }
353
354 return 0;
355}
356
365uint8_t as3935_basic_read_distance(int8_t *km)
366{
367 uint8_t raw;
368
369 /* read */
370 if (as3935_read_distance(&gs_handle, &raw, km) != 0)
371 {
372 return 1;
373 }
374
375 return 0;
376}
377
386{
387 /* clear statistics */
388 if (as3935_set_clear_statistics(&gs_handle, AS3935_BOOL_TRUE) != 0)
389 {
390 return 1;
391 }
392
393 /* clear statistics */
395 {
396 return 1;
397 }
398
399 /* clear statistics */
400 if (as3935_set_clear_statistics(&gs_handle, AS3935_BOOL_TRUE) != 0)
401 {
402 return 1;
403 }
404
405 return 0;
406}
driver as3935 basic header file
uint8_t as3935_set_frequency_division_ration(as3935_handle_t *handle, as3935_frequency_division_ration_t division)
set frequency division ration
uint8_t as3935_set_interface(as3935_handle_t *handle, as3935_interface_t interface)
set the chip interface
uint8_t as3935_set_clear_statistics(as3935_handle_t *handle, as3935_bool_t enable)
enable or disable clear statistics
uint8_t as3935_set_power_down(as3935_handle_t *handle, as3935_bool_t enable)
set power down
uint8_t as3935_set_watchdog_threshold(as3935_handle_t *handle, uint8_t threshold)
set watchdog threshold
uint8_t as3935_set_spike_rejection(as3935_handle_t *handle, uint8_t rejection)
set spike rejection
uint8_t as3935_internal_tuning_capacitor_convert_to_register(as3935_handle_t *handle, float pf, uint8_t *reg)
convert the internal tuning capacitor to the register raw data
uint8_t as3935_set_noise_floor_level(as3935_handle_t *handle, as3935_noise_floor_level_t level)
set noise floor level
uint8_t as3935_set_calibrate_rc_osc(as3935_handle_t *handle)
calibrate rc osc
uint8_t as3935_deinit(as3935_handle_t *handle)
close the chip
uint8_t as3935_set_afe_gain_boost(as3935_handle_t *handle, as3935_afe_gain_t gain)
set afe gain boost
uint8_t as3935_read_single_lightning_energy(as3935_handle_t *handle, uint32_t *energy)
read single lightning energy
as3935_address_t
as3935 address enumeration definition
as3935_interface_t
as3935 interface enumeration definition
uint8_t as3935_set_mask_disturber(as3935_handle_t *handle, as3935_bool_t enable)
enable or disable mask disturber
uint8_t as3935_set_internal_tuning_capacitor(as3935_handle_t *handle, uint8_t cap)
set internal tuning capacitor
uint8_t as3935_init(as3935_handle_t *handle)
initialize the chip
struct as3935_handle_s as3935_handle_t
as3935 handle structure definition
uint8_t as3935_set_lightning_min_number(as3935_handle_t *handle, as3935_lightning_min_number_t number)
set lightning min number
uint8_t as3935_set_addr_pin(as3935_handle_t *handle, as3935_address_t addr_pin)
set the iic address pin
uint8_t as3935_set_system_rc_osc_display_on_irq(as3935_handle_t *handle, as3935_bool_t enable)
enable or disable system rc osc display on irq
uint8_t as3935_read_distance(as3935_handle_t *handle, uint8_t *raw, int8_t *km)
read distance
uint8_t as3935_set_lc_osc_display_on_irq(as3935_handle_t *handle, as3935_bool_t enable)
enable or disable lc osc display on irq
uint8_t as3935_irq_handler(as3935_handle_t *handle)
irq handler
uint8_t as3935_reset_default(as3935_handle_t *handle)
reset to default
uint8_t as3935_set_timer_rc_osc_display_on_irq(as3935_handle_t *handle, as3935_bool_t enable)
enable or disable timer rc osc display on irq
@ AS3935_BOOL_FALSE
@ AS3935_BOOL_TRUE
#define AS3935_BASIC_DEFAULT_LIGHTNING_MIN_NUMBER
uint8_t as3935_basic_clear_statistics(void)
basic example clear statistics
uint8_t as3935_basic_read_single_lightning_energy(uint32_t *energy)
basic example read single lightning energy
uint8_t as3935_basic_read_distance(int8_t *km)
basic example read distance
#define AS3935_BASIC_DEFAULT_FREQUENCY_DIVISION_RATION
uint8_t as3935_basic_irq_handler(void)
basic irq handler
uint8_t as3935_basic_init(as3935_interface_t interface, as3935_address_t addr_pin, void(*callback)(uint8_t type))
basic example init
uint8_t as3935_basic_deinit(void)
basic example deinit
#define AS3935_BASIC_DEFAULT_NOISE_FLOOR_LEVEL
#define AS3935_BASIC_DEFAULT_MASK_DISTURBER
#define AS3935_BASIC_DEFAULT_SPIKE_REJECTION
#define AS3935_BASIC_DEFAULT_AFE_GAIN
as3935 basic example default definition
#define AS3935_BASIC_DEFAULT_CAP
#define AS3935_BASIC_DEFAULT_WATCHDOG_THRESHOLD
void as3935_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t as3935_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void as3935_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t as3935_interface_iic_deinit(void)
interface iic bus deinit
uint8_t as3935_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t as3935_interface_iic_init(void)
interface iic bus init
uint8_t as3935_interface_spi_init(void)
interface spi bus init
uint8_t as3935_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
uint8_t as3935_interface_spi_deinit(void)
interface spi bus deinit
uint8_t as3935_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write