diff --git a/lib/FT817_NBS/FT817_NBS.cpp b/lib/FT817_NBS/FT817_NBS.cpp index 16bc0fe..c2acdb4 100644 --- a/lib/FT817_NBS/FT817_NBS.cpp +++ b/lib/FT817_NBS/FT817_NBS.cpp @@ -137,4 +137,13 @@ void FT817_NBS::setFrequency(unsigned long frequency){ convertFromValueToBcd(&data[0], frequency); data[4] = 0x1; sendCommand(&data[0], sizeof(data)); +} + +void FT817_NBS::setMode(FT817_NBS::SignalMode mode){ + if(mode == SignalMode::UNKNOWN || mode == SignalMode::WFM){ + return; + } + uint8_t value = (uint8_t) mode; + uint8_t data[5] = {value, 0x0, 0x0, 0x0, 0x7}; + sendCommand(&data[0], sizeof(data)); } \ No newline at end of file diff --git a/lib/FT817_NBS/FT817_NBS.h b/lib/FT817_NBS/FT817_NBS.h index 73ea31d..4650dca 100644 --- a/lib/FT817_NBS/FT817_NBS.h +++ b/lib/FT817_NBS/FT817_NBS.h @@ -30,5 +30,6 @@ public: FT817_NBS::Frequency getFrequency(); void setFrequency(unsigned long frequency); void toggleAB(); + void setMode(FT817_NBS::SignalMode); }; #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 6aa90e8..45c7da7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,11 +4,13 @@ #define SET_FREQ 4 #define SWITCH_AB 5 +#define SWITCH_USB_CW 6 SoftwareSerial radio = SoftwareSerial(2, 3); FT817_NBS ft817(&radio); void setFreq(); +void switchUsbCw(); void setup() { // put your setup code here, to run once: @@ -16,10 +18,12 @@ void setup() { Serial.begin(9600); pinMode(SET_FREQ, INPUT_PULLUP); pinMode(SWITCH_AB, INPUT_PULLUP); + pinMode(SWITCH_USB_CW, INPUT_PULLUP); } boolean pressBlockSetFreq = false; boolean pressBlockSwitchAB = false; +boolean pressBlockSwitchUsbCW = false; void loop() { // put your main code here, to run repeatedly: @@ -42,6 +46,16 @@ void loop() { pressBlockSwitchAB = false; delay(20); } + + if (digitalRead(SWITCH_USB_CW) == LOW && !pressBlockSwitchUsbCW){ + switchUsbCw(); + pressBlockSwitchUsbCW = true; + + } + else if(digitalRead(SWITCH_USB_CW) != LOW){ + pressBlockSwitchUsbCW = false; + delay(20); + } } void setFreq(){ @@ -61,5 +75,29 @@ void setFreq(){ delay(300); + ft817.toggleAB(); +} + +void switchUsbCw(){ + FT817_NBS::SignalMode mode = ft817.getFrequency().mode; + FT817_NBS::SignalMode newMode; + + if (mode == FT817_NBS::SignalMode::USB){ + newMode = FT817_NBS::SignalMode::CW; + } + else{ + newMode = FT817_NBS::SignalMode::USB; + } + + delay(300); + ft817.setMode(newMode); + + delay(300); + ft817.toggleAB(); + + delay(300); + ft817.setMode(newMode); + + delay(300); ft817.toggleAB(); } \ No newline at end of file