@@ -2083,6 +2083,8 @@ constexpr const Plugin_ptr_t PROGMEM Plugin_ptr[] =
2083
2083
#endif // ifdef USES_P255
2084
2084
};
2085
2085
2086
+ bool _Plugin_init_setupDone = false ;
2087
+
2086
2088
2087
2089
constexpr size_t DeviceIndex_to_Plugin_id_size = NR_ELEMENTS(DeviceIndex_to_Plugin_id);
2088
2090
@@ -2174,7 +2176,7 @@ deviceIndex_t getDeviceIndex_from_PluginID(pluginID_t pluginID)
2174
2176
2175
2177
pluginID_t getPluginID_from_DeviceIndex (deviceIndex_t deviceIndex)
2176
2178
{
2177
- if (deviceIndex < DeviceIndex_to_Plugin_id_size )
2179
+ if (validDeviceIndex_init ( deviceIndex) )
2178
2180
{
2179
2181
return pluginID_t::toPluginID (pgm_read_byte (DeviceIndex_to_Plugin_id + deviceIndex.value ));
2180
2182
}
@@ -2183,13 +2185,16 @@ pluginID_t getPluginID_from_DeviceIndex(deviceIndex_t deviceIndex)
2183
2185
2184
2186
bool validDeviceIndex_init (deviceIndex_t deviceIndex)
2185
2187
{
2186
- return deviceIndex < DeviceIndex_to_Plugin_id_size;
2188
+ if (_Plugin_init_setupDone) {
2189
+ return deviceIndex < DeviceIndex_to_Plugin_id_size;
2190
+ }
2191
+ return false ;
2187
2192
}
2188
2193
2189
2194
// Array containing "DeviceIndex" alfabetically sorted.
2190
2195
deviceIndex_t getDeviceIndex_sorted (deviceIndex_t deviceIndex)
2191
2196
{
2192
- if (deviceIndex < DeviceIndex_to_Plugin_id_size ) {
2197
+ if (validDeviceIndex_init ( deviceIndex) ) {
2193
2198
return DeviceIndex_sorted[deviceIndex.value ];
2194
2199
}
2195
2200
return INVALID_DEVICE_INDEX;
@@ -2198,7 +2203,7 @@ deviceIndex_t getDeviceIndex_sorted(deviceIndex_t deviceIndex)
2198
2203
2199
2204
boolean PluginCall (deviceIndex_t deviceIndex, uint8_t function, struct EventStruct *event, String& string)
2200
2205
{
2201
- if (deviceIndex < DeviceIndex_to_Plugin_id_size )
2206
+ if (validDeviceIndex_init ( deviceIndex) )
2202
2207
{
2203
2208
Plugin_ptr_t plugin_call = (Plugin_ptr_t)pgm_read_ptr (Plugin_ptr + deviceIndex.value );
2204
2209
return plugin_call (function, event, string);
@@ -2208,10 +2213,9 @@ boolean PluginCall(deviceIndex_t deviceIndex, uint8_t function, struct EventStru
2208
2213
2209
2214
void PluginSetup ()
2210
2215
{
2211
- static bool setupDone = false ;
2212
- if (setupDone) return ;
2216
+ if (_Plugin_init_setupDone) return ;
2213
2217
2214
- setupDone = true ;
2218
+ _Plugin_init_setupDone = true ;
2215
2219
2216
2220
for (size_t id = 0 ; id < Plugin_id_to_DeviceIndex_size; ++id)
2217
2221
{
0 commit comments