73 lines
1.6 KiB
C
73 lines
1.6 KiB
C
#include <stdint.h>
|
|
#include <zephyr/kernel.h>
|
|
#include <zephyr/sys/printk.h>
|
|
|
|
#include "epaper/epaper.h"
|
|
//#include "oled/oled.h"
|
|
|
|
#include "lora/lora.h"
|
|
|
|
#include "master/master.h"
|
|
|
|
#include "utils/buttons.h"
|
|
#include "utils/leds.h"
|
|
#include "utils/constAndVars.h"
|
|
|
|
struct k_work_delayable lora_check_work;
|
|
|
|
|
|
uint8_t init_led_and_button(void) {
|
|
uint8_t ret;
|
|
|
|
//if (!gpio_is_ready_dt(&led_green)) return -1;
|
|
//ret = gpio_pin_configure_dt(&led_green, GPIO_OUTPUT_INACTIVE);
|
|
//if (ret < 0) return ret;
|
|
|
|
if (!gpio_is_ready_dt(&button0)) return -1;
|
|
ret = gpio_pin_configure_dt(&button0, GPIO_INPUT);
|
|
if (ret < 0) return ret;
|
|
|
|
ret = gpio_pin_interrupt_configure_dt(&button0, GPIO_INT_EDGE_TO_ACTIVE);
|
|
if (ret < 0) return ret;
|
|
|
|
//gpio_init_callback(&button_cb_data, button_pressed, BIT(button.pin));
|
|
//gpio_add_callback(button.port, &button_cb_data);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void run_master(void) {
|
|
printk("Running as MASTER\n");
|
|
master_init();
|
|
// Master-spezifische Logik
|
|
}
|
|
|
|
int run_slave(void)
|
|
{
|
|
printk("Running as SLAVE\n");
|
|
if (init_led_and_button() != 0) {
|
|
printk("❌ GPIO-Initialisierung fehlgeschlagen\n");
|
|
error = true;
|
|
return -1;
|
|
}
|
|
|
|
epd_init();
|
|
|
|
lora_init();
|
|
|
|
while (1) {
|
|
k_sleep(K_SECONDS(1)); // Energiesparend schlafen
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void main(void) {
|
|
#if IS_ENABLED(CONFIG_DEVICE_MODE_MASTER)
|
|
run_master();
|
|
#elif IS_ENABLED(CONFIG_DEVICE_MODE_SLAVE)
|
|
run_slave();
|
|
#else
|
|
#error "No device mode selected. Please enable one mode in prj.conf or via build flags."
|
|
#endif
|
|
} |