amelioration pir
This commit is contained in:
parent
7c7d298af1
commit
ad4cd34559
37
main/main.c
37
main/main.c
@ -242,7 +242,11 @@ void alloc_fail(size_t size, uint32_t caps, const char * function_name){
|
||||
|
||||
}
|
||||
static QueueHandle_t gpio_evt_queue = NULL;
|
||||
esp_timer_handle_t periodic_timer;
|
||||
// Durée pour l'arret automatique (micro-secondes ^^)
|
||||
uint64_t arretAuto=5*60*1000*1000;
|
||||
bool ecranEteint=true;
|
||||
// Ce timer permet d'eteindre l'ecran "arretAuto" apres la derniere présence détectée
|
||||
esp_timer_handle_t presence_timer;
|
||||
|
||||
static void IRAM_ATTR gpio_isr_handler(void* arg)
|
||||
{
|
||||
@ -257,16 +261,23 @@ static void gpio_task_example(void* arg)
|
||||
for (;;) {
|
||||
if (xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
|
||||
ESP_LOGE(TAG,"Got it !");
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
bsp_display_brightness_set(i);
|
||||
vTaskDelay(delay/portTICK_PERIOD_MS);
|
||||
if(ecranEteint){
|
||||
if(bsp_display_lock(0)){
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
bsp_display_brightness_set(i);
|
||||
vTaskDelay(delay/portTICK_PERIOD_MS);
|
||||
}
|
||||
bsp_display_unlock();
|
||||
ecranEteint=false;
|
||||
}
|
||||
}else{
|
||||
ESP_LOGI(TAG, "Ecran déjà allumé");
|
||||
}
|
||||
//On arrete le timer de presence
|
||||
esp_timer_stop(periodic_timer);
|
||||
esp_timer_stop(presence_timer);
|
||||
//Pour le redemarrer
|
||||
ESP_ERROR_CHECK(esp_timer_start_once(periodic_timer, 10*1000*1000));
|
||||
|
||||
ESP_ERROR_CHECK(esp_timer_start_once(presence_timer, arretAuto));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -290,8 +301,8 @@ void initPirSensor(){
|
||||
|
||||
}
|
||||
|
||||
/* Ce timer permet d'eteindre l'ecran apres 30s de présence*/
|
||||
static void periodic_timer_callback(void* arg)
|
||||
/* Ce timer permet d'eteindre l'ecran apres @arretAuto de présence*/
|
||||
static void presence_timer_callback(void* arg)
|
||||
{
|
||||
int64_t time_since_boot = esp_timer_get_time();
|
||||
if(bsp_display_lock(0)){
|
||||
@ -401,13 +412,13 @@ static httpd_handle_t start_webserver(void) {
|
||||
void app_main(void)
|
||||
{
|
||||
const esp_timer_create_args_t periodic_timer_args = {
|
||||
.callback = &periodic_timer_callback,
|
||||
.callback = &presence_timer_callback,
|
||||
/* name is optional, but may help identify the timer when debugging */
|
||||
.name = "presence"
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_timer_create(&periodic_timer_args, &periodic_timer));
|
||||
ESP_ERROR_CHECK(esp_timer_create(&periodic_timer_args, &presence_timer));
|
||||
/* Start the timers */
|
||||
ESP_ERROR_CHECK(esp_timer_start_once(periodic_timer, 30*1000*1000));
|
||||
ESP_ERROR_CHECK(esp_timer_start_once(presence_timer, 30*1000*1000));
|
||||
|
||||
|
||||
initPirSensor();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user