diff --git a/ArduChess.ino b/ArduChess.ino index 10c2545..1621bed 100644 --- a/ArduChess.ino +++ b/ArduChess.ino @@ -28,6 +28,7 @@ void bench() { int elapsed = micros() - startTime; Serial.print(elapsed); Serial.println(F("microseconds for 5 moves")); + panic(F("Bench finished!")); } diff --git a/Config.h b/Config.h index 1a8b2a5..6e29856 100644 --- a/Config.h +++ b/Config.h @@ -1,3 +1,7 @@ // CLEAR_UNMOVE is a feature that clears the unmake stack when it is not used. // This is useful for making it more human readable //#define _ACF_CLEAR_UNMOVE + +// PANIC_BLINK makes the Arduino blink an error code when it panics. +// Costs a lot of flash though (around 700 bytes) +//#define _ACF_PANIC_BLINK diff --git a/Panic.h b/Panic.h index 664e1b9..b3dd59c 100644 --- a/Panic.h +++ b/Panic.h @@ -1,12 +1,43 @@ #ifndef __PANIC_H_INC #define __PANIC_H_INC -void panic(const __FlashStringHelper* message) { +#pragma GCC push_options +#pragma GCC optimize("-Os") + +#ifdef _ACF_PANIC_BLINK +void sos() { + pinMode(LED_BUILTIN, OUTPUT); while(true) { - Serial.println(F("PANIC!")); - Serial.println(message); - delay(1000); + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(200); + digitalWrite(LED_BUILTIN, HIGH); + delay(150); + digitalWrite(LED_BUILTIN, LOW); + delay(150); + digitalWrite(LED_BUILTIN, HIGH); + delay(150); + digitalWrite(LED_BUILTIN, LOW); + delay(150); + digitalWrite(LED_BUILTIN, HIGH); + delay(150); + digitalWrite(LED_BUILTIN, LOW); + delay(150); + delay(2000); } } - +#endif + +void panic(const __FlashStringHelper* message) { + Serial.println(F("PANIC!")); + Serial.println(message); + + #ifdef _ACF_PANIC_BLINK + sos(); + #endif + while(true); +} + +#pragma GCC pop_options #endif