/
util.h
61 lines (51 loc) · 1.97 KB
/
util.h
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
/**
* @file util.h
* @author paul
* @date 24.02.19
* @brief several utility functions used for io
*/
#ifndef ARDF_FIRMWARE_UTIL_H
#define ARDF_FIRMWARE_UTIL_H
#include <stdint.h>
#include <stdbool.h>
/*
* To decrease the write cycles on the eeprom it is of great importance to remove all noise
* from the analogue measurements. This modules applies an low pass (using exponential smoothing)
* and then quantizes the measured value using a fixed number of steps. This value is filtered using
* a multivalue schmitt-trigger.
*/
typedef struct {
uint8_t steps;
uint8_t val;
uint16_t _mem;
uint8_t low_pass_weight;
uint16_t max_val;
} util_quantized_low_pass_t;
/**
** Generate an quantized_low_pass_t object from a given set of parameters.
* @param steps the number of steps to use
* @param low_pass_weight the 1-alpha value used in exponential smoothing
* @param max_val the maximum measured value (2^Resolution)
* @return an quantized_low_pass_t object
*/
util_quantized_low_pass_t util_init_quantizized_low_pass(uint8_t steps, uint8_t low_pass_weight,
uint16_t max_val);
/**
* Add a new measurement to the filter. This calculates the filtered step ans returns it.
* @param quantizized_low_pass the object generated by the init function
* @param measurement the new measured value
* @return the estimated step.
*/
uint8_t util_add_new_measurent(util_quantized_low_pass_t* quantizized_low_pass, uint16_t measurement);
/**
* Modulates the morse code using the send_en pin, this sends the same signal to led1
* @param c the character, if this is not an alphabetic character nothing will be send
* @param output_func a functor which accepts a boolean and sets an output
*/
void util_send_char(char c, void (*output_func)(bool));
/**
* This measures the battery, calculates the voltage and filters it using a low pass filter.
* @return the voltage in milli volt at the battery
*/
uint16_t util_battery_voltage_milli_volt(void);
#endif //ARDF_FIRMWARE_UTIL_H