From cd22f0c8adc5395a4170040abf8ccca5c084a6e0 Mon Sep 17 00:00:00 2001 From: jupfi Date: Fri, 18 Aug 2023 13:57:06 +0200 Subject: [PATCH] Implemented ControlSwitch command. --- src/ATM.ino | 7 ++--- src/commands/ControlSwitch.cpp | 52 ++++++++++++++++++++++++++++++++++ src/commands/ControlSwitch.h | 26 +++++++++++++++++ 3 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 src/commands/ControlSwitch.cpp create mode 100644 src/commands/ControlSwitch.h diff --git a/src/ATM.ino b/src/ATM.ino index b40a5f1..e35ddaa 100644 --- a/src/ATM.ino +++ b/src/ATM.ino @@ -7,6 +7,7 @@ #include "commands/SetVoltages.h" #include "commands/MeasureReflection.h" #include "commands/VoltageSweep.h" +#include "commands/ControlSwitch.h" #define DEBUG @@ -21,6 +22,7 @@ Homing homing; SetVoltages setVoltages; MeasureReflection measureReflection; VoltageSweep voltageSweep; +ControlSwitch controlSwitch; // Frequency Settings #define FREQUENCY_STEP 100000U // 100kHz frequency steps for initial frequency sweep @@ -58,6 +60,7 @@ void setup() commandManager.registerCommand('v', &setVoltages); commandManager.registerCommand('m', &measureReflection); commandManager.registerCommand('s', &voltageSweep); + commandManager.registerCommand('c', &controlSwitch); pinMode(MISO_PIN, INPUT_PULLUP); // Seems to be necessary for SPI to work @@ -118,10 +121,6 @@ void setup() digitalWrite(FILTER_SWITCH_A, LOW); digitalWrite(FILTER_SWITCH_B, HIGH); - // RF Switch for switching between preamp and tuning and matching module - pinMode(RF_SWITCH_PIN, OUTPUT); - digitalWrite(RF_SWITCH_PIN, HIGH); - // ADAC module adac.enable_internal_Vref(); adac.set_DAC_max_2x_Vref(); diff --git a/src/commands/ControlSwitch.cpp b/src/commands/ControlSwitch.cpp new file mode 100644 index 0000000..ace6b29 --- /dev/null +++ b/src/commands/ControlSwitch.cpp @@ -0,0 +1,52 @@ +#include "Utilities.h" +#include "ControlSwitch.h" + +// Constructor +ControlSwitch::ControlSwitch() +{ + pinMode(RF_SWITCH_PIN, OUTPUT); + switch_state = ATM_SYSTEM; + digitalWrite(RF_SWITCH_PIN, LOW); +} + +void ControlSwitch::execute(String input_line) +{ + char switch_to = input_line[1]; + + if ((switch_to == PRE_AMP) && (switch_state != PRE_AMP)) + { + switch_state = PRE_AMP; + digitalWrite(RF_SWITCH_PIN, HIGH); + result = "Switched to preamp"; + } + else if ((switch_to == ATM_SYSTEM) && (switch_state != ATM_SYSTEM)) + { + switch_state = ATM_SYSTEM; + digitalWrite(RF_SWITCH_PIN, LOW); + result = "Switched to atm system"; + } + else if (switch_to == switch_state) + { + result = "Already switched to " + String(switch_to); + } + else + { + result = "Invalid switch state"; + } +} + +void ControlSwitch::printResult() +{ + printInfo(result); +} + +void ControlSwitch::printHelp() +{ + Serial.println("Control switch command"); + Serial.println("Syntax: s"); + Serial.println("Example: sa"); + Serial.println("This will switch to the atm system"); + Serial.println("Possible switch states:"); + Serial.println("p: preamp"); + Serial.println("a: atm system"); +} \ No newline at end of file diff --git a/src/commands/ControlSwitch.h b/src/commands/ControlSwitch.h new file mode 100644 index 0000000..e114a83 --- /dev/null +++ b/src/commands/ControlSwitch.h @@ -0,0 +1,26 @@ +#ifndef CONTROLSWITCH_H +#define CONTROLSWITCH_H + +#define PRE_AMP 'p' +#define ATM_SYSTEM 'a' + +#include "Command.h" + +/** + * @brief This class is used to control the switch which is used to switch between the preamplifier and the atm system. + * It can take the command where switch_state is either p or a for preamp or atm system respectively. + */ +class ControlSwitch : public Command +{ +public: + ControlSwitch(); + void execute(String input_line) override; + void printResult() override; + void printHelp() override; + +private: + char switch_state; + String result; +}; + +#endif \ No newline at end of file