From: Nathael Pajani Date: Thu, 24 Sep 2020 11:15:30 +0000 (+0200) Subject: Add movement detection sensor to CPE IoT app X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=1e62183d94af131afd14e42814ac81fb1a58b43a;p=soft%2Fperso%2Fcpe Add movement detection sensor to CPE IoT app --- diff --git a/projet_cpe_iot/main.c b/projet_cpe_iot/main.c index 490635e..2bfa0fe 100644 --- a/projet_cpe_iot/main.c +++ b/projet_cpe_iot/main.c @@ -80,6 +80,10 @@ const struct pio_config common_pins[] = { { LPC_ADC_AD0_PIO_0_30, LPC_IO_ANALOG }, { LPC_ADC_AD1_PIO_0_31, LPC_IO_ANALOG }, { LPC_ADC_AD2_PIO_1_0, LPC_IO_ANALOG }, + /* GPIO */ + { LPC_GPIO_0_0, LPC_IO_DIGITAL }, + { LPC_GPIO_0_23, LPC_IO_DIGITAL }, + { LPC_GPIO_0_24, LPC_IO_DIGITAL }, ARRAY_LAST_PIO, }; @@ -88,7 +92,11 @@ const struct pio cc1101_miso_pin = LPC_SSP0_MISO_PIO_0_16; const struct pio cc1101_gdo0 = LPC_GPIO_0_6; const struct pio cc1101_gdo2 = LPC_GPIO_0_7; +const struct pio move_detect = LPC_GPIO_0_0; const struct pio temp_alert = LPC_GPIO_0_3; +const struct pio move_led_green = LPC_GPIO_0_24; +const struct pio move_led_red = LPC_GPIO_0_23; + const struct pio status_led_green = LPC_GPIO_0_28; const struct pio status_led_red = LPC_GPIO_0_29; @@ -99,10 +107,16 @@ const struct pio status_led_red = LPC_GPIO_0_29; #define ADC_EXT2 LPC_ADC(2) /***************************************************************************** */ +const struct wdt_config wdconf = { + .clk_sel = WDT_CLK_IRC, + .intr_mode_only = 0, + .nb_clk = 0x03FFFFFF, /* 0x3FF to 0x03FFFFFF */ +}; + void system_init() { - /* Stop the watchdog */ - startup_watchdog_disable(); /* Do it right now, before it gets a chance to break in */ + /* Configure the watchdog */ + watchdog_config(&wdconf); system_set_default_power_state(); clock_config(SELECTED_FREQ); set_pins(common_pins); @@ -283,7 +297,7 @@ void bme_config(int uart_num) } } -void bme_display(int uart_num, uint32_t* pressure, uint32_t* temp, uint16_t* humidity) +void bme_display(int uart_num, uint32_t* pressure, int32_t* temp, uint16_t* humidity) { int ret = 0; @@ -343,6 +357,29 @@ void uv_display(int uart_num, uint16_t* uv_raw) } +/******************************************************************************/ +/* Movement detector */ +static volatile int move_detected = 0; +void mdet_callback(uint32_t gpio) +{ + move_detected = 1; + if (gpio_read(move_detect) == 0) { + gpio_set(move_led_green); + gpio_clear(move_led_red); + } else { + gpio_set(move_led_red); + gpio_clear(move_led_green); + } +} + +int mdet_config(int uart_num) +{ + set_gpio_callback(mdet_callback, &move_detect, EDGES_BOTH); + config_gpio(&move_led_red, 0, GPIO_DIR_OUT, 0); + config_gpio(&move_led_green, 0, GPIO_DIR_OUT, 0); + return 0; +} + /******************************************************************************/ /* RF Communication */ @@ -495,6 +532,7 @@ int main(void) bme_config(UART0); uv_config(UART0); lux_config(UART0); + mdet_config(UART0); /* Add periodic handler */ add_systick_callback(periodic_display, 1000); @@ -509,7 +547,17 @@ int main(void) adc_start_convertion_once(ADC_VBAT, LPC_ADC_SEQ(0), 0); /* Tell we are alive :) */ - chenillard(250); + watchdog_feed(); + chenillard(100); + + /* Move detected ! */ + if (move_detected == 1) { + /* FIXME : Send info on RF */ + memcpy((void*)cc_tx_buff, "Move detected\n", 14); + cc_ptr = 14; + cc_tx = 1; + uprintf(UART0, "Move detected\n"); + } /* RF */ if (cc_tx == 1) { @@ -540,7 +588,8 @@ int main(void) /* Display */ if (update_display == 1) { uint16_t uv = 0, ir = 0, humidity = 0; - uint32_t pressure = 0, temp = 0, lux = 0; + uint32_t pressure = 0, lux = 0; + int32_t temp = 0; int deci_degrees = 0; char data[20]; @@ -572,6 +621,10 @@ int main(void) } update_display = 0; } + + if (move_detected == 1) { + move_detected = 0; + } } return 0; }