cleaned project, added a first working version of the bootloader
This commit is contained in:
52
src/main.c
52
src/main.c
@@ -12,7 +12,7 @@
|
||||
#include "actuator.h"
|
||||
#include "battery_adc.h"
|
||||
#include "temperature.h"
|
||||
#include "timer_count.h" // your custom measurement driver
|
||||
#include "timer_count.h" // your custom measurement driver
|
||||
|
||||
const struct device *const dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
|
||||
|
||||
@@ -21,7 +21,8 @@ int main(void)
|
||||
int ret;
|
||||
|
||||
/* Init USB */
|
||||
if (usb_enable(NULL)) {
|
||||
if (usb_enable(NULL))
|
||||
{
|
||||
printk("USB init failed\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -31,16 +32,18 @@ int main(void)
|
||||
button_init();
|
||||
digital_out_init();
|
||||
ret = battery_adc_init();
|
||||
if (ret < 0) {
|
||||
if (ret < 0)
|
||||
{
|
||||
printk("Battery ADC init failed (%d)\n", ret);
|
||||
}
|
||||
ret = temperature_init();
|
||||
if (ret < 0) {
|
||||
if (ret < 0)
|
||||
{
|
||||
printk("Temperature init failed (%d)\n", ret);
|
||||
}
|
||||
|
||||
configure_measurement();
|
||||
make_measurement();
|
||||
make_measurement();
|
||||
|
||||
/* Start blinking LED0 every 1s */
|
||||
led_start_blink(0, 1000);
|
||||
@@ -48,27 +51,34 @@ int main(void)
|
||||
int old_val = 1;
|
||||
int out_en = 1;
|
||||
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
/* --- Battery measurement --- */
|
||||
int32_t batt_mv;
|
||||
ret = battery_measure_mv(&batt_mv);
|
||||
if (ret == 0) {
|
||||
if (ret == 0)
|
||||
{
|
||||
printk("Battery: %d mV ", batt_mv);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
printk("Battery measurement failed (%d) ", ret);
|
||||
}
|
||||
|
||||
/* --- Temperature measurement --- */
|
||||
int32_t temp_c;
|
||||
ret = temperature_get_celsius(&temp_c);
|
||||
if (ret == 0) {
|
||||
if (ret == 0)
|
||||
{
|
||||
printk("Temperature: %d C ", temp_c);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
printk("Temperature read failed (%d) ", ret);
|
||||
}
|
||||
|
||||
int32_t humidity_meas = read_measurement();
|
||||
if( humidity_meas >= 0)
|
||||
if (humidity_meas >= 0)
|
||||
{
|
||||
printk("humidity_raw: %d\n", humidity_meas);
|
||||
make_measurement();
|
||||
@@ -76,20 +86,26 @@ int main(void)
|
||||
|
||||
/* --- Button handling --- */
|
||||
int val = button_read();
|
||||
if (val < 0) {
|
||||
if (val < 0)
|
||||
{
|
||||
printk("Error reading button\n");
|
||||
} else if (val == 0) {
|
||||
if (old_val != val) {
|
||||
}
|
||||
else if (val == 0)
|
||||
{
|
||||
if (old_val != val)
|
||||
{
|
||||
out_en = !out_en;
|
||||
digital_out_toggle_do1();
|
||||
digital_out_toggle_do2();
|
||||
digital_out_toggle_do_en();
|
||||
led_toggle(1); // toggle LED1 on press
|
||||
led_toggle(1); // toggle LED1 on press
|
||||
old_val = val;
|
||||
|
||||
}
|
||||
} else {
|
||||
if (old_val != val) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (old_val != val)
|
||||
{
|
||||
old_val = val;
|
||||
}
|
||||
printk("Button released\n");
|
||||
|
||||
Reference in New Issue
Block a user