-
Notifications
You must be signed in to change notification settings - Fork 0
/
rgb_led_strips.c
113 lines (81 loc) · 2.79 KB
/
rgb_led_strips.c
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
/*
rgb_led_strips.c - plugin for configuring number of LEDs in up to two strips
Part of grblHAL misc. plugins
Public domain.
$536 - length of strip 1.
$537 - length of strip 2.
*/
#include "driver.h"
#if RGB_LED_ENABLE
static bool is_setting_available (const setting_detail_t *setting)
{
bool available = false;
switch(setting->id) {
case Setting_RGB_StripLengt0:
available = hal.rgb0.flags.is_strip;
break;
case Setting_RGB_StripLengt1:
available = hal.rgb1.flags.is_strip;
break;
default:
break;
}
return available;
}
static const setting_group_detail_t rgb_groups[] = {
{ Group_Root, Group_AuxPorts, "Aux ports"}
};
static const setting_detail_t rgb_settings[] = {
{ Setting_RGB_StripLengt0, Group_AuxPorts, "LED strip 1 length", NULL, Format_Int8, "##0", NULL, "255", Setting_NonCore, &settings.rgb_strip.length0, NULL, is_setting_available },
{ Setting_RGB_StripLengt1, Group_AuxPorts, "LED strip 2 length", NULL, Format_Int8, "##0", NULL, "255", Setting_NonCore, &settings.rgb_strip.length1, NULL, is_setting_available }
};
#ifndef NO_SETTINGS_DESCRIPTIONS
static const setting_descr_t rgb_settings_descr[] = {
{ Setting_RGB_StripLengt0, "Number of LEDS in strip 1." },
{ Setting_RGB_StripLengt1, "Number of LEDS in strip 2." }
};
#endif
static void rgb_setting_changed (settings_t *settings, settings_changed_flags_t changed)
{
hal.settings_changed(settings, changed);
}
#if RGB_LED_ENABLE == 1
static bool led_enabled;
static on_report_options_ptr on_report_options;
static void onReportOptions (bool newopt)
{
on_report_options(newopt);
if(!newopt)
report_plugin(led_enabled
? "RGB LED strips"
: "RGB LED strips (N/A)", "0.03");
}
void rgb_led_init (void)
{
if((led_enabled = hal.rgb0.flags.is_strip || hal.rgb1.flags.is_strip))
settings_register(&setting_details);
on_report_options = grbl.on_report_options;
grbl.on_report_options = onReportOptions;
}
#else
static inline bool rgb_led_settings_register (void)
{
static setting_details_t setting_details = {
.groups = rgb_groups,
.n_groups = sizeof(rgb_groups) / sizeof(setting_group_detail_t),
.settings = rgb_settings,
.n_settings = sizeof(rgb_settings) / sizeof(setting_detail_t),
#ifndef NO_SETTINGS_DESCRIPTIONS
.descriptions = rgb_settings_descr,
.n_descriptions = sizeof(rgb_settings_descr) / sizeof(setting_descr_t),
#endif
.on_changed = rgb_setting_changed,
.save = settings_write_global
};
bool ok;
if((ok = hal.rgb0.flags.is_strip || hal.rgb1.flags.is_strip))
settings_register(&setting_details);
return ok;
}
#endif
#endif // RGB_LED_ENABLE