-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
93 lines (73 loc) · 2.49 KB
/
main.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
#include "main.h"
//TODO
//Define better non blocking sleep function
// Initialize the variables here
struct bmp180_model my_bmp180;
struct bmp180_calib_param my_bmp180_calib_params;
struct bmp180_measurements my_bmp180_measurements;
struct bme280_model my_bme280;
struct bme280_calib_param my_bme280_calib_params;
struct bme280_settings my_bme280_settings;
struct bme280_measurements my_bme280_measurements;
struct lcb16b_eeprom my_eeprom;
void toggle_led(uint8_t* led_state) {
//Update the passed state
*led_state = (*led_state+1)%2;
//Update the current LED
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, *led_state);
}
// Main init function to initialize all periphirals on program start
void program_init(){
// Initialize all standard stdio types linked with binary.
stdio_init_all();
// Initialize cyw43 module to allow us to blink the onboard LED.
if (cyw43_arch_init()) {
printf("WiFi init failed");
return;
}
printf("CYW43 WiFi init success");
//Init I2C
global_i2c_init();
//Init BMP180
bmp180_init(&my_bmp180, &my_bmp180_calib_params, &my_bmp180_measurements);
//Init BME280
bme280_init(&my_bme280, &my_bme280_calib_params, &my_bme280_settings, &my_bme280_measurements);
//Init the eeprom
lcb16b_eeprom_init(&my_eeprom);
//Init the RTC
init_pico_rtc(&my_datetime);
//Init the com protocol
com_protocol_init();
}
int main() {
//Init stuff
program_init();
// Holds the current state of the blink
uint8_t LED_STATE = 0;
// Allocate some space to store a queue entry
queue_entry_t call_queue_entry;
// Main stuff....
while (true) {
sleep_ms(2000);
toggle_led(&LED_STATE);
// Execute anything that might be en the queue
// Check if any entry exists in the result queue
if (queue_is_empty(&call_queue))
{
// Empty. For debugging tell me
#if MAIN_DEBUG
printf("Call queue is empty.\r\n");
#endif
}
else{
// Read in the function and input from stdin
queue_remove_blocking(&call_queue, &call_queue_entry);
void (*stdin_func)() = (void(*)())(call_queue_entry.func);
void *std_in_value = call_queue_entry.data ;
// Execute the function
(*stdin_func)(std_in_value);
// Add response to the result queue (stdout)
int res = stdout_selector(call_queue_entry.func);
}
}
}