-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsensor.h
More file actions
45 lines (33 loc) · 941 Bytes
/
sensor.h
File metadata and controls
45 lines (33 loc) · 941 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
#ifndef SENSOR_H
#define SENSOR_H
#include <stdint.h>
#include <stdbool.h>
// Sensor states
typedef enum {
SENSOR_NO_OBJECT,
SENSOR_OBJECT_DETECTED,
SENSOR_STABLE
} sensor_state_t;
// Sensor reading structure
typedef struct {
sensor_state_t state;
bool current_reading;
bool last_reading;
uint32_t detection_start_time;
uint32_t detection_end_time;
bool object_present;
uint32_t debounce_counter;
} sensor_t;
// Initialize sensor
void sensor_init(sensor_t *sensor);
// Read sensor input (digital HIGH/LOW)
bool sensor_read(sensor_t *sensor);
// Check if object is detected (with debouncing)
bool sensor_is_object_detected(sensor_t *sensor);
// Update sensor state
void sensor_update(sensor_t *sensor, uint32_t current_time);
// Get sensor state
sensor_state_t sensor_get_state(sensor_t *sensor);
// Reset sensor detection timestamps
void sensor_reset(sensor_t *sensor);
#endif // SENSOR_H