MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / _led_write

Function _led_write

components/drivers/led/led.c:65–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65static rt_ssize_t _led_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
66{
67 rt_uint32_t brightness = 0;
68 const char *value = buffer;
69 struct rt_led_device *led = rt_container_of(dev, struct rt_led_device, parent);
70
71 for (int i = 0; i < RT_ARRAY_SIZE(_led_states); ++i)
72 {
73 if (!rt_strncpy((char *)_led_states[i], buffer, size))
74 {
75 return rt_led_set_state(led, i) ? : size;
76 }
77 }
78
79 while (*value)
80 {
81 if (*value < '0' || *value > '9')
82 {
83 return -RT_EINVAL;
84 }
85
86 brightness *= 10;
87 brightness += *value - '0';
88
89 ++value;
90 }
91
92 rt_led_set_brightness(led, brightness);
93
94 return size;
95}
96
97#ifdef RT_USING_DEVICE_OPS
98const static struct rt_device_ops _led_ops =

Callers

nothing calls this directly

Calls 3

rt_strncpyFunction · 0.85
rt_led_set_stateFunction · 0.85
rt_led_set_brightnessFunction · 0.85

Tested by

no test coverage detected