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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* <rc/led.h>
*
* @brief Control the LEDs on Robotics Cape and BeagleBone Blue.
*
* @author James Strawson
* @date 1/31/2018
*
* @addtogroup LED
* @{
*/
#ifndef RC_LED_H
#define RC_LED_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Availabe LEDs on the BeagleBone platform.
*
* This list may expand for future boards. Note that the WIFI and USR LEDs are
* normally controlled by separate processes. They can be controlled, but may
* conflict as other processes continue to try to write to them simultaneously.
*
* The BAT LED's are controlled by the rc_battery_monitor service. If you want
* to control these LEDs yourself please stop the service first.
*
* ```bash
* sudo systemctl stop rc_battery_monitor
* sudo systemctl disable rc_battery_monitor
* ```
*/
typedef enum rc_led_t{
RC_LED_GREEN,
RC_LED_RED,
RC_LED_USR0,
RC_LED_USR1,
RC_LED_USR2,
RC_LED_USR3,
RC_LED_BAT25,
RC_LED_BAT50,
RC_LED_BAT75,
RC_LED_BAT100,
RC_LED_WIFI
} rc_led_t;
/**
* @brief sets the state of an LED
*
* @param[in] led rc_led_t enum
* @param[in] value 0 for OFF, non-zero for ON
*
* @return 0 on success, -1 on failure
*/
int rc_led_set(rc_led_t led, int value);
/**
* @brief closes file descriptors to all opened LEDs
*
* This does NOT turn off the LEDs, it is up to the user to leave the LEDs in
* the desired state before closing.
*/
void rc_led_cleanup(void);
/**
* @brief gets the current state of an LED
*
* @param[in] led rc_led_t enum
*
* @return 0 if off, 1 if on, -1 on error
*/
int rc_led_get(rc_led_t led);
/**
* @brief blinks an led at specified frequency and duration.
*
* This is a blocking function call, it does not return until either the
* specified duration has completed or rc_led_stop_blink has been called from
* another thread.
*
* @param[in] led rc_led_t enum
* @param[in] hz blink frequency in HZ
* @param[in] duration blink duration in seconds
*
* @return 0 on success, -1 on error, 1 if function exited prematurely.
*/
int rc_led_blink(rc_led_t led, float hz, float duration);
/**
* @brief Stops an LED from blinking.
*
* Since rc_led_blink is a blocking function, it's obviously necessary to call
* rc_led_stop_blink from a separate thread or signal handler. This will cause
* rc_led_blink to return 1 if blinking was stopped mid-way. Also see
* rc_led_stop_blink_all
*
* @param[in] led rc_led_t enum
*/
void rc_led_stop_blink(rc_led_t led);
/**
* @brief stops all LEDs from blinking
*
* Since rc_led_blink is a blocking function, it's obviously necessary to call
* rc_led_stop_blink from a separate thread or signal handler. This will cause
* rc_led_blink to return 1 if blinking was stopped mid-way.
*/
void rc_led_stop_blink_all(void);
#ifdef __cplusplus
}
#endif
#endif // RC_LED_H
/** @} end group LED */