From 5474a97f012f2a3b49b3cd3e3399dcf2a80c7c75 Mon Sep 17 00:00:00 2001 From: Wolfgang Bachschwell Date: Sat, 9 May 2020 11:51:19 +0200 Subject: [PATCH] Rearranged buttons, added INIT, USB Beacon, CW Beacon. --- lib/FT817_NBS/FT817_NBS.cpp | 11 ++++ lib/FT817_NBS/FT817_NBS.h | 1 + src/main.cpp | 107 ++++++++++++++++++++++++++++++++++-- 3 files changed, 114 insertions(+), 5 deletions(-) diff --git a/lib/FT817_NBS/FT817_NBS.cpp b/lib/FT817_NBS/FT817_NBS.cpp index c2acdb4..a1c9e07 100644 --- a/lib/FT817_NBS/FT817_NBS.cpp +++ b/lib/FT817_NBS/FT817_NBS.cpp @@ -146,4 +146,15 @@ void FT817_NBS::setMode(FT817_NBS::SignalMode mode){ uint8_t value = (uint8_t) mode; uint8_t data[5] = {value, 0x0, 0x0, 0x0, 0x7}; sendCommand(&data[0], sizeof(data)); +} + +void FT817_NBS::setSplit(bool on){ + uint8_t data[5] = {0x0, 0x0, 0x0, 0x0}; + if(on){ + data[4] = 0x2; + } + else{ + data[4] = 0x82; + } + 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 4650dca..83223f6 100644 --- a/lib/FT817_NBS/FT817_NBS.h +++ b/lib/FT817_NBS/FT817_NBS.h @@ -31,5 +31,6 @@ public: void setFrequency(unsigned long frequency); void toggleAB(); void setMode(FT817_NBS::SignalMode); + void setSplit(bool on); }; #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 45c7da7..cb2e662 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,13 +4,19 @@ #define SET_FREQ 4 #define SWITCH_AB 5 -#define SWITCH_USB_CW 6 +#define SWITCH_USB_CW 7 +#define INIT 9 +#define LOWER_FREQ_BEACON 6 +#define HIGHER_FREQ_BEACON 8 SoftwareSerial radio = SoftwareSerial(2, 3); FT817_NBS ft817(&radio); void setFreq(); void switchUsbCw(); +void initRadio(); +bool setBeaconHigh(); +bool setBeaconLow(); void setup() { // put your setup code here, to run once: @@ -19,11 +25,19 @@ void setup() { pinMode(SET_FREQ, INPUT_PULLUP); pinMode(SWITCH_AB, INPUT_PULLUP); pinMode(SWITCH_USB_CW, INPUT_PULLUP); + pinMode(INIT, INPUT_PULLUP); + pinMode(HIGHER_FREQ_BEACON, INPUT_PULLUP); + pinMode(LOWER_FREQ_BEACON, INPUT_PULLUP); } -boolean pressBlockSetFreq = false; -boolean pressBlockSwitchAB = false; -boolean pressBlockSwitchUsbCW = false; +bool pressBlockSetFreq = false; +bool pressBlockSwitchAB = false; +bool pressBlockSwitchUsbCW = false; +bool pressBlockInit = false; +bool pressBlockLowerFreqBeacon = false; +bool pressBlockHigherFreqBeacon = false; + +unsigned long pressLengthInit = 0; void loop() { // put your main code here, to run repeatedly: @@ -56,6 +70,42 @@ void loop() { pressBlockSwitchUsbCW = false; delay(20); } + + if(digitalRead(INIT) == LOW && !pressBlockInit){ + pressLengthInit = millis() + 1000; + pressBlockInit = true; + } + else if(digitalRead(INIT) == LOW) { + if(pressLengthInit != 0 && pressLengthInit <= millis()){ + pressLengthInit = 0; + initRadio(); + } + } + else{ + pressLengthInit = 0; + pressBlockInit = false; + delay(20); + } + + if (digitalRead(HIGHER_FREQ_BEACON) == LOW && !pressBlockHigherFreqBeacon){ + setBeaconHigh(); + pressBlockHigherFreqBeacon = true; + + } + else if(digitalRead(HIGHER_FREQ_BEACON) != LOW){ + pressBlockHigherFreqBeacon = false; + delay(20); + } + + if (digitalRead(LOWER_FREQ_BEACON) == LOW && !pressBlockLowerFreqBeacon){ + setBeaconLow(); + pressBlockLowerFreqBeacon = true; + + } + else if(digitalRead(LOWER_FREQ_BEACON) != LOW){ + pressBlockLowerFreqBeacon = false; + delay(20); + } } void setFreq(){ @@ -100,4 +150,51 @@ void switchUsbCw(){ delay(300); ft817.toggleAB(); -} \ No newline at end of file +} + +void initRadio(){ + ft817.setMode(FT817_NBS::SignalMode::USB); + delay(300); + ft817.setFrequency(14420000); + delay(300); + ft817.toggleAB(); + delay(300); + ft817.setMode(FT817_NBS::SignalMode::USB); + delay(300); + ft817.setFrequency(43250000); //43274500, 43250000 + delay(300); + ft817.setSplit(true); +} + +bool setBeacon(unsigned long frequency, FT817_NBS::SignalMode mode, bool firstVFO){ + unsigned long result = ft817.getFrequency().frequency; + if(result >= 43000000 && result <= 44000000){ + delay(300); + ft817.setMode(mode); + delay(300); + ft817.setFrequency(frequency); + return true; + } + else{ + delay(300); + ft817.toggleAB(); + if(firstVFO){ + delay(300); + return setBeacon(frequency, mode, false); + } + else{ + Serial.println("Could not set beacon. Please initialise the radio first."); + return false; + } + } +} + +bool setBeaconHigh(){ + return setBeacon(43274500, FT817_NBS::SignalMode::USB, true); +} + +bool setBeaconLow(){ + return setBeacon(43250000, FT817_NBS::SignalMode::CW, true); +} + +