|
1 | | -/* V7/8-261. |
| 1 | +/* V7/8-265. |
2 | 2 | ============================================================ |
3 | 3 | ================= SABERSENSE PROP FILE ================= |
4 | 4 | ================= by ================= |
@@ -238,6 +238,22 @@ COLOUR CHANGE FUNCTIONS WITH BLADE ON |
238 | 238 | { 3, ... } |
239 | 239 | etc. |
240 | 240 |
|
| 241 | +#define SABERSENSE_DEFAULT_BLADE_ARRAY 3 |
| 242 | + This feature is really intended for busy installers |
| 243 | + and sets the default blade array in multi-array systems. |
| 244 | + Using this feature, you can have a blade array with all |
| 245 | + the common blade lengths included, and then select which |
| 246 | + length to default to on first boot (i.e. until a save |
| 247 | + file is written). |
| 248 | + The alternative is to simply re-order the blade array |
| 249 | + manually, but then you have to re-order the array1.wav, |
| 250 | + array2.wav etc. files on the SD card to match, which |
| 251 | + is a hassle. |
| 252 | + Note that the define uses zero-based numbering, the |
| 253 | + same as the blade array itself, so you must use the |
| 254 | + number as it is shown in the blade array - i.e. number 3 |
| 255 | + for the fourth array down the full list. |
| 256 | +
|
241 | 257 | #define SABERSENSE_DISABLE_SAVE_ARRAY |
242 | 258 | By default, SABERSENSE_ARRAY_SELECTOR saves the current |
243 | 259 | array so that the saber will always boot into the last |
@@ -322,19 +338,47 @@ GESTURE CONTROLS |
322 | 338 |
|
323 | 339 | #ifdef SABERSENSE_ARRAY_SELECTOR |
324 | 340 |
|
| 341 | +#ifndef SABERSENSE_DEFAULT_BLADE_ARRAY |
| 342 | +#ifdef BLADE_DETECT_PIN |
| 343 | +#define SABERSENSE_DEFAULT_BLADE_ARRAY 1 |
| 344 | +#else |
| 345 | +#define SABERSENSE_DEFAULT_BLADE_ARRAY 0 |
| 346 | +#endif |
| 347 | +#endif |
| 348 | + |
| 349 | + // Check user-defined array is valid at compile time. |
| 350 | + static_assert( |
| 351 | + SABERSENSE_DEFAULT_BLADE_ARRAY < NELEM(blades), |
| 352 | + "[Sabersense] ERROR: " |
| 353 | + "#define SABERSENSE_DEFAULT_BLADE_ARRAY must be less than the number of blade arrays present." |
| 354 | + ); |
| 355 | +#ifdef BLADE_DETECT_PIN |
| 356 | + static_assert( |
| 357 | + SABERSENSE_DEFAULT_BLADE_ARRAY != 0, |
| 358 | + "[Sabersense] ERROR: " |
| 359 | + "#define SABERSENSE_DEFAULT_BLADE_ARRAY must be 1 or higher when using Blade Detect." |
| 360 | + ); |
| 361 | +#endif |
| 362 | +
|
325 | 363 | #ifndef SABERSENSE_DISABLE_SAVE_ARRAY |
326 | 364 | class SaveArrayStateFile : public ConfigFile { |
327 | 365 | public: |
328 | 366 | void iterateVariables(VariableOP *op) override { |
329 | | - CONFIG_VARIABLE2(sabersense_array_index, 0); // Default array if no save file. |
| 367 | + // Default array if no save file present... |
| 368 | + CONFIG_VARIABLE2(sabersense_array_index, SABERSENSE_DEFAULT_BLADE_ARRAY); |
330 | 369 | } |
331 | | - int sabersense_array_index; // Stores current array index. |
332 | | - }; |
| 370 | + int sabersense_array_index; // Stores current array index. |
| 371 | +}; |
333 | 372 | #endif |
334 | 373 |
|
335 | 374 | struct SabersenseArraySelector { |
336 | 375 | static int return_value; // Tracks current array index. |
337 | 376 | float id() { |
| 377 | + if (return_value < 0 || return_value >= NELEM(blades)) { |
| 378 | + Serial.println("[Sabersense] ALERT: User or externally-specified array index invalid. " |
| 379 | + "Resetting to default."); |
| 380 | + return_value = SABERSENSE_DEFAULT_BLADE_ARRAY; |
| 381 | + } |
338 | 382 | return return_value; |
339 | 383 | } |
340 | 384 | static void cycle() { |
|
0 commit comments