From 2b01f7fc4dbbd66f3575c02fd8cf899c7aad50fe Mon Sep 17 00:00:00 2001 From: Ancyker Date: Sun, 2 Jun 2024 11:56:08 -0400 Subject: [PATCH] Add checks for unsafe configurations * Fixes #929 * Updated `ci.yml` to define `GITHUB_CI` * Compilation will now error if VSELECT is enabled on hardware versions that don't support it (any version other than HW5). * HW4 and SERIAL might work but are untested. The error message for these versions reflects this. * Erroring when unsafe configurations are defined can be overridden by defining `ALLOW_UNSAFE_CONFIG` which will throw a warning instead. * This should only be done if trying to implement or test on a currently unsupported platform. * If both `GITHUB_CI` and `ALLOW_UNSAFE_CONFIG` are defined an error will be thrown causing the CI tests to fail. This is just in case someone makes a commit with it defined. --- .github/workflows/ci.yml | 2 +- Cart_Reader/OSCR.h | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9217980..bdda3e0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,4 +47,4 @@ jobs: cd Cart_Reader/ # Select hardware version by uncommenting it (using regular expression) sed -i 's/^\/\/[\t ]*#define ${{ matrix.hwVersion }}/#define ${{ matrix.hwVersion }}/g' Config.h - arduino-cli compile --fqbn arduino:avr:mega --warnings all + arduino-cli compile --fqbn arduino:avr:mega --warnings all --build-property compiler.cpp.extra_flags="-DGITHUB_CI" diff --git a/Cart_Reader/OSCR.h b/Cart_Reader/OSCR.h index 5fde9d4..c2bf695 100644 --- a/Cart_Reader/OSCR.h +++ b/Cart_Reader/OSCR.h @@ -19,10 +19,54 @@ # error !!! PLEASE CHOOSE HARDWARE VERSION IN CONFIG.H !!! # endif +// Let user know unsafe configs are allowed +# if defined(ALLOW_UNSAFE_CONFIG) +// Error if defined during GitHub CI tests. This should not happen unless someone accidentally committed their Config.h +# if defined(GITHUB_CI) +# error !! UNSAFE CONFIGURATIONS ARE ALLOWED !! -- This should not be enabled on the repository! +# else /* !defined(GITHUB_CI) */ +# warning !! UNSAFE CONFIGURATIONS ARE ALLOWED !! -- Unless you are a developer this probably is not something you want set. +# endif /* GITHUB_CI */ +# endif /* ALLOW_UNSAFE_CONFIG */ + # if defined(ENABLE_3V3FIX) && !defined(ENABLE_VSELECT) # warning Using 3V3FIX is best with VSELECT. # endif +# if defined(ENABLE_VSELECT) + +// Error if not a supported hardware version +# if !(defined(HW4) || defined(HW5) || defined(SERIAL_MONITOR)) +# if defined(ALLOW_UNSAFE_CONFIG) +# warning Using VSELECT with hardware revisions other than 4 or 5 is not supported. +# else /* !defined(ALLOW_UNSAFE_CONFIG) */ +# error Using VSELECT with hardware revisions other than 4 or 5 is not supported. \ + If you understand what you are doing you can define ALLOW_UNSAFE_CONFIG in Config.h to allow compiling. +# endif /* ALLOW_UNSAFE_CONFIG */ +# endif /* !(HW4 | HW5 | SERIAL_MONITOR) */ + +// HW4 might work but needs tested. Make sure they know it's untested. +# if defined(HW4) +# if defined(ALLOW_UNSAFE_CONFIG) +# warning Using VSELECT with HW4 is untested. Verification with a multimeter before use is strongly recommended. Please remember to report back with your findings. +# else /* !defined(ALLOW_UNSAFE_CONFIG) */ +# error Using VSELECT with HW4 is untested. Verification with a multimeter before use is strongly recommended. \ + Define ALLOW_UNSAFE_CONFIG in Config.h to allow compiling. Please report back with your findings after testing! +# endif /* ALLOW_UNSAFE_CONFIG */ +# endif /* HW4 */ + +// SERIAL might work but needs tested. Make sure they know it's untested. +# if defined(SERIAL_MONITOR) +# if defined(ALLOW_UNSAFE_CONFIG) +# warning Using VSELECT with a serial-only OSCR is untested. Verification with a multimeter before use is strongly recommended. Please remember to report back with your findings. +# else /* !defined(ALLOW_UNSAFE_CONFIG) */ +# error Using VSELECT with a serial-only OSCR is untested. Verification with a multimeter before use is strongly recommended. \ + Define ALLOW_UNSAFE_CONFIG in Config.h to allow compiling. Please report back with your findings after testing! +# endif /* ALLOW_UNSAFE_CONFIG */ +# endif /* SERIAL_MONITOR */ + +# endif /* ENABLE_VSELECT */ + /*==== CONSTANTS ==================================================*/ /** * String Constants