Compare commits
1 Commits
main
...
programmer
Author | SHA1 | Date | |
---|---|---|---|
33001f7c59 |
@ -1,6 +1,8 @@
|
|||||||
#include <FT817_NBS.h>
|
#include <FT817_NBS.h>
|
||||||
|
|
||||||
FT817_NBS::FT817_NBS(SoftwareSerial *connection) { serial = connection; }
|
FT817_NBS::FT817_NBS(SoftwareSerial *connection){
|
||||||
|
serial = connection;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned long FT817_NBS::bcdToInt(uint8_t bcd){
|
unsigned long FT817_NBS::bcdToInt(uint8_t bcd){
|
||||||
int byte = (bcd & 0xF0) >> 4;
|
int byte = (bcd & 0xF0) >> 4;
|
||||||
@ -74,8 +76,7 @@ FT817_NBS::SignalMode FT817_NBS::getSignalMode(uint8_t numericValue) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FT817_NBS::convertFromValueToBcd(uint8_t *buffer,
|
void FT817_NBS::convertFromValueToBcd(uint8_t *buffer, unsigned long actualValue){
|
||||||
unsigned long actualValue) {
|
|
||||||
for(int partsLeft = 0;partsLeft < 4; partsLeft++){
|
for(int partsLeft = 0;partsLeft < 4; partsLeft++){
|
||||||
unsigned long part = actualValue / getDevicer(partsLeft);
|
unsigned long part = actualValue / getDevicer(partsLeft);
|
||||||
actualValue -= part * getDevicer(partsLeft);
|
actualValue -= part * getDevicer(partsLeft);
|
||||||
@ -151,7 +152,8 @@ void FT817_NBS::setSplit(bool on) {
|
|||||||
uint8_t data[5] = {0x0, 0x0, 0x0, 0x0};
|
uint8_t data[5] = {0x0, 0x0, 0x0, 0x0};
|
||||||
if(on){
|
if(on){
|
||||||
data[4] = 0x2;
|
data[4] = 0x2;
|
||||||
} else {
|
}
|
||||||
|
else{
|
||||||
data[4] = 0x82;
|
data[4] = 0x82;
|
||||||
}
|
}
|
||||||
sendCommand(&data[0], sizeof(data));
|
sendCommand(&data[0], sizeof(data));
|
||||||
|
@ -6,18 +6,7 @@
|
|||||||
|
|
||||||
class FT817_NBS {
|
class FT817_NBS {
|
||||||
public:
|
public:
|
||||||
enum SignalMode {
|
enum SignalMode {LSB = 0x0, USB = 0x1, CW = 0x2, CWR = 0x3, AM = 0x4, WFM = 0x6, FM = 0x8, DIG = 0xA, PKT = 0xC, UNKNOWN};
|
||||||
LSB = 0x0,
|
|
||||||
USB = 0x1,
|
|
||||||
CW = 0x2,
|
|
||||||
CWR = 0x3,
|
|
||||||
AM = 0x4,
|
|
||||||
WFM = 0x6,
|
|
||||||
FM = 0x8,
|
|
||||||
DIG = 0xA,
|
|
||||||
PKT = 0xC,
|
|
||||||
UNKNOWN
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SoftwareSerial *serial;
|
SoftwareSerial *serial;
|
||||||
|
@ -13,13 +13,8 @@ platform = atmelavr
|
|||||||
board = uno
|
board = uno
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
|
||||||
; upload_protocol = stk500v2
|
upload_protocol = stk500v2
|
||||||
|
|
||||||
upload_protocol = stk500v1
|
|
||||||
; edit these lines
|
|
||||||
upload_port = /dev/tty.usbmodem14101
|
|
||||||
upload_speed = 19200
|
|
||||||
; each flag in a new line
|
; each flag in a new line
|
||||||
upload_flags =
|
upload_flags =
|
||||||
-P$UPLOAD_PORT
|
-Pusb
|
||||||
-b$UPLOAD_SPEED
|
upload_port = usb
|
102
src/main.cpp
102
src/main.cpp
@ -1,31 +1,29 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <FT817_NBS.h>
|
|
||||||
#include <SoftwareSerial.h>
|
#include <SoftwareSerial.h>
|
||||||
|
#include <FT817_NBS.h>
|
||||||
|
|
||||||
#define LOWER_FREQ_BEACON A0
|
|
||||||
#define INIT A1
|
|
||||||
#define HIGHER_FREQ_BEACON A2
|
|
||||||
#define SWITCH_USB_CW A3
|
|
||||||
#define SET_FREQ A4
|
#define SET_FREQ A4
|
||||||
#define SWITCH_AB A5
|
#define SWITCH_AB A5
|
||||||
|
#define SWITCH_USB_CW A3
|
||||||
|
#define INIT A1
|
||||||
|
#define LOWER_FREQ_BEACON A0
|
||||||
|
#define HIGHER_FREQ_BEACON A2
|
||||||
|
|
||||||
|
#define LED_LOWER_FREQ_BEACON 5
|
||||||
|
#define LED_INIT 6
|
||||||
|
#define LED_HIGHER_FREQ_BEACON 7
|
||||||
|
#define LED_SWITCH_USB_CW 8
|
||||||
|
#define LED_SET_FREQ 9
|
||||||
|
#define LED_SWITCH_AB 10
|
||||||
|
|
||||||
#define LED_LOWER_FREQ_BEACON 4
|
|
||||||
#define LED_INIT 5
|
|
||||||
#define LED_HIGHER_FREQ_BEACON 6
|
|
||||||
#define LED_SWITCH_USB_CW 7
|
|
||||||
#define LED_SET_FREQ 8
|
|
||||||
#define LED_SWITCH_AB 9
|
|
||||||
|
|
||||||
SoftwareSerial radio = SoftwareSerial(2, 3);
|
SoftwareSerial radio = SoftwareSerial(2, 3);
|
||||||
FT817_NBS ft817(&radio);
|
FT817_NBS ft817(&radio);
|
||||||
|
|
||||||
void setFreq();
|
void setFreq();
|
||||||
void switchUsbCw();
|
void switchUsbCw();
|
||||||
void initRadio();
|
void initRadio();
|
||||||
bool setBeaconHigh();
|
bool setBeaconHigh();
|
||||||
bool setBeaconLow();
|
bool setBeaconLow();
|
||||||
void checkSync();
|
|
||||||
void slowBlinkerClock();
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
@ -37,15 +35,10 @@ void setup() {
|
|||||||
pinMode(INIT, INPUT_PULLUP);
|
pinMode(INIT, INPUT_PULLUP);
|
||||||
pinMode(HIGHER_FREQ_BEACON, INPUT_PULLUP);
|
pinMode(HIGHER_FREQ_BEACON, INPUT_PULLUP);
|
||||||
pinMode(LOWER_FREQ_BEACON, INPUT_PULLUP);
|
pinMode(LOWER_FREQ_BEACON, INPUT_PULLUP);
|
||||||
|
|
||||||
pinMode(LED_INIT, OUTPUT);
|
pinMode(LED_INIT, OUTPUT);
|
||||||
pinMode(LED_SET_FREQ, OUTPUT);
|
|
||||||
digitalWrite(LED_INIT,HIGH);
|
digitalWrite(LED_INIT,HIGH);
|
||||||
delay (500);
|
delay (500);
|
||||||
digitalWrite(LED_INIT, LOW);
|
digitalWrite(LED_INIT, LOW);
|
||||||
digitalWrite(LED_SET_FREQ, HIGH);
|
|
||||||
delay(500);
|
|
||||||
digitalWrite(LED_SET_FREQ, LOW);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pressBlockSetFreq = false;
|
bool pressBlockSetFreq = false;
|
||||||
@ -54,11 +47,8 @@ bool pressBlockSwitchUsbCW = false;
|
|||||||
bool pressBlockInit = false;
|
bool pressBlockInit = false;
|
||||||
bool pressBlockLowerFreqBeacon = false;
|
bool pressBlockLowerFreqBeacon = false;
|
||||||
bool pressBlockHigherFreqBeacon = false;
|
bool pressBlockHigherFreqBeacon = false;
|
||||||
bool slowBlinker = false;
|
|
||||||
|
|
||||||
unsigned long pressLengthInit = 0;
|
unsigned long pressLengthInit = 0;
|
||||||
unsigned long lastSyncFrequency = 0;
|
|
||||||
unsigned long lastBlinkToggle = 0;
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// put your main code here, to run repeatedly:
|
// put your main code here, to run repeatedly:
|
||||||
@ -66,7 +56,8 @@ void loop() {
|
|||||||
if (digitalRead(SET_FREQ) == LOW && !pressBlockSetFreq){
|
if (digitalRead(SET_FREQ) == LOW && !pressBlockSetFreq){
|
||||||
pressBlockSetFreq = true;
|
pressBlockSetFreq = true;
|
||||||
setFreq();
|
setFreq();
|
||||||
} else if (digitalRead(SET_FREQ) != LOW) {
|
}
|
||||||
|
else if(digitalRead(SET_FREQ) != LOW){
|
||||||
pressBlockSetFreq = false;
|
pressBlockSetFreq = false;
|
||||||
delay(20);
|
delay(20);
|
||||||
}
|
}
|
||||||
@ -74,7 +65,9 @@ void loop() {
|
|||||||
if (digitalRead(SWITCH_AB) == LOW && !pressBlockSwitchAB){
|
if (digitalRead(SWITCH_AB) == LOW && !pressBlockSwitchAB){
|
||||||
ft817.toggleAB();
|
ft817.toggleAB();
|
||||||
pressBlockSwitchAB = true;
|
pressBlockSwitchAB = true;
|
||||||
} else if (digitalRead(SWITCH_AB) != LOW) {
|
|
||||||
|
}
|
||||||
|
else if(digitalRead(SWITCH_AB) != LOW){
|
||||||
pressBlockSwitchAB = false;
|
pressBlockSwitchAB = false;
|
||||||
delay(20);
|
delay(20);
|
||||||
}
|
}
|
||||||
@ -82,7 +75,9 @@ void loop() {
|
|||||||
if (digitalRead(SWITCH_USB_CW) == LOW && !pressBlockSwitchUsbCW){
|
if (digitalRead(SWITCH_USB_CW) == LOW && !pressBlockSwitchUsbCW){
|
||||||
switchUsbCw();
|
switchUsbCw();
|
||||||
pressBlockSwitchUsbCW = true;
|
pressBlockSwitchUsbCW = true;
|
||||||
} else if (digitalRead(SWITCH_USB_CW) != LOW) {
|
|
||||||
|
}
|
||||||
|
else if(digitalRead(SWITCH_USB_CW) != LOW){
|
||||||
pressBlockSwitchUsbCW = false;
|
pressBlockSwitchUsbCW = false;
|
||||||
delay(20);
|
delay(20);
|
||||||
}
|
}
|
||||||
@ -90,12 +85,14 @@ void loop() {
|
|||||||
if(digitalRead(INIT) == LOW && !pressBlockInit){
|
if(digitalRead(INIT) == LOW && !pressBlockInit){
|
||||||
pressLengthInit = millis() + 1000;
|
pressLengthInit = millis() + 1000;
|
||||||
pressBlockInit = true;
|
pressBlockInit = true;
|
||||||
} else if (digitalRead(INIT) == LOW) {
|
}
|
||||||
|
else if(digitalRead(INIT) == LOW) {
|
||||||
if(pressLengthInit != 0 && pressLengthInit <= millis()){
|
if(pressLengthInit != 0 && pressLengthInit <= millis()){
|
||||||
pressLengthInit = 0;
|
pressLengthInit = 0;
|
||||||
initRadio();
|
initRadio();
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else{
|
||||||
pressLengthInit = 0;
|
pressLengthInit = 0;
|
||||||
pressBlockInit = false;
|
pressBlockInit = false;
|
||||||
delay(20);
|
delay(20);
|
||||||
@ -104,7 +101,9 @@ void loop() {
|
|||||||
if (digitalRead(HIGHER_FREQ_BEACON) == LOW && !pressBlockHigherFreqBeacon){
|
if (digitalRead(HIGHER_FREQ_BEACON) == LOW && !pressBlockHigherFreqBeacon){
|
||||||
setBeaconHigh();
|
setBeaconHigh();
|
||||||
pressBlockHigherFreqBeacon = true;
|
pressBlockHigherFreqBeacon = true;
|
||||||
} else if (digitalRead(HIGHER_FREQ_BEACON) != LOW) {
|
|
||||||
|
}
|
||||||
|
else if(digitalRead(HIGHER_FREQ_BEACON) != LOW){
|
||||||
pressBlockHigherFreqBeacon = false;
|
pressBlockHigherFreqBeacon = false;
|
||||||
delay(20);
|
delay(20);
|
||||||
}
|
}
|
||||||
@ -112,30 +111,28 @@ void loop() {
|
|||||||
if (digitalRead(LOWER_FREQ_BEACON) == LOW && !pressBlockLowerFreqBeacon){
|
if (digitalRead(LOWER_FREQ_BEACON) == LOW && !pressBlockLowerFreqBeacon){
|
||||||
setBeaconLow();
|
setBeaconLow();
|
||||||
pressBlockLowerFreqBeacon = true;
|
pressBlockLowerFreqBeacon = true;
|
||||||
} else if (digitalRead(LOWER_FREQ_BEACON) != LOW) {
|
|
||||||
|
}
|
||||||
|
else if(digitalRead(LOWER_FREQ_BEACON) != LOW){
|
||||||
pressBlockLowerFreqBeacon = false;
|
pressBlockLowerFreqBeacon = false;
|
||||||
delay(20);
|
delay(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkSync();
|
|
||||||
slowBlinkerClock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setFreq(){
|
void setFreq(){
|
||||||
unsigned long rxFrequency = ft817.getFrequency().frequency;
|
unsigned long frequency = ft817.getFrequency().frequency;
|
||||||
|
|
||||||
if (rxFrequency < 28850000) {
|
if(frequency < 28850000){
|
||||||
Serial.println("Please go into the 70 cm Band!");
|
Serial.println("Please go into the 70 cm Band!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
delay(300);
|
delay(300);
|
||||||
unsigned long txFrequency = rxFrequency - 28850000;
|
unsigned long newFrequency = frequency - 28850000;
|
||||||
lastSyncFrequency = rxFrequency;
|
|
||||||
|
|
||||||
ft817.toggleAB();
|
ft817.toggleAB();
|
||||||
delay(300);
|
delay(300);
|
||||||
|
|
||||||
ft817.setFrequency(txFrequency);
|
ft817.setFrequency(newFrequency);
|
||||||
|
|
||||||
delay(300);
|
delay(300);
|
||||||
|
|
||||||
@ -148,7 +145,8 @@ void switchUsbCw() {
|
|||||||
|
|
||||||
if (mode == FT817_NBS::SignalMode::USB){
|
if (mode == FT817_NBS::SignalMode::USB){
|
||||||
newMode = FT817_NBS::SignalMode::CW;
|
newMode = FT817_NBS::SignalMode::CW;
|
||||||
} else {
|
}
|
||||||
|
else{
|
||||||
newMode = FT817_NBS::SignalMode::USB;
|
newMode = FT817_NBS::SignalMode::USB;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,8 +177,7 @@ void initRadio() {
|
|||||||
ft817.setSplit(true);
|
ft817.setSplit(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool setBeacon(unsigned long frequency, FT817_NBS::SignalMode mode,
|
bool setBeacon(unsigned long frequency, FT817_NBS::SignalMode mode, bool firstVFO){
|
||||||
bool firstVFO) {
|
|
||||||
unsigned long result = ft817.getFrequency().frequency;
|
unsigned long result = ft817.getFrequency().frequency;
|
||||||
if(result >= 43000000 && result <= 44000000){
|
if(result >= 43000000 && result <= 44000000){
|
||||||
delay(300);
|
delay(300);
|
||||||
@ -188,15 +185,16 @@ bool setBeacon(unsigned long frequency, FT817_NBS::SignalMode mode,
|
|||||||
delay(300);
|
delay(300);
|
||||||
ft817.setFrequency(frequency);
|
ft817.setFrequency(frequency);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
|
else{
|
||||||
delay(300);
|
delay(300);
|
||||||
ft817.toggleAB();
|
ft817.toggleAB();
|
||||||
if(firstVFO){
|
if(firstVFO){
|
||||||
delay(300);
|
delay(300);
|
||||||
return setBeacon(frequency, mode, false);
|
return setBeacon(frequency, mode, false);
|
||||||
} else {
|
}
|
||||||
Serial.println(
|
else{
|
||||||
"Could not set beacon. Please initialise the radio first.");
|
Serial.println("Could not set beacon. Please initialise the radio first.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,20 +208,4 @@ bool setBeaconLow() {
|
|||||||
return setBeacon(43250000, FT817_NBS::SignalMode::CW, true);
|
return setBeacon(43250000, FT817_NBS::SignalMode::CW, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkSync() {
|
|
||||||
unsigned long latest_rxFrequency = ft817.getFrequency().frequency;
|
|
||||||
if (abs(latest_rxFrequency - lastSyncFrequency) >= 250) {
|
|
||||||
digitalWrite(LED_SET_FREQ, HIGH);
|
|
||||||
} else if (abs(latest_rxFrequency - lastSyncFrequency) == 0) {
|
|
||||||
digitalWrite(LED_SET_FREQ, LOW);
|
|
||||||
} else if (abs(latest_rxFrequency - lastSyncFrequency) < 250) {
|
|
||||||
digitalWrite(LED_SET_FREQ, slowBlinker);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void slowBlinkerClock() {
|
|
||||||
if ((millis() - lastBlinkToggle) >= 1000) {
|
|
||||||
lastBlinkToggle = millis();
|
|
||||||
slowBlinker = !slowBlinker;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user