-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsensor.c
More file actions
executable file
·45 lines (38 loc) · 867 Bytes
/
sensor.c
File metadata and controls
executable file
·45 lines (38 loc) · 867 Bytes
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
#include "c_types.h"
#include "osapi.h"
#include <stdbool.h>
#include "eagle_soc.h"
#include "gpio.h"
#include "ets_sys.h"
#include "user_interface.h"
#include "sensor.h"
#include "command.h"
#include "espmissingincludes.h"
/* en milisegundos */
#define READ_PERIOD 50
#define FAR_THRESHOLD 512
#define CLOSE_THRESHOLD 128
os_timer_t timer;
static void timer_cb(void *arg);
void ICACHE_FLASH_ATTR sensor_init(void)
{
}
void ICACHE_FLASH_ATTR sensor_start(void)
{
os_timer_disarm(&timer);
os_timer_setfn(&timer, timer_cb, NULL);
os_timer_arm(&timer, READ_PERIOD, true);
}
void ICACHE_FLASH_ATTR sensor_stop(void)
{
os_timer_disarm(&timer);
}
static void ICACHE_FLASH_ATTR timer_cb(void *arg)
{
uint16_t adc = system_adc_read();
if (adc > CLOSE_THRESHOLD)
command_touched();
else if (adc > FAR_THRESHOLD)
command_touched();
os_printf("%u\n", adc);
}