libwebsockets
Lightweight C library for HTML5 websockets
Toggle main menu visibility
Loading...
Searching...
No Matches
lws-led.h
Go to the documentation of this file.
1
/*
2
* Generic LED controller ops
3
*
4
* Copyright (C) 2019 - 2020 Andy Green <andy@warmcat.com>
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining a copy
7
* of this software and associated documentation files (the "Software"), to
8
* deal in the Software without restriction, including without limitation the
9
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
* sell copies of the Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
12
*
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
15
*
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
* IN THE SOFTWARE.
23
*
24
* This is like an abstract class for leds, a real implementation provides
25
* functions for the ops that use the underlying, eg, OS gpio arrangements.
26
*/
27
28
/* only b15 significant for GPIO */
29
typedef
uint16_t
lws_led_intensity_t
;
30
typedef
uint16_t
lws_led_seq_phase_t
;
31
32
/* the normalized max intensity */
33
#define LWS_LED_MAX_INTENSITY (0xffff)
34
35
/* the normalized 360 degree phase count for intensity functions */
36
#define LWS_LED_FUNC_PHASE 65536
37
/* used when the sequence doesn't stop by itself and goes around forever */
38
#define LWS_SEQ_LEDPHASE_TOTAL_ENDLESS (-1)
39
40
#define LWS_LED_SEQUENCER_UPDATE_INTERVAL_MS 33
41
42
struct
lws_led_state;
/* opaque */
43
struct
lws_pwm_ops
;
/* forward ref */
44
45
typedef
lws_led_intensity_t
(*
lws_led_lookup_t
)(
lws_led_seq_phase_t
ph);
46
47
typedef
struct
lws_led_sequence_def_t
{
48
lws_led_lookup_t
func
;
49
lws_led_seq_phase_t
ledphase_offset
;
50
int
ledphase_total
;
/* 65536= one cycle */
51
uint16_t
ms
;
52
uint8_t
flags
;
53
}
lws_led_sequence_def_t
;
54
55
enum
{
56
LLSI_CURR
,
57
LLSI_NEXT
,
58
LLSI_TRANS
59
};
60
61
typedef
struct
lws_led_state_ch
62
{
63
const
lws_led_sequence_def_t
*
seq
;
/* NULL = inactive */
64
lws_led_seq_phase_t
ph
;
65
lws_led_seq_phase_t
step
;
66
int
phase_budget
;
67
lws_led_intensity_t
last
;
71
}
lws_led_state_ch_t
;
72
73
typedef
struct
lws_led_state_chs
74
{
75
lws_led_state_ch_t
seqs
[3];
76
}
lws_led_state_chs_t
;
77
78
/* this should always be first in the subclassed implementation types */
79
80
typedef
struct
lws_led_ops
{
81
void (*
intensity
)(
const
struct
lws_led_ops
*lo,
const
char
*name,
82
lws_led_intensity_t
inten);
84
struct
lws_led_state * (*create)(
const
struct
lws_led_ops
*led_ops);
85
void (*
destroy
)(
struct
lws_led_state *);
86
}
lws_led_ops_t
;
87
88
typedef
struct
lws_led_gpio_map
{
89
const
char
*
name
;
90
_lws_plat_gpio_t
gpio
;
91
lws_led_lookup_t
intensity_correction
;
97
const
struct
lws_pwm_ops
*
pwm_ops
;
100
uint8_t
active_level
;
101
}
lws_led_gpio_map_t
;
102
103
typedef
struct
lws_led_gpio_controller
{
104
const
lws_led_ops_t
led_ops
;
105
106
const
lws_gpio_ops_t
*
gpio_ops
;
107
const
lws_led_gpio_map_t
*
led_map
;
108
uint8_t
count_leds
;
109
}
lws_led_gpio_controller_t
;
110
111
/* ops */
112
113
LWS_VISIBLE
LWS_EXTERN
struct
lws_led_state *
114
lws_led_gpio_create
(
const
lws_led_ops_t
*led_ops);
115
116
LWS_VISIBLE
LWS_EXTERN
void
117
lws_led_gpio_destroy
(
struct
lws_led_state *lcs);
118
130
LWS_VISIBLE
LWS_EXTERN
void
131
lws_led_gpio_intensity
(
const
struct
lws_led_ops
*lo,
const
char
*name,
132
lws_led_intensity_t
inten);
133
134
LWS_VISIBLE
LWS_EXTERN
int
135
lws_led_transition
(
struct
lws_led_state *lcs,
const
char
*name,
136
const
lws_led_sequence_def_t
*next,
137
const
lws_led_sequence_def_t
*trans);
138
139
140
#define lws_led_gpio_ops \
141
{ \
142
.create = lws_led_gpio_create, \
143
.destroy = lws_led_gpio_destroy, \
144
.intensity = lws_led_gpio_intensity, \
145
}
146
uint16_t
unsigned short uint16_t
Definition
libwebsockets.h:698
LWS_EXTERN
#define LWS_EXTERN
Definition
libwebsockets.h:296
uint8_t
unsigned char uint8_t
Definition
libwebsockets.h:699
LWS_VISIBLE
#define LWS_VISIBLE
Definition
libwebsockets.h:291
lws_gpio_ops_t
struct lws_gpio_ops lws_gpio_ops_t
_lws_plat_gpio_t
int _lws_plat_gpio_t
Definition
lws-gpio.h:31
lws_led_gpio_destroy
LWS_VISIBLE LWS_EXTERN void lws_led_gpio_destroy(struct lws_led_state *lcs)
LLSI_CURR
@ LLSI_CURR
Definition
lws-led.h:56
LLSI_NEXT
@ LLSI_NEXT
Definition
lws-led.h:57
LLSI_TRANS
@ LLSI_TRANS
Definition
lws-led.h:58
lws_led_gpio_controller::led_ops
const lws_led_ops_t led_ops
Definition
lws-led.h:104
lws_led_state_chs::seqs
lws_led_state_ch_t seqs[3]
Definition
lws-led.h:75
lws_led_gpio_controller::led_map
const lws_led_gpio_map_t * led_map
Definition
lws-led.h:107
lws_led_gpio_map::active_level
uint8_t active_level
Definition
lws-led.h:100
lws_led_state_ch::seq
const lws_led_sequence_def_t * seq
Definition
lws-led.h:63
lws_led_state_ch::step
lws_led_seq_phase_t step
Definition
lws-led.h:65
lws_led_seq_phase_t
uint16_t lws_led_seq_phase_t
Definition
lws-led.h:30
lws_led_sequence_def_t::ms
uint16_t ms
Definition
lws-led.h:51
lws_led_sequence_def_t::ledphase_total
int ledphase_total
Definition
lws-led.h:50
lws_led_gpio_controller::gpio_ops
const lws_gpio_ops_t * gpio_ops
Definition
lws-led.h:106
lws_led_state_ch::phase_budget
int phase_budget
Definition
lws-led.h:66
lws_led_gpio_map::intensity_correction
lws_led_lookup_t intensity_correction
Definition
lws-led.h:91
lws_led_gpio_create
LWS_VISIBLE LWS_EXTERN struct lws_led_state * lws_led_gpio_create(const lws_led_ops_t *led_ops)
lws_led_gpio_intensity
LWS_VISIBLE LWS_EXTERN void lws_led_gpio_intensity(const struct lws_led_ops *lo, const char *name, lws_led_intensity_t inten)
lws_led_intensity_t
uint16_t lws_led_intensity_t
Definition
lws-led.h:29
lws_led_gpio_controller::count_leds
uint8_t count_leds
Definition
lws-led.h:108
lws_led_sequence_def_t::flags
uint8_t flags
Definition
lws-led.h:52
lws_led_ops_t
struct lws_led_ops lws_led_ops_t
lws_led_gpio_map_t
struct lws_led_gpio_map lws_led_gpio_map_t
lws_led_gpio_controller_t
struct lws_led_gpio_controller lws_led_gpio_controller_t
lws_led_sequence_def_t::ledphase_offset
lws_led_seq_phase_t ledphase_offset
Definition
lws-led.h:49
lws_led_state_ch::ph
lws_led_seq_phase_t ph
Definition
lws-led.h:64
lws_led_state_ch_t
struct lws_led_state_ch lws_led_state_ch_t
lws_led_sequence_def_t::func
lws_led_lookup_t func
Definition
lws-led.h:48
lws_led_gpio_map::name
const char * name
Definition
lws-led.h:89
lws_led_gpio_map::gpio
_lws_plat_gpio_t gpio
Definition
lws-led.h:90
lws_led_state_ch::last
lws_led_intensity_t last
Definition
lws-led.h:67
lws_led_transition
LWS_VISIBLE LWS_EXTERN int lws_led_transition(struct lws_led_state *lcs, const char *name, const lws_led_sequence_def_t *next, const lws_led_sequence_def_t *trans)
lws_led_gpio_map::pwm_ops
const struct lws_pwm_ops * pwm_ops
Definition
lws-led.h:97
lws_led_state_chs_t
struct lws_led_state_chs lws_led_state_chs_t
lws_led_lookup_t
lws_led_intensity_t(* lws_led_lookup_t)(lws_led_seq_phase_t ph)
Definition
lws-led.h:45
lws_led_gpio_controller
Definition
lws-led.h:103
lws_led_gpio_map
Definition
lws-led.h:88
lws_led_sequence_def_t
Definition
lws-led.h:47
lws_led_state_ch
Definition
lws-led.h:62
lws_led_state_chs
Definition
lws-led.h:74
lws_led_ops
Definition
lws-led.h:80
lws_led_ops::destroy
void(* destroy)(struct lws_led_state *)
Definition
lws-led.h:85
lws_led_ops::intensity
void(* intensity)(const struct lws_led_ops *lo, const char *name, lws_led_intensity_t inten)
Definition
lws-led.h:81
lws_pwm_ops
Definition
lws-pwm.h:31
include
libwebsockets
lws-led.h
Generated on
for libwebsockets by
1.18.0