Compare commits
No commits in common. "master" and "1.1.3" have entirely different histories.
|
@ -1,7 +1,5 @@
|
||||||
# HamShield
|
# HamShield
|
||||||
|
|
||||||
You can purchase HamShield (as well as smaller variants or LoRa version) at http://www.enhancedradio.com/
|
|
||||||
|
|
||||||
The master branch is intended for use with HamShield hardware -09 and above.
|
The master branch is intended for use with HamShield hardware -09 and above.
|
||||||
|
|
||||||
WARNING: The dev branch is not guaranteed to work. Please use caution if you choose to use that branch.
|
WARNING: The dev branch is not guaranteed to work. Please use caution if you choose to use that branch.
|
||||||
|
|
|
@ -41,7 +41,6 @@ void setup() {
|
||||||
digitalWrite(MIC_PIN, LOW);
|
digitalWrite(MIC_PIN, LOW);
|
||||||
|
|
||||||
// prep the switch
|
// prep the switch
|
||||||
// NOTE: HamShieldMini doesn't have a reset pin, so this has no effect
|
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
// set up the reset control pin
|
// set up the reset control pin
|
||||||
|
|
|
@ -24,7 +24,6 @@ void setup() {
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
// set up the reset control pin
|
// set up the reset control pin
|
||||||
// NOTE: HamShieldMini doesn't have a reset pin, so this has no effect
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
delay(5); // wait for device to come up
|
delay(5); // wait for device to come up
|
||||||
|
|
|
@ -50,7 +50,6 @@ void setup() {
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
// set up the reset control pin
|
// set up the reset control pin
|
||||||
// NOTE: HamShieldMini doesn't have a reset pin, so this has no effect
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN, LOW);
|
digitalWrite(RESET_PIN, LOW);
|
||||||
|
|
||||||
|
@ -69,10 +68,10 @@ void setup() {
|
||||||
|
|
||||||
// verify connection
|
// verify connection
|
||||||
Serial.println("Testing device connections...");
|
Serial.println("Testing device connections...");
|
||||||
Serial.println(radio.testConnection() ? "radio connection successful" : "radio connection failed");
|
Serial.println(radio.testConnection() ? "RDA radio connection successful" : "RDA radio connection failed");
|
||||||
|
|
||||||
// initialize device
|
// initialize device
|
||||||
Serial.println("Initializing radio device...");
|
Serial.println("Initializing I2C devices...");
|
||||||
radio.initialize(); // initializes automatically for UHF 12.5kHz channel
|
radio.initialize(); // initializes automatically for UHF 12.5kHz channel
|
||||||
|
|
||||||
Serial.println("setting default Radio configuration");
|
Serial.println("setting default Radio configuration");
|
||||||
|
@ -167,7 +166,7 @@ void loop() {
|
||||||
} else {
|
} else {
|
||||||
Serial.setTimeout(40);
|
Serial.setTimeout(40);
|
||||||
freq = Serial.parseInt();
|
freq = Serial.parseInt();
|
||||||
while (Serial.available()) Serial.read();
|
Serial.flush();
|
||||||
radio.frequency(freq);
|
radio.frequency(freq);
|
||||||
Serial.print("set frequency: ");
|
Serial.print("set frequency: ");
|
||||||
Serial.println(freq);
|
Serial.println(freq);
|
||||||
|
|
|
@ -33,7 +33,6 @@ void setup() {
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
// set up the reset control pin
|
// set up the reset control pin
|
||||||
// NOTE: HamShieldMini doesn't have a reset pin, so this has no effect
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
// turn on radio
|
// turn on radio
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
|
|
|
@ -35,7 +35,6 @@ void setup() {
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
// set up the reset control pin
|
// set up the reset control pin
|
||||||
// NOTE: HamShieldMini doesn't have a reset pin, so this has no effect
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN, LOW);
|
digitalWrite(RESET_PIN, LOW);
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ void setup() {
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
// set up the reset control pin
|
// set up the reset control pin
|
||||||
// NOTE: HamShieldMini doesn't have a reset pin, so this has no effect
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
delay(5); // wait for device to come up
|
delay(5); // wait for device to come up
|
||||||
|
|
|
@ -36,7 +36,6 @@ void setup() {
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
// set up the reset control pin
|
// set up the reset control pin
|
||||||
// NOTE: HamShieldMini doesn't have a reset pin, so this has no effect
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
delay(5); // wait for device to come up
|
delay(5); // wait for device to come up
|
||||||
|
|
|
@ -46,7 +46,6 @@ void setup() {
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
// set up the reset control pin
|
// set up the reset control pin
|
||||||
// NOTE: HamShieldMini doesn't have a reset pin, so this has no effect
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN, LOW);
|
digitalWrite(RESET_PIN, LOW);
|
||||||
|
|
||||||
|
@ -58,8 +57,7 @@ void setup() {
|
||||||
while (digitalRead(SWITCH_PIN) && !Serial.available());
|
while (digitalRead(SWITCH_PIN) && !Serial.available());
|
||||||
Serial.read(); // flush
|
Serial.read(); // flush
|
||||||
|
|
||||||
// let the radio out of reset
|
// let the AU ot of reset
|
||||||
// NOTE: HamShieldMini doesn't have a reset pin, so this has no effect
|
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
delay(5); // wait for device to come up
|
delay(5); // wait for device to come up
|
||||||
|
|
||||||
|
@ -67,10 +65,10 @@ void setup() {
|
||||||
|
|
||||||
// verify connection
|
// verify connection
|
||||||
Serial.println("Testing device connections...");
|
Serial.println("Testing device connections...");
|
||||||
Serial.println(radio.testConnection() ? "radio connection successful" : "radio connection failed");
|
Serial.println(radio.testConnection() ? "RDA radio connection successful" : "RDA radio connection failed");
|
||||||
|
|
||||||
// initialize device
|
// initialize device
|
||||||
Serial.println("Initializing radio device...");
|
Serial.println("Initializing I2C devices...");
|
||||||
radio.initialize(); // initializes automatically for UHF 12.5kHz channel
|
radio.initialize(); // initializes automatically for UHF 12.5kHz channel
|
||||||
|
|
||||||
Serial.println("setting default Radio configuration");
|
Serial.println("setting default Radio configuration");
|
||||||
|
@ -137,7 +135,7 @@ void loop() {
|
||||||
} else {
|
} else {
|
||||||
Serial.setTimeout(40);
|
Serial.setTimeout(40);
|
||||||
freq = Serial.parseInt();
|
freq = Serial.parseInt();
|
||||||
while (Serial.available()) Serial.read();
|
Serial.flush();
|
||||||
radio.frequency(freq);
|
radio.frequency(freq);
|
||||||
Serial.print("set frequency: ");
|
Serial.print("set frequency: ");
|
||||||
Serial.println(freq);
|
Serial.println(freq);
|
||||||
|
|
|
@ -1,283 +1,282 @@
|
||||||
/* Hamshield
|
/* Hamshield
|
||||||
* Example: HandyTalkie_nRF52840
|
* Example: HandyTalkie_nRF52840
|
||||||
* This is a simple example to demonstrate the HamShield working
|
* This is a simple example to demonstrate the HamShield working
|
||||||
* with an Adafruit Feather nRF52840 Express
|
* with an Adafruit Feather nRF52840 Express
|
||||||
*
|
*
|
||||||
* HamShield to Feather Connections:
|
* HamShield to Feather Connections:
|
||||||
* SPKR - Feather A0
|
* SPKR - Feather A0
|
||||||
* MIC - Feather D11
|
* MIC - Feather D11
|
||||||
* CLK - Feather D5
|
* CLK - Feather D5
|
||||||
* nCS - Feather D6
|
* nCS - Feather D6
|
||||||
* DAT - Feather D9
|
* DAT - Feather D9
|
||||||
* GND - Feather GND
|
* GND - Feather GND
|
||||||
* VCC - Feather 3.3V
|
* VCC - Feather 3.3V
|
||||||
*
|
*
|
||||||
* Connect the HamShield to your Feather as above.
|
* Connect the HamShield to your Feather as above.
|
||||||
* Screw the antenna into the HamShield RF jack. Plug a pair
|
* Screw the antenna into the HamShield RF jack. Plug a pair
|
||||||
* of headphones into the HamShield.
|
* of headphones into the HamShield.
|
||||||
*
|
*
|
||||||
* Connect the Feather nRF52840 Express to your computer via
|
* Connect the Feather nRF52840 Express to your computer via
|
||||||
* a USB Micro B cable. After uploading this program to
|
* a USB Micro B cable. After uploading this program to
|
||||||
* your Feather, open the Serial Monitor. You should see some
|
* your Feather, open the Serial Monitor. You should see some
|
||||||
* text displayed that documents the setup process.
|
* text displayed that documents the setup process.
|
||||||
*
|
*
|
||||||
* Once the Feather is set up and talking to the HamShield,
|
* Once the Feather is set up and talking to the HamShield,
|
||||||
* you can control it over USB-Serial or BLE-Serial(UART).
|
* you can control it over USB-Serial or BLE-Serial(UART).
|
||||||
*
|
*
|
||||||
* Try using Adafruit's Bluefruit app to connect to the Feather.
|
* Try using Adafruit's Bluefruit app to connect to the Feather.
|
||||||
* Once you're connected, you can control the HamShield using
|
* Once you're connected, you can control the HamShield using
|
||||||
* the same commands you'd use over USB-Serial. The response to
|
* the same commands you'd use over USB-Serial. The response to
|
||||||
* all commands will be echoed to both USB-Serial and BLE-Serial(UART).
|
* all commands will be echoed to both USB-Serial and BLE-Serial(UART).
|
||||||
*
|
*
|
||||||
* Serial UART commands:
|
* Serial UART commands:
|
||||||
* t - change from Tx to Rx (or vice versa)
|
* t - change from Tx to Rx (or vice versa)
|
||||||
* F123400 - set frequency to 123400 kHz
|
* F123400 - set frequency to 123400 kHz
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <bluefruit.h>
|
#include <bluefruit.h>
|
||||||
|
|
||||||
// BLE Service
|
// BLE Service
|
||||||
BLEDis bledis; // device information
|
BLEDis bledis; // device information
|
||||||
BLEUart bleuart; // uart over ble
|
BLEUart bleuart; // uart over ble
|
||||||
BLEBas blebas; // battery
|
BLEBas blebas; // battery
|
||||||
|
|
||||||
#include <HamShield.h>
|
#include <HamShield.h>
|
||||||
// create object for radio
|
// create object for radio
|
||||||
HamShield radio(6,5,9);
|
HamShield radio(9,5,6);
|
||||||
// To use non-standard pins, use the following initialization
|
// To use non-standard pins, use the following initialization
|
||||||
//HamShield radio(ncs_pin, clk_pin, dat_pin);
|
//HamShield radio(ncs_pin, clk_pin, dat_pin);
|
||||||
|
|
||||||
#define LED_PIN 3
|
#define LED_PIN 3
|
||||||
#define RSSI_REPORT_RATE_MS 5000
|
#define RSSI_REPORT_RATE_MS 5000
|
||||||
|
|
||||||
#define MIC_PIN A1
|
#define MIC_PIN A1
|
||||||
|
|
||||||
bool blinkState = false;
|
bool blinkState = false;
|
||||||
bool currently_tx;
|
bool currently_tx;
|
||||||
|
|
||||||
uint32_t freq;
|
uint32_t freq;
|
||||||
|
|
||||||
unsigned long rssi_timeout;
|
unsigned long rssi_timeout;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
// NOTE: if not using PWM out, it should be held low to avoid tx noise
|
// NOTE: if not using PWM out, it should be held low to avoid tx noise
|
||||||
pinMode(MIC_PIN, OUTPUT);
|
pinMode(MIC_PIN, OUTPUT);
|
||||||
digitalWrite(MIC_PIN, LOW);
|
digitalWrite(MIC_PIN, LOW);
|
||||||
|
|
||||||
// initialize serial communication
|
// initialize serial communication
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
while (!Serial) delay(10);
|
while (!Serial) delay(10);
|
||||||
Serial.println("Setting up BLE");
|
Serial.println("Setting up BLE");
|
||||||
|
|
||||||
// Setup the BLE LED to be enabled on CONNECT
|
// Setup the BLE LED to be enabled on CONNECT
|
||||||
// Note: This is actually the default behaviour, but provided
|
// Note: This is actually the default behaviour, but provided
|
||||||
// here in case you want to control this LED manually via PIN 19
|
// here in case you want to control this LED manually via PIN 19
|
||||||
Bluefruit.autoConnLed(true);
|
Bluefruit.autoConnLed(true);
|
||||||
|
|
||||||
// Config the peripheral connection with maximum bandwidth
|
// Config the peripheral connection with maximum bandwidth
|
||||||
// more SRAM required by SoftDevice
|
// more SRAM required by SoftDevice
|
||||||
// Note: All config***() function must be called before begin()
|
// Note: All config***() function must be called before begin()
|
||||||
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
|
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
|
||||||
|
|
||||||
Bluefruit.begin();
|
Bluefruit.begin();
|
||||||
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
|
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
|
||||||
Bluefruit.setTxPower(4);
|
Bluefruit.setTxPower(4);
|
||||||
Bluefruit.setName("MyBlueHam");
|
Bluefruit.setName("MyBlueHam");
|
||||||
//Bluefruit.setName(getMcuUniqueID()); // useful testing with multiple central connections
|
//Bluefruit.setName(getMcuUniqueID()); // useful testing with multiple central connections
|
||||||
Bluefruit.setConnectCallback(connect_callback);
|
Bluefruit.setConnectCallback(connect_callback);
|
||||||
Bluefruit.setDisconnectCallback(disconnect_callback);
|
Bluefruit.setDisconnectCallback(disconnect_callback);
|
||||||
|
|
||||||
// Configure and Start Device Information Service
|
// Configure and Start Device Information Service
|
||||||
bledis.setManufacturer("Enhanced Radio Devices");
|
bledis.setManufacturer("Enhanced Radio Devices");
|
||||||
bledis.setModel("BlueHam");
|
bledis.setModel("BlueHam");
|
||||||
bledis.begin();
|
bledis.begin();
|
||||||
|
|
||||||
// Configure and Start BLE Uart Service
|
// Configure and Start BLE Uart Service
|
||||||
bleuart.begin();
|
bleuart.begin();
|
||||||
|
|
||||||
// Start BLE Battery Service
|
// Start BLE Battery Service
|
||||||
blebas.begin();
|
blebas.begin();
|
||||||
blebas.write(100);
|
blebas.write(100);
|
||||||
|
|
||||||
// Set up and start advertising
|
// Set up and start advertising
|
||||||
startAdv();
|
startAdv();
|
||||||
|
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
Serial.println("beginning Ham radio setup");
|
Serial.println("beginning Ham radio setup");
|
||||||
|
|
||||||
// verify connection
|
// verify connection
|
||||||
Serial.println("Testing device connections...");
|
Serial.println("Testing device connections...");
|
||||||
if (radio.testConnection()) {
|
if (radio.testConnection()) {
|
||||||
Serial.println("HamShield connection successful");
|
Serial.println("HamShield connection successful");
|
||||||
} else {
|
} else {
|
||||||
Serial.print("HamShield connection failed");
|
Serial.print("HamShield connection failed");
|
||||||
while(1) delay(100);
|
while(1) delay(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize device
|
// initialize device
|
||||||
Serial.println("Initializing radio device...");
|
Serial.println("Initializing I2C devices...");
|
||||||
radio.initialize(); // initializes automatically for UHF 12.5kHz channel
|
radio.initialize(); // initializes automatically for UHF 12.5kHz channel
|
||||||
|
|
||||||
Serial.println("setting default Radio configuration");
|
Serial.println("setting default Radio configuration");
|
||||||
|
|
||||||
// set frequency
|
// set frequency
|
||||||
Serial.println("changing frequency");
|
Serial.println("changing frequency");
|
||||||
|
|
||||||
radio.setSQOff();
|
radio.setSQOff();
|
||||||
freq = 432100; // 70cm calling frequency
|
freq = 432100; // 70cm calling frequency
|
||||||
radio.frequency(freq);
|
radio.frequency(freq);
|
||||||
|
|
||||||
// set to receive
|
// set to receive
|
||||||
|
|
||||||
radio.setModeReceive();
|
radio.setModeReceive();
|
||||||
currently_tx = false;
|
currently_tx = false;
|
||||||
Serial.print("config register is: ");
|
Serial.print("config register is: ");
|
||||||
Serial.println(radio.readCtlReg());
|
Serial.println(radio.readCtlReg());
|
||||||
Serial.println(radio.readRSSI());
|
Serial.println(radio.readRSSI());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// set to transmit
|
// set to transmit
|
||||||
radio.setModeTransmit();
|
radio.setModeTransmit();
|
||||||
// maybe set PA bias voltage
|
// maybe set PA bias voltage
|
||||||
Serial.println("configured for transmit");
|
Serial.println("configured for transmit");
|
||||||
radio.setTxSourceMic();
|
radio.setTxSourceMic();
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
radio.setRfPower(0);
|
radio.setRfPower(0);
|
||||||
|
|
||||||
// configure Arduino LED for
|
// configure Arduino LED for
|
||||||
pinMode(LED_PIN, OUTPUT);
|
pinMode(LED_PIN, OUTPUT);
|
||||||
digitalWrite(LED_PIN, HIGH);
|
digitalWrite(LED_PIN, HIGH);
|
||||||
rssi_timeout = 0;
|
rssi_timeout = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void startAdv(void)
|
void startAdv(void)
|
||||||
{
|
{
|
||||||
// Advertising packet
|
// Advertising packet
|
||||||
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
||||||
Bluefruit.Advertising.addTxPower();
|
Bluefruit.Advertising.addTxPower();
|
||||||
|
|
||||||
// Include bleuart 128-bit uuid
|
// Include bleuart 128-bit uuid
|
||||||
Bluefruit.Advertising.addService(bleuart);
|
Bluefruit.Advertising.addService(bleuart);
|
||||||
|
|
||||||
// Secondary Scan Response packet (optional)
|
// Secondary Scan Response packet (optional)
|
||||||
// Since there is no room for 'Name' in Advertising packet
|
// Since there is no room for 'Name' in Advertising packet
|
||||||
Bluefruit.ScanResponse.addName();
|
Bluefruit.ScanResponse.addName();
|
||||||
|
|
||||||
/* Start Advertising
|
/* Start Advertising
|
||||||
* - Enable auto advertising if disconnected
|
* - Enable auto advertising if disconnected
|
||||||
* - Interval: fast mode = 20 ms, slow mode = 152.5 ms
|
* - Interval: fast mode = 20 ms, slow mode = 152.5 ms
|
||||||
* - Timeout for fast mode is 30 seconds
|
* - Timeout for fast mode is 30 seconds
|
||||||
* - Start(timeout) with timeout = 0 will advertise forever (until connected)
|
* - Start(timeout) with timeout = 0 will advertise forever (until connected)
|
||||||
*
|
*
|
||||||
* For recommended advertising interval
|
* For recommended advertising interval
|
||||||
* https://developer.apple.com/library/content/qa/qa1931/_index.html
|
* https://developer.apple.com/library/content/qa/qa1931/_index.html
|
||||||
*/
|
*/
|
||||||
Bluefruit.Advertising.restartOnDisconnect(true);
|
Bluefruit.Advertising.restartOnDisconnect(true);
|
||||||
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
|
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
|
||||||
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
|
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
|
||||||
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
|
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
|
||||||
}
|
}
|
||||||
|
|
||||||
// for serial output buffer on both interfaces
|
#define TEXT_BUF_LEN 64
|
||||||
#define TEXT_BUF_LEN 64
|
char text_buf[TEXT_BUF_LEN];
|
||||||
char text_buf[TEXT_BUF_LEN];
|
void loop() {
|
||||||
void loop() {
|
|
||||||
|
char c = 0;
|
||||||
char c = 0;
|
bool ble_serial = false;
|
||||||
bool ble_serial = false;
|
if (Serial.available()) {
|
||||||
if (Serial.available()) {
|
Serial.readBytes(&c, 1);
|
||||||
Serial.readBytes(&c, 1);
|
} else if (bleuart.available()) {
|
||||||
} else if (bleuart.available()) {
|
c = (char) bleuart.read();
|
||||||
c = (char) bleuart.read();
|
ble_serial = true;
|
||||||
ble_serial = true;
|
}
|
||||||
}
|
|
||||||
|
if (c != 0) {
|
||||||
if (c != 0) {
|
if (c == 't')
|
||||||
if (c == 't')
|
{
|
||||||
{
|
if (!currently_tx)
|
||||||
if (!currently_tx)
|
{
|
||||||
{
|
currently_tx = true;
|
||||||
currently_tx = true;
|
|
||||||
|
// set to transmit
|
||||||
// set to transmit
|
radio.setModeTransmit();
|
||||||
radio.setModeTransmit();
|
|
||||||
|
Serial.println("Tx");
|
||||||
Serial.println("Tx");
|
int str_len = snprintf(text_buf, TEXT_BUF_LEN, "Tx\n");
|
||||||
int str_len = snprintf(text_buf, TEXT_BUF_LEN, "Tx\n");
|
bleuart.write(text_buf, str_len);
|
||||||
bleuart.write(text_buf, str_len);
|
//radio.setTxSourceMic();
|
||||||
//radio.setTxSourceMic();
|
//radio.setRfPower(1);
|
||||||
//radio.setRfPower(1);
|
} else {
|
||||||
} else {
|
radio.setModeReceive();
|
||||||
radio.setModeReceive();
|
currently_tx = false;
|
||||||
currently_tx = false;
|
Serial.println("Rx");
|
||||||
Serial.println("Rx");
|
int str_len = snprintf(text_buf, TEXT_BUF_LEN, "Rx\n");
|
||||||
int str_len = snprintf(text_buf, TEXT_BUF_LEN, "Rx\n");
|
bleuart.write(text_buf, str_len);
|
||||||
bleuart.write(text_buf, str_len);
|
}
|
||||||
}
|
} else if (c == 'F') {
|
||||||
} else if (c == 'F') {
|
if (ble_serial == false) {
|
||||||
if (ble_serial == false) {
|
Serial.setTimeout(40);
|
||||||
Serial.setTimeout(40);
|
freq = Serial.parseInt();
|
||||||
freq = Serial.parseInt();
|
Serial.flush();
|
||||||
Serial.flush();
|
} else {
|
||||||
} else {
|
int idx = 0;
|
||||||
int idx = 0;
|
while (bleuart.available() &&
|
||||||
while (bleuart.available() &&
|
bleuart.peek() >= '0' &&
|
||||||
bleuart.peek() >= '0' &&
|
bleuart.peek() <= '9' &&
|
||||||
bleuart.peek() <= '9' &&
|
idx < TEXT_BUF_LEN) {
|
||||||
idx < TEXT_BUF_LEN) {
|
|
||||||
|
text_buf[idx] = bleuart.read();
|
||||||
text_buf[idx] = bleuart.read();
|
idx++;
|
||||||
idx++;
|
}
|
||||||
}
|
text_buf[idx] = 0; // null terminate
|
||||||
text_buf[idx] = 0; // null terminate
|
freq = atoi(text_buf);
|
||||||
freq = atoi(text_buf);
|
}
|
||||||
}
|
radio.frequency(freq);
|
||||||
radio.frequency(freq);
|
Serial.print("set frequency: ");
|
||||||
Serial.print("set frequency: ");
|
Serial.println(freq);
|
||||||
Serial.println(freq);
|
int str_len = snprintf(text_buf, TEXT_BUF_LEN, "set frequency: %d\n", freq);
|
||||||
int str_len = snprintf(text_buf, TEXT_BUF_LEN, "set frequency: %d\n", freq);
|
bleuart.write(text_buf, str_len);
|
||||||
bleuart.write(text_buf, str_len);
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if (!currently_tx && (millis() - rssi_timeout) > RSSI_REPORT_RATE_MS)
|
||||||
if (!currently_tx && (millis() - rssi_timeout) > RSSI_REPORT_RATE_MS)
|
{
|
||||||
{
|
int rssi = radio.readRSSI();
|
||||||
int rssi = radio.readRSSI();
|
Serial.println(rssi);
|
||||||
Serial.println(rssi);
|
int str_len = snprintf(text_buf, TEXT_BUF_LEN, "rssi: %d\n", rssi);
|
||||||
int str_len = snprintf(text_buf, TEXT_BUF_LEN, "rssi: %d\n", rssi);
|
bleuart.write(text_buf, str_len);
|
||||||
bleuart.write(text_buf, str_len);
|
rssi_timeout = millis();
|
||||||
rssi_timeout = millis();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// callback invoked when central connects
|
||||||
// callback invoked when central connects
|
void connect_callback(uint16_t conn_handle)
|
||||||
void connect_callback(uint16_t conn_handle)
|
{
|
||||||
{
|
char central_name[32] = { 0 };
|
||||||
char central_name[32] = { 0 };
|
Bluefruit.Gap.getPeerName(conn_handle, central_name, sizeof(central_name));
|
||||||
Bluefruit.Gap.getPeerName(conn_handle, central_name, sizeof(central_name));
|
|
||||||
|
Serial.print("Connected to ");
|
||||||
Serial.print("Connected to ");
|
Serial.println(central_name);
|
||||||
Serial.println(central_name);
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Callback invoked when a connection is dropped
|
||||||
* Callback invoked when a connection is dropped
|
* @param conn_handle connection where this event happens
|
||||||
* @param conn_handle connection where this event happens
|
* @param reason is a BLE_HCI_STATUS_CODE which can be found in ble_hci.h
|
||||||
* @param reason is a BLE_HCI_STATUS_CODE which can be found in ble_hci.h
|
* https://github.com/adafruit/Adafruit_nRF52_Arduino/blob/master/cores/nRF5/nordic/softdevice/s140_nrf52_6.1.1_API/include/ble_hci.h
|
||||||
* https://github.com/adafruit/Adafruit_nRF52_Arduino/blob/master/cores/nRF5/nordic/softdevice/s140_nrf52_6.1.1_API/include/ble_hci.h
|
*/
|
||||||
*/
|
void disconnect_callback(uint16_t conn_handle, uint8_t reason)
|
||||||
void disconnect_callback(uint16_t conn_handle, uint8_t reason)
|
{
|
||||||
{
|
(void) conn_handle;
|
||||||
(void) conn_handle;
|
(void) reason;
|
||||||
(void) reason;
|
|
||||||
|
Serial.println();
|
||||||
Serial.println();
|
Serial.println("Disconnected");
|
||||||
Serial.println("Disconnected");
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -48,7 +48,6 @@ void setup() {
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
// set up the reset control pin
|
// set up the reset control pin
|
||||||
// NOTE: HamShieldMini doesn't have a reset pin, so this has no effect
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
delay(5); // wait for device to come up
|
delay(5); // wait for device to come up
|
||||||
|
|
|
@ -49,7 +49,6 @@ void setup() {
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
// set up the reset control pin
|
// set up the reset control pin
|
||||||
// NOTE: HamShieldMini doesn't have a reset pin, so this has no effect
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
delay(5); // wait for device to come up
|
delay(5); // wait for device to come up
|
||||||
|
|
|
@ -35,7 +35,6 @@ void setup() {
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
// set up the reset control pin
|
// set up the reset control pin
|
||||||
// NOTE: HamShieldMini doesn't have a reset pin, so this has no effect
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
delay(5); // wait for device to come up
|
delay(5); // wait for device to come up
|
||||||
|
|
|
@ -39,7 +39,6 @@ void setup() {
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
// set up the reset control pin
|
// set up the reset control pin
|
||||||
// NOTE: HamShieldMini doesn't have a reset pin, so this has no effect
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
delay(5); // wait for device to come up
|
delay(5); // wait for device to come up
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,704 +0,0 @@
|
||||||
/* Hamshield
|
|
||||||
* Example: AppSerialController_nRF52840
|
|
||||||
* This is a simple example to demonstrate the HamShield working
|
|
||||||
* with an Adafruit Feather nRF52840 Express
|
|
||||||
*
|
|
||||||
* HamShield to Feather Connections:
|
|
||||||
* SPKR - Feather A0
|
|
||||||
* MIC - Feather D11
|
|
||||||
* CLK - Feather D5
|
|
||||||
* nCS - Feather D6
|
|
||||||
* DAT - Feather D9
|
|
||||||
* GND - Feather GND
|
|
||||||
* VCC - Feather 3.3V
|
|
||||||
*
|
|
||||||
* Connect the HamShield to your Feather as above.
|
|
||||||
* Screw the antenna into the HamShield RF jack. Plug a pair
|
|
||||||
* of headphones into the HamShield.
|
|
||||||
*
|
|
||||||
* Connect the Feather nRF52840 Express to your computer via
|
|
||||||
* a USB Micro B cable. After uploading this program to
|
|
||||||
* your Feather, open the Serial Monitor. You should see some
|
|
||||||
* text displayed that documents the setup process.
|
|
||||||
*
|
|
||||||
* Once the Feather is set up and talking to the HamShield,
|
|
||||||
* you can control it over USB-Serial or BLE-Serial(UART).
|
|
||||||
*
|
|
||||||
* Try using Adafruit's Bluefruit app to connect to the Feather.
|
|
||||||
* Once you're connected, you can control the HamShield using
|
|
||||||
* the same commands you'd use over USB-Serial. The response to
|
|
||||||
* all commands will be echoed to both USB-Serial and BLE-Serial(UART).
|
|
||||||
*
|
|
||||||
|
|
||||||
Commands:
|
|
||||||
|
|
||||||
Mode ASCII Description
|
|
||||||
-------------- ----------- --------------------------------------------------------------------------------------------------------------------------------------------
|
|
||||||
Transmit space Space must be received at least every 500 mS
|
|
||||||
Receive not space If space is not received and/or 500 mS timeout of space occurs, unit will go into receive mode
|
|
||||||
Frequency F<freq>; Set the receive frequency in KHz, if offset is disabled, this is the transmit frequency
|
|
||||||
Morse Out M<text>; A small buffer for morse code (32 chars)
|
|
||||||
Morse In N; Sets mode to Morse In, listening for Morse
|
|
||||||
Power level P<level>; Set the power amp level, 0 = lowest, 15 = highest
|
|
||||||
Enable Offset R<state>; 1 turns on repeater offset mode, 0 turns off repeater offset mode
|
|
||||||
Squelch S<level>; Set the squelch level
|
|
||||||
TX Offset T<freq>; The absolute frequency of the repeater offset to transmit on in KHz
|
|
||||||
RSSI ? Respond with the current receive level in - dBm (no sign provided on numerical response)
|
|
||||||
Voice Level ^ Respond with the current voice level (VSSI), only valid when transmitting
|
|
||||||
DTMF Out D<vals>; A small buffer for DTMF out (only 0-9,A,B,C,D,*,# accepted)
|
|
||||||
DTMF In B; Sets mode to DTMF In, listening for DTMF
|
|
||||||
PL Tone Tx A<val>; Sets PL tone for TX, value is tone frequency in Hz (float), set to 0 to disable
|
|
||||||
PL Tone Rx C<val>; Sets PL tone for RX, value is tone frequency in Hz (float), set to 0 to disable
|
|
||||||
Volume 1 V1<val>; Set volume 1 (value between 0 and 15)
|
|
||||||
Volume 2 V2<val>; Set volume 2 (value between 0 and 15)
|
|
||||||
KISS TNC K; Move to KISS TNC mode (send ^; to move back to normal mode). NOT IMPELEMENTED YET
|
|
||||||
Normal Mode _ Move to Normal mode from any other mode (except TX)
|
|
||||||
|
|
||||||
Responses:
|
|
||||||
|
|
||||||
Condition ASCII Description
|
|
||||||
------------ ---------- -----------------------------------------------------------------
|
|
||||||
Startup *<code>; Startup and shield connection status
|
|
||||||
Success !; Generic success message for command that returns no value
|
|
||||||
Error X<code>; Indicates an error code. The numerical value is the type of error
|
|
||||||
Value :<value>; In response to a query
|
|
||||||
Status #<value>; Unsolicited status message
|
|
||||||
Debug Msg @<text>; 32 character debug message
|
|
||||||
Rx Msg R<text>; up to 32 characters of received message, only if device is in DTMF or Morse Rx modes
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Note that the following are not yet implemented
|
|
||||||
// TODO: change get_value so it's intuitive
|
|
||||||
// TODO: Squelch open and squelch shut independently controllable
|
|
||||||
// TODO: pre/de emph filter
|
|
||||||
// TODO: walkie-talkie
|
|
||||||
// TODO: KISS TNC
|
|
||||||
|
|
||||||
#include <bluefruit.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <HamShield.h>
|
|
||||||
|
|
||||||
// BLE Service
|
|
||||||
BLEDis bledis; // device information
|
|
||||||
BLEUart bleuart; // uart over ble
|
|
||||||
BLEBas blebas; // battery
|
|
||||||
|
|
||||||
|
|
||||||
// create object for radio
|
|
||||||
HamShield radio(6,5,9);
|
|
||||||
// To use non-standard pins, use the following initialization
|
|
||||||
//HamShield radio(ncs_pin, clk_pin, dat_pin);
|
|
||||||
|
|
||||||
#define LED_PIN 3
|
|
||||||
|
|
||||||
#define MIC_PIN A1
|
|
||||||
|
|
||||||
|
|
||||||
enum {TX, NORMAL, DTMF, MORSE, KISS};
|
|
||||||
|
|
||||||
int state = NORMAL;
|
|
||||||
bool rx_ctcss = false;
|
|
||||||
bool muted = false;
|
|
||||||
|
|
||||||
int txcount = 0;
|
|
||||||
long timer = 0; // Transmit timer to track timeout (send space to reset)
|
|
||||||
|
|
||||||
long freq = 432100; // 70cm calling frequency, receive frequency and default transmit frequency
|
|
||||||
long tx_freq = 0; // transmit frequency if repeater is on
|
|
||||||
int pwr = 0; // tx power
|
|
||||||
|
|
||||||
char cmdbuff[32] = "";
|
|
||||||
int temp = 0;
|
|
||||||
|
|
||||||
bool repeater = false; // true if transmit and receive operate on different frequencies
|
|
||||||
char pl_rx_buffer[32]; // pl tone rx buffer
|
|
||||||
char pl_tx_buffer[32]; // pl tone tx buffer
|
|
||||||
|
|
||||||
float ctcssin = 0;
|
|
||||||
float ctcssout = 0;
|
|
||||||
int cdcssin = 0;
|
|
||||||
int cdcssout = 0;
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
// NOTE: if not using PWM out (MIC pin), it should be held low to avoid tx noise
|
|
||||||
pinMode(MIC_PIN, OUTPUT);
|
|
||||||
digitalWrite(MIC_PIN, LOW);
|
|
||||||
|
|
||||||
// initialize serial communication
|
|
||||||
Serial.begin(115200);
|
|
||||||
while (!Serial) delay(10);
|
|
||||||
|
|
||||||
// Setup the BLE LED to be enabled on CONNECT
|
|
||||||
// Note: This is actually the default behaviour, but provided
|
|
||||||
// here in case you want to control this LED manually via PIN 19
|
|
||||||
Bluefruit.autoConnLed(true);
|
|
||||||
|
|
||||||
// Config the peripheral connection with maximum bandwidth
|
|
||||||
// more SRAM required by SoftDevice
|
|
||||||
// Note: All config***() function must be called before begin()
|
|
||||||
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
|
|
||||||
|
|
||||||
Bluefruit.begin();
|
|
||||||
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
|
|
||||||
Bluefruit.setTxPower(4);
|
|
||||||
Bluefruit.setName("MyBlueHam");
|
|
||||||
//Bluefruit.setName(getMcuUniqueID()); // useful testing with multiple central connections
|
|
||||||
Bluefruit.setConnectCallback(connect_callback);
|
|
||||||
Bluefruit.setDisconnectCallback(disconnect_callback);
|
|
||||||
|
|
||||||
// Configure and Start Device Information Service
|
|
||||||
bledis.setManufacturer("Enhanced Radio Devices");
|
|
||||||
bledis.setModel("BlueHam");
|
|
||||||
bledis.begin();
|
|
||||||
|
|
||||||
// Configure and Start BLE Uart Service
|
|
||||||
bleuart.begin();
|
|
||||||
|
|
||||||
// Start BLE Battery Service
|
|
||||||
blebas.begin();
|
|
||||||
blebas.write(100);
|
|
||||||
|
|
||||||
// Set up and start advertising
|
|
||||||
startAdv();
|
|
||||||
|
|
||||||
delay(100);
|
|
||||||
|
|
||||||
SerialWrite(";;;;;;;;;;;;;;;;;;;;;;;;;;\n");
|
|
||||||
|
|
||||||
int result = radio.testConnection();
|
|
||||||
SerialWrite("*%d;\n", result);
|
|
||||||
radio.initialize(); // initializes automatically for UHF 12.5kHz channel
|
|
||||||
radio.frequency(freq);
|
|
||||||
radio.setVolume1(0xF);
|
|
||||||
radio.setVolume2(0xF);
|
|
||||||
radio.setModeReceive();
|
|
||||||
radio.setTxSourceMic();
|
|
||||||
radio.setRfPower(pwr);
|
|
||||||
radio.setSQLoThresh(-80);
|
|
||||||
radio.setSQHiThresh(-70);
|
|
||||||
radio.setSQOn();
|
|
||||||
SerialWrite("*START;\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void startAdv(void)
|
|
||||||
{
|
|
||||||
// Advertising packet
|
|
||||||
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
|
||||||
Bluefruit.Advertising.addTxPower();
|
|
||||||
|
|
||||||
// Include bleuart 128-bit uuid
|
|
||||||
Bluefruit.Advertising.addService(bleuart);
|
|
||||||
|
|
||||||
// Secondary Scan Response packet (optional)
|
|
||||||
// Since there is no room for 'Name' in Advertising packet
|
|
||||||
Bluefruit.ScanResponse.addName();
|
|
||||||
|
|
||||||
/* Start Advertising
|
|
||||||
* - Enable auto advertising if disconnected
|
|
||||||
* - Interval: fast mode = 20 ms, slow mode = 152.5 ms
|
|
||||||
* - Timeout for fast mode is 30 seconds
|
|
||||||
* - Start(timeout) with timeout = 0 will advertise forever (until connected)
|
|
||||||
*
|
|
||||||
* For recommended advertising interval
|
|
||||||
* https://developer.apple.com/library/content/qa/qa1931/_index.html
|
|
||||||
*/
|
|
||||||
Bluefruit.Advertising.restartOnDisconnect(true);
|
|
||||||
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
|
|
||||||
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
|
|
||||||
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
// TODO: loop fixing based on serialtransciever!
|
|
||||||
|
|
||||||
char c = 0;
|
|
||||||
bool ble_serial = false;
|
|
||||||
if (Serial.available()) {
|
|
||||||
Serial.readBytes(&c, 1);
|
|
||||||
} else if (bleuart.available()) {
|
|
||||||
c = (char) bleuart.read();
|
|
||||||
ble_serial = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: BLE
|
|
||||||
if(c != 0) {
|
|
||||||
|
|
||||||
int text = c; // get the first char to see what the upcoming command is
|
|
||||||
|
|
||||||
switch (state) {
|
|
||||||
// we handle commands differently based on what state we're in
|
|
||||||
|
|
||||||
case TX:
|
|
||||||
// we're currently transmitting
|
|
||||||
// if we got a space, reset our transmit timeout
|
|
||||||
if(text == ' ') { timer = millis();}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NORMAL:
|
|
||||||
switch(text) {
|
|
||||||
case ' ': // space - transmit
|
|
||||||
if(repeater == true && tx_freq != 0) { radio.frequency(tx_freq); }
|
|
||||||
muted = false; // can't mute (for PL tones) during tx
|
|
||||||
radio.setUnmute();
|
|
||||||
radio.setModeTransmit();
|
|
||||||
state = TX;
|
|
||||||
SerialWrite("#TX,ON;\n");
|
|
||||||
timer = millis();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '?': // ? - RSSI
|
|
||||||
SerialWrite(":%d;\n", radio.readRSSI());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '^': // ^ - VSSI (voice) level
|
|
||||||
SerialWrite(":%d;\n", radio.readVSSI());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'F': // F - frequency
|
|
||||||
getValue(ble_serial);
|
|
||||||
freq = atol(cmdbuff);
|
|
||||||
if(radio.frequency(freq) == true) {
|
|
||||||
SerialWrite("@%d;!;\n", freq);
|
|
||||||
} else {
|
|
||||||
SerialWrite("X1;\n");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'P': // P - power level
|
|
||||||
getValue(ble_serial);
|
|
||||||
temp = atol(cmdbuff);
|
|
||||||
radio.setRfPower(temp);
|
|
||||||
SerialWrite("!;\n");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'S': // S - squelch
|
|
||||||
getValue(ble_serial);
|
|
||||||
temp = atol(cmdbuff);
|
|
||||||
if (temp < -2 && temp > -130) {
|
|
||||||
radio.setSQLoThresh(temp);
|
|
||||||
radio.setSQHiThresh(temp+2);
|
|
||||||
radio.setSQOn();
|
|
||||||
SerialWrite("%d!;\n", temp);
|
|
||||||
} else {
|
|
||||||
SerialWrite("X!;\n");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'R': // R - repeater offset mode
|
|
||||||
getValue(ble_serial);
|
|
||||||
temp = atol(cmdbuff);
|
|
||||||
if(temp == 0) { repeater = 0; }
|
|
||||||
if(temp == 1) { repeater = 1; }
|
|
||||||
SerialWrite("!;\n");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'T': // T - transmit offset
|
|
||||||
getValue(ble_serial);
|
|
||||||
tx_freq = atol(cmdbuff);
|
|
||||||
SerialWrite("!;\n");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'M': // M - Morse
|
|
||||||
getValue(ble_serial);
|
|
||||||
if(repeater == true && tx_freq != 0) { radio.frequency(tx_freq); }
|
|
||||||
muted = false; // can't mute (for PL tones) during tx
|
|
||||||
radio.setUnmute();
|
|
||||||
radio.setModeTransmit();
|
|
||||||
delay(300);
|
|
||||||
radio.morseOut(cmdbuff);
|
|
||||||
if(repeater == true) { radio.frequency(freq); }
|
|
||||||
radio.setModeReceive();
|
|
||||||
SerialWrite("!;\n");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'N': // N - set to Morse in Mode
|
|
||||||
morse_rx_setup();
|
|
||||||
state = MORSE;
|
|
||||||
SerialWrite("!;\n");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'D': // D - DTMF Out
|
|
||||||
dtmfSetup();
|
|
||||||
getValue(ble_serial);
|
|
||||||
dtmf_out(cmdbuff);
|
|
||||||
SerialWrite("!;\n");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'B': // B - set to DTMF in Mode
|
|
||||||
dtmfSetup();
|
|
||||||
radio.enableDTMFReceive();
|
|
||||||
state = DTMF;
|
|
||||||
SerialWrite("!;\n");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'A': // A - TX PL Tone configuration command
|
|
||||||
pl_tone_tx();
|
|
||||||
SerialWrite("!;\n");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'C': // C - RX PL Tone configuration command
|
|
||||||
pl_tone_rx();
|
|
||||||
SerialWrite("!;\n");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'V': // V - set volume
|
|
||||||
getValue(ble_serial);
|
|
||||||
temp = cmdbuff[0];
|
|
||||||
if (temp == 0x31) {
|
|
||||||
temp = atol(cmdbuff + 1);
|
|
||||||
radio.setVolume1(temp);
|
|
||||||
SerialWrite("!;\n");
|
|
||||||
} else if (temp == 0x32) {
|
|
||||||
temp = atol(cmdbuff + 1);
|
|
||||||
radio.setVolume2(temp);
|
|
||||||
SerialWrite("!;\n");
|
|
||||||
} else {
|
|
||||||
// not a valid volume command, flush buffers
|
|
||||||
SerialFlush(ble_serial);
|
|
||||||
SerialWrite("X!;\n");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'K': // K - switch to KISS TNC mode
|
|
||||||
//state = KISS;
|
|
||||||
//TODO: set up KISS
|
|
||||||
SerialWrite("X1;\n");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
// unknown command, flush the input buffer and wait for next one
|
|
||||||
SerialWrite("X1;\n");
|
|
||||||
SerialFlush(ble_serial);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case KISS:
|
|
||||||
if ((ble_serial && bleuart.peek() == '_') || (!ble_serial && Serial.peek() == '_')) {
|
|
||||||
state = NORMAL;
|
|
||||||
if (rx_ctcss) {
|
|
||||||
radio.enableCtcss();
|
|
||||||
muted = true; // can't mute (for PL tones) during tx
|
|
||||||
radio.setMute();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO: handle KISS TNC
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MORSE:
|
|
||||||
if (text == '_') { state = NORMAL; }
|
|
||||||
if (text == 'M') { // tx message
|
|
||||||
getValue(ble_serial);
|
|
||||||
if(repeater == true && tx_freq != 0) { radio.frequency(tx_freq); }
|
|
||||||
muted = false; // can't mute (for PL tones) during tx
|
|
||||||
radio.setUnmute();
|
|
||||||
radio.setModeTransmit();
|
|
||||||
delay(300);
|
|
||||||
radio.morseOut(cmdbuff);
|
|
||||||
if(repeater == true) { radio.frequency(freq); }
|
|
||||||
radio.setModeReceive();
|
|
||||||
} else {
|
|
||||||
// not a valid cmd
|
|
||||||
SerialFlush(ble_serial);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DTMF:
|
|
||||||
if (text == '_') { state = NORMAL; }
|
|
||||||
if (text == 'D') { // tx message
|
|
||||||
getValue(ble_serial);
|
|
||||||
dtmf_out(cmdbuff);
|
|
||||||
} else {
|
|
||||||
// not a valid cmd
|
|
||||||
SerialFlush(ble_serial);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
// we're in an invalid state, reset to safe settings
|
|
||||||
SerialFlush(ble_serial);
|
|
||||||
radio.frequency(freq);
|
|
||||||
radio.setModeReceive();
|
|
||||||
state = NORMAL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// now handle any state related functions
|
|
||||||
switch (state) {
|
|
||||||
case TX:
|
|
||||||
if(millis() > (timer + 500)) {
|
|
||||||
SerialWrite("#TX,OFF;\n");
|
|
||||||
radio.setModeReceive();
|
|
||||||
if(repeater == true) { radio.frequency(freq); }
|
|
||||||
if (rx_ctcss) {
|
|
||||||
radio.setMute();
|
|
||||||
muted = true;
|
|
||||||
}
|
|
||||||
txcount = 0;
|
|
||||||
state = NORMAL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NORMAL:
|
|
||||||
// deal with rx ctccs if necessary
|
|
||||||
if (rx_ctcss) {
|
|
||||||
if (radio.getCtcssToneDetected()) {
|
|
||||||
if (muted) {
|
|
||||||
muted = false;
|
|
||||||
radio.setUnmute();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!muted) {
|
|
||||||
muted = true;
|
|
||||||
radio.setMute();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DTMF:
|
|
||||||
dtmf_rx(); // wait for DTMF reception
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MORSE:
|
|
||||||
morse_rx(); // wait for Morse reception
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get rid of any trailing whitespace in the serial buffer
|
|
||||||
SerialFlushWhitespace(ble_serial);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// callback invoked when central connects
|
|
||||||
void connect_callback(uint16_t conn_handle)
|
|
||||||
{
|
|
||||||
char central_name[32] = { 0 };
|
|
||||||
Bluefruit.Gap.getPeerName(conn_handle, central_name, sizeof(central_name));
|
|
||||||
|
|
||||||
Serial.print("Connected to ");
|
|
||||||
Serial.println(central_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback invoked when a connection is dropped
|
|
||||||
* @param conn_handle connection where this event happens
|
|
||||||
* @param reason is a BLE_HCI_STATUS_CODE which can be found in ble_hci.h
|
|
||||||
* https://github.com/adafruit/Adafruit_nRF52_Arduino/blob/master/cores/nRF5/nordic/softdevice/s140_nrf52_6.1.1_API/include/ble_hci.h
|
|
||||||
*/
|
|
||||||
void disconnect_callback(uint16_t conn_handle, uint8_t reason)
|
|
||||||
{
|
|
||||||
(void) conn_handle;
|
|
||||||
(void) reason;
|
|
||||||
|
|
||||||
Serial.println();
|
|
||||||
Serial.println("Disconnected");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void getValue(bool ble_serial) {
|
|
||||||
int p = 0;
|
|
||||||
char temp;
|
|
||||||
|
|
||||||
for(;;) {
|
|
||||||
if((!ble_serial && Serial.available()) || (ble_serial && bleuart.available())) {
|
|
||||||
if (ble_serial) {
|
|
||||||
temp = bleuart.read();
|
|
||||||
} else {
|
|
||||||
temp = Serial.read();
|
|
||||||
}
|
|
||||||
if(temp == 59) {
|
|
||||||
cmdbuff[p] = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cmdbuff[p] = temp;
|
|
||||||
p++;
|
|
||||||
if(p == 32) {
|
|
||||||
cmdbuff[0] = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void dtmfSetup() {
|
|
||||||
radio.setVolume1(6);
|
|
||||||
radio.setVolume2(0);
|
|
||||||
radio.setDTMFDetectTime(24); // time to detect a DTMF code, units are 2.5ms
|
|
||||||
radio.setDTMFIdleTime(50); // time between transmitted DTMF codes, units are 2.5ms
|
|
||||||
radio.setDTMFTxTime(60); // duration of transmitted DTMF codes, units are 2.5ms
|
|
||||||
}
|
|
||||||
|
|
||||||
void dtmf_out(char * out_buf) {
|
|
||||||
if (out_buf[0] == ';' || out_buf[0] == 0) return; // empty message
|
|
||||||
|
|
||||||
uint8_t i = 0;
|
|
||||||
uint8_t code = radio.DTMFchar2code(out_buf[i]);
|
|
||||||
|
|
||||||
// start transmitting
|
|
||||||
radio.setDTMFCode(code); // set first
|
|
||||||
radio.setTxSourceTones();
|
|
||||||
if(repeater == true && tx_freq != 0) { radio.frequency(tx_freq); }
|
|
||||||
muted = false; // can't mute during transmit
|
|
||||||
radio.setUnmute();
|
|
||||||
radio.setModeTransmit();
|
|
||||||
delay(300); // wait for TX to come to full power
|
|
||||||
|
|
||||||
bool dtmf_to_tx = true;
|
|
||||||
while (dtmf_to_tx) {
|
|
||||||
// wait until ready
|
|
||||||
while (radio.getDTMFTxActive() != 1) {
|
|
||||||
// wait until we're ready for a new code
|
|
||||||
delay(10);
|
|
||||||
}
|
|
||||||
if (i < 32 && out_buf[i] != ';' && out_buf[i] != 0) {
|
|
||||||
code = radio.DTMFchar2code(out_buf[i]);
|
|
||||||
if (code == 255) code = 0xE; // throw a * in there so we don't break things with an invalid code
|
|
||||||
radio.setDTMFCode(code); // set first
|
|
||||||
} else {
|
|
||||||
dtmf_to_tx = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
|
|
||||||
while (radio.getDTMFTxActive() != 0) {
|
|
||||||
// wait until this code is done
|
|
||||||
delay(10);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// done with tone
|
|
||||||
radio.setModeReceive();
|
|
||||||
if (repeater == true) {radio.frequency(freq);}
|
|
||||||
radio.setTxSourceMic();
|
|
||||||
}
|
|
||||||
|
|
||||||
void dtmf_rx() {
|
|
||||||
char m = radio.DTMFRxLoop();
|
|
||||||
if (m != 0) {
|
|
||||||
// Note: not doing buffering of messages,
|
|
||||||
// we just send a single morse character
|
|
||||||
// whenever we get it
|
|
||||||
SerialWrite("R%d;\n", m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: morse config info
|
|
||||||
|
|
||||||
void morse_rx_setup() {
|
|
||||||
// Set the morse code characteristics
|
|
||||||
radio.setMorseFreq(MORSE_FREQ);
|
|
||||||
radio.setMorseDotMillis(MORSE_DOT);
|
|
||||||
|
|
||||||
radio.lookForTone(MORSE_FREQ);
|
|
||||||
|
|
||||||
radio.setupMorseRx();
|
|
||||||
}
|
|
||||||
|
|
||||||
void morse_rx() {
|
|
||||||
char m = radio.morseRxLoop();
|
|
||||||
|
|
||||||
if (m != 0) {
|
|
||||||
// Note: not doing buffering of messages,
|
|
||||||
// we just send a single morse character
|
|
||||||
// whenever we get it
|
|
||||||
SerialWrite("R%c;\n",m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void pl_tone_tx() {
|
|
||||||
memset(pl_tx_buffer,0,32);
|
|
||||||
uint8_t ptr = 0;
|
|
||||||
while(1) {
|
|
||||||
if(Serial.available()) {
|
|
||||||
uint8_t buf = Serial.read();
|
|
||||||
if(buf == 'X') { return; }
|
|
||||||
if(buf == ';') { pl_tx_buffer[ptr] = 0; program_pl_tx(); return; }
|
|
||||||
if(ptr == 31) { return; }
|
|
||||||
pl_tx_buffer[ptr] = buf; ptr++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void program_pl_tx() {
|
|
||||||
float pl_tx = atof(pl_tx_buffer);
|
|
||||||
radio.setCtcss(pl_tx);
|
|
||||||
|
|
||||||
if (pl_tx == 0) {
|
|
||||||
radio.disableCtcssTx();
|
|
||||||
} else {
|
|
||||||
radio.enableCtcssTx();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void pl_tone_rx() {
|
|
||||||
memset(pl_rx_buffer,0,32);
|
|
||||||
uint8_t ptr = 0;
|
|
||||||
while(1) {
|
|
||||||
if(Serial.available()) {
|
|
||||||
uint8_t buf = Serial.read();
|
|
||||||
if(buf == 'X') { return; }
|
|
||||||
if(buf == ';') { pl_rx_buffer[ptr] = 0; program_pl_rx(); return; }
|
|
||||||
if(ptr == 31) { return; }
|
|
||||||
pl_rx_buffer[ptr] = buf; ptr++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void program_pl_rx() {
|
|
||||||
float pl_rx = atof(pl_rx_buffer);
|
|
||||||
radio.setCtcss(pl_rx);
|
|
||||||
if (pl_rx == 0) {
|
|
||||||
rx_ctcss = false;
|
|
||||||
radio.setUnmute();
|
|
||||||
muted = false;
|
|
||||||
radio.disableCtcssRx();
|
|
||||||
} else {
|
|
||||||
rx_ctcss = true;
|
|
||||||
radio.setMute();
|
|
||||||
muted = true;
|
|
||||||
radio.enableCtcssRx();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TEXT_BUF_LEN 64
|
|
||||||
char text_buf[TEXT_BUF_LEN];
|
|
||||||
void SerialWrite(const char *fmt, ...) {
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
int str_len = vsnprintf(text_buf, TEXT_BUF_LEN, fmt, args);
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
bleuart.write(text_buf, str_len);
|
|
||||||
Serial.write(text_buf, str_len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SerialFlush(bool ble_serial) {
|
|
||||||
if (ble_serial) {
|
|
||||||
while (bleuart.available()) { bleuart.read(); }
|
|
||||||
} else {
|
|
||||||
while (Serial.available()) { Serial.read(); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SerialFlushWhitespace(bool ble_serial) {
|
|
||||||
if (!ble_serial && Serial.available()) {
|
|
||||||
char cpeek = Serial.peek();
|
|
||||||
while (cpeek == ' ' || cpeek == '\r' || cpeek == '\n')
|
|
||||||
{
|
|
||||||
Serial.read();
|
|
||||||
cpeek = Serial.peek();
|
|
||||||
}
|
|
||||||
} else if (ble_serial && bleuart.available()) {
|
|
||||||
char cpeek = bleuart.peek();
|
|
||||||
while (cpeek == ' ' || cpeek == '\r' || cpeek == '\n')
|
|
||||||
{
|
|
||||||
bleuart.read();
|
|
||||||
cpeek = bleuart.peek();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -97,7 +97,6 @@ void setup() {
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
// set up the reset control pin
|
// set up the reset control pin
|
||||||
// NOTE: HamShieldMini doesn't have a reset pin, so this has no effect
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
delay(5); // wait for device to come up
|
delay(5); // wait for device to come up
|
||||||
|
|
|
@ -2,10 +2,6 @@
|
||||||
* Example: SpeechTX - This example used the basic JustTransmit example from the above site
|
* Example: SpeechTX - This example used the basic JustTransmit example from the above site
|
||||||
* This example uses the Talkie Arduino speech library. It transmits pre-encoded speech over the air.
|
* This example uses the Talkie Arduino speech library. It transmits pre-encoded speech over the air.
|
||||||
* More info at: https://github.com/going-digital/Talkie
|
* More info at: https://github.com/going-digital/Talkie
|
||||||
*
|
|
||||||
* Make sure you're using an Arduino Uno or equivalent. The Talkie library doesn't work
|
|
||||||
* with hardware that doesn't use the ATMega328 or ATMega168.
|
|
||||||
*
|
|
||||||
* Connect the HamShield to your Arduino. Screw the antenna
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
* into the HamShield RF jack. Connect the Arduino to
|
* into the HamShield RF jack. Connect the Arduino to
|
||||||
* wall power and then to your computer via USB. After
|
* wall power and then to your computer via USB. After
|
||||||
|
@ -241,7 +237,6 @@ void setup() {
|
||||||
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
// set up the reset control pin
|
// set up the reset control pin
|
||||||
// NOTE: HamShieldMini doesn't have a reset pin, so this has no effect
|
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
delay(5); // wait for device to come up
|
delay(5); // wait for device to come up
|
||||||
|
@ -255,15 +250,8 @@ void setup() {
|
||||||
radio.initialize();
|
radio.initialize();
|
||||||
radio.setRfPower(0);
|
radio.setRfPower(0);
|
||||||
radio.frequency(145010);
|
radio.frequency(145010);
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
|
|
||||||
radio.waitForChannel(); // wait for the channel to be empty
|
|
||||||
|
|
||||||
radio.setModeTransmit();
|
radio.setModeTransmit();
|
||||||
delay(100); // wait for PA to come up
|
|
||||||
voice.say(spKILO); // to change these to the words you would like to say, or a ham radio call sign - uncomment above encoded words
|
voice.say(spKILO); // to change these to the words you would like to say, or a ham radio call sign - uncomment above encoded words
|
||||||
voice.say(spSIX); // more word choices can be found at the talkie github site
|
voice.say(spSIX); // more word choices can be found at the talkie github site
|
||||||
voice.say(spALPHA);
|
voice.say(spALPHA);
|
||||||
|
@ -278,7 +266,11 @@ void loop() {
|
||||||
voice.say(spIS);
|
voice.say(spIS);
|
||||||
voice.say(spON);
|
voice.say(spON);
|
||||||
voice.say(spFIRE);
|
voice.say(spFIRE);
|
||||||
|
|
||||||
radio.setModeReceive();
|
}
|
||||||
delay(10000);
|
|
||||||
|
void loop() {
|
||||||
|
radio.frequency(144025);
|
||||||
|
radio.setModeTransmit();
|
||||||
|
for(;;) { }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name=HamShield
|
name=HamShield
|
||||||
version=1.1.4
|
version=1.1.3
|
||||||
author=Morgan Redfield <morgan@enhancedradio.com>, Casey Halverson <casey@enhancedradio.com>
|
author=Morgan Redfield <morgan@enhancedradio.com>, Casey Halverson <casey@enhancedradio.com>
|
||||||
maintainer=Morgan Redfield <morgan@enhancedradio.com>
|
maintainer=Morgan Redfield <morgan@enhancedradio.com>
|
||||||
sentence=A library for use with HamShield by Enhanced Radio Devices.
|
sentence=A library for use with HamShield by Enhanced Radio Devices.
|
||||||
|
|
|
@ -234,8 +234,8 @@ void HamShield::initialize(bool narrowBand) {
|
||||||
setDTMFTxTime(60);
|
setDTMFTxTime(60);
|
||||||
setDTMFDetectTime(24);
|
setDTMFDetectTime(24);
|
||||||
|
|
||||||
HSreadWord(devAddr, A1846S_DTMF_ENABLE_REG, radio_dat_buf);
|
HSreadWord(devAddr, A1846S_DTMF_ENABLE_REG, radio_i2c_buf);
|
||||||
old_dtmf_reg = radio_dat_buf[0];
|
old_dtmf_reg = radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -388,13 +388,13 @@ void HamShield::setupWideBand() {
|
||||||
// end AGC table
|
// end AGC table
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Verify the data connection.
|
/** Verify the I2C connection.
|
||||||
* Make sure the device is connected and responds as expected.
|
* Make sure the device is connected and responds as expected.
|
||||||
* @return True if connection is valid, false otherwise
|
* @return True if connection is valid, false otherwise
|
||||||
*/
|
*/
|
||||||
bool HamShield::testConnection() {
|
bool HamShield::testConnection() {
|
||||||
HSreadWord(devAddr, 0x00, radio_dat_buf);
|
HSreadWord(devAddr, 0x00, radio_i2c_buf);
|
||||||
return radio_dat_buf[0] == 0x1846;
|
return radio_i2c_buf[0] == 0x1846;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -414,8 +414,8 @@ bool HamShield::testConnection() {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint16_t HamShield::readCtlReg() {
|
uint16_t HamShield::readCtlReg() {
|
||||||
HSreadWord(devAddr, A1846S_CTL_REG, radio_dat_buf);
|
HSreadWord(devAddr, A1846S_CTL_REG, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
void HamShield::softReset() {
|
void HamShield::softReset() {
|
||||||
|
@ -503,8 +503,8 @@ void HamShield::setClkMode(bool LFClk){
|
||||||
HSwriteWord(devAddr, A1846S_CLK_MODE_REG, tx_data);
|
HSwriteWord(devAddr, A1846S_CLK_MODE_REG, tx_data);
|
||||||
}
|
}
|
||||||
bool HamShield::getClkMode(){
|
bool HamShield::getClkMode(){
|
||||||
HSreadBitW(devAddr, A1846S_CLK_MODE_REG, A1846S_CLK_MODE_BIT, radio_dat_buf);
|
HSreadBitW(devAddr, A1846S_CLK_MODE_REG, A1846S_CLK_MODE_BIT, radio_i2c_buf);
|
||||||
return (radio_dat_buf[0] != 0);
|
return (radio_i2c_buf[0] != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: create a 25kHz setup option as well as 12.5kHz (as is implemented now)
|
// TODO: create a 25kHz setup option as well as 12.5kHz (as is implemented now)
|
||||||
|
@ -517,8 +517,8 @@ void HamShield::setChanMode(uint16_t mode){
|
||||||
HSwriteBitsW(devAddr, A1846S_CTL_REG, A1846S_CHAN_MODE_BIT, A1846S_CHAN_MODE_LENGTH, mode);
|
HSwriteBitsW(devAddr, A1846S_CTL_REG, A1846S_CHAN_MODE_BIT, A1846S_CHAN_MODE_LENGTH, mode);
|
||||||
}
|
}
|
||||||
uint16_t HamShield::getChanMode(){
|
uint16_t HamShield::getChanMode(){
|
||||||
HSreadBitsW(devAddr, A1846S_CTL_REG, A1846S_CHAN_MODE_BIT, A1846S_CHAN_MODE_LENGTH, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_CTL_REG, A1846S_CHAN_MODE_BIT, A1846S_CHAN_MODE_LENGTH, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -551,8 +551,8 @@ void HamShield::setTX(bool on_noff){
|
||||||
HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_TX_MODE_BIT, on_noff);
|
HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_TX_MODE_BIT, on_noff);
|
||||||
}
|
}
|
||||||
bool HamShield::getTX(){
|
bool HamShield::getTX(){
|
||||||
HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_TX_MODE_BIT, radio_dat_buf);
|
HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_TX_MODE_BIT, radio_i2c_buf);
|
||||||
return (radio_dat_buf[0] != 0);
|
return (radio_i2c_buf[0] != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HamShield::setRX(bool on_noff){
|
void HamShield::setRX(bool on_noff){
|
||||||
|
@ -573,8 +573,8 @@ void HamShield::setRX(bool on_noff){
|
||||||
HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_RX_MODE_BIT, on_noff);
|
HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_RX_MODE_BIT, on_noff);
|
||||||
}
|
}
|
||||||
bool HamShield::getRX(){
|
bool HamShield::getRX(){
|
||||||
HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_RX_MODE_BIT, radio_dat_buf);
|
HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_RX_MODE_BIT, radio_i2c_buf);
|
||||||
return (radio_dat_buf[0] != 0);
|
return (radio_i2c_buf[0] != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HamShield::setModeTransmit(){
|
void HamShield::setModeTransmit(){
|
||||||
|
@ -634,8 +634,8 @@ void HamShield::setTxSourceNone(){
|
||||||
setTxSource(0);
|
setTxSource(0);
|
||||||
}
|
}
|
||||||
uint16_t HamShield::getTxSource(){
|
uint16_t HamShield::getTxSource(){
|
||||||
HSreadBitsW(devAddr, A1846S_TX_VOICE_REG, A1846S_VOICE_SEL_BIT, A1846S_VOICE_SEL_LENGTH, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_TX_VOICE_REG, A1846S_VOICE_SEL_BIT, A1846S_VOICE_SEL_LENGTH, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -652,8 +652,8 @@ void HamShield::setPABiasVoltage(uint16_t voltage){
|
||||||
HSwriteBitsW(devAddr, A1846S_PABIAS_REG, A1846S_PABIAS_BIT, A1846S_PABIAS_LENGTH, voltage);
|
HSwriteBitsW(devAddr, A1846S_PABIAS_REG, A1846S_PABIAS_BIT, A1846S_PABIAS_LENGTH, voltage);
|
||||||
}
|
}
|
||||||
uint16_t HamShield::getPABiasVoltage(){
|
uint16_t HamShield::getPABiasVoltage(){
|
||||||
HSreadBitsW(devAddr, A1846S_PABIAS_REG, A1846S_PABIAS_BIT, A1846S_PABIAS_LENGTH, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_PABIAS_REG, A1846S_PABIAS_BIT, A1846S_PABIAS_LENGTH, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
// Subaudio settings
|
// Subaudio settings
|
||||||
|
@ -672,8 +672,8 @@ void HamShield::setCtcssCdcssMode(uint16_t mode){
|
||||||
HSwriteBitsW(devAddr, A1846S_TX_VOICE_REG, A1846S_CTDCSS_DTEN_BIT, A1846S_CTDCSS_DTEN_LEN, mode);
|
HSwriteBitsW(devAddr, A1846S_TX_VOICE_REG, A1846S_CTDCSS_DTEN_BIT, A1846S_CTDCSS_DTEN_LEN, mode);
|
||||||
}
|
}
|
||||||
uint16_t HamShield::getCtcssCdcssMode(){
|
uint16_t HamShield::getCtcssCdcssMode(){
|
||||||
HSreadBitsW(devAddr, A1846S_TX_VOICE_REG, A1846S_CTDCSS_DTEN_BIT, A1846S_CTDCSS_DTEN_BIT, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_TX_VOICE_REG, A1846S_CTDCSS_DTEN_BIT, A1846S_CTDCSS_DTEN_BIT, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
void HamShield::setDetPhaseShift() {
|
void HamShield::setDetPhaseShift() {
|
||||||
|
@ -711,16 +711,16 @@ void HamShield::setCdcssSel(bool long_nshort){
|
||||||
HSwriteBitW(devAddr, A1846S_CTCSS_MODE_REG, A1846S_CDCSS_SEL_BIT, long_nshort);
|
HSwriteBitW(devAddr, A1846S_CTCSS_MODE_REG, A1846S_CDCSS_SEL_BIT, long_nshort);
|
||||||
}
|
}
|
||||||
bool HamShield::getCdcssSel(){
|
bool HamShield::getCdcssSel(){
|
||||||
HSreadBitW(devAddr, A1846S_CTCSS_MODE_REG, A1846S_CDCSS_SEL_BIT, radio_dat_buf);
|
HSreadBitW(devAddr, A1846S_CTCSS_MODE_REG, A1846S_CDCSS_SEL_BIT, radio_i2c_buf);
|
||||||
return (radio_dat_buf[0] == 1);
|
return (radio_i2c_buf[0] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HamShield::setCdcssInvert(bool invert) {
|
void HamShield::setCdcssInvert(bool invert) {
|
||||||
HSwriteBitW(devAddr, A1846S_CTCSS_MODE_REG, A1846S_CDCSS_INVERT_BIT, invert);
|
HSwriteBitW(devAddr, A1846S_CTCSS_MODE_REG, A1846S_CDCSS_INVERT_BIT, invert);
|
||||||
}
|
}
|
||||||
bool HamShield::getCdcssInvert() {
|
bool HamShield::getCdcssInvert() {
|
||||||
HSreadBitW(devAddr, A1846S_CTCSS_MODE_REG, A1846S_CDCSS_INVERT_BIT, radio_dat_buf);
|
HSreadBitW(devAddr, A1846S_CTCSS_MODE_REG, A1846S_CDCSS_INVERT_BIT, radio_i2c_buf);
|
||||||
return (radio_dat_buf[0] == 1);
|
return (radio_i2c_buf[0] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cdcss neg_det_en
|
// Cdcss neg_det_en
|
||||||
|
@ -763,8 +763,8 @@ float HamShield::getCtcssFreqHz() {
|
||||||
//y = mx + b
|
//y = mx + b
|
||||||
float m = 1.678;
|
float m = 1.678;
|
||||||
float b = -3.3;
|
float b = -3.3;
|
||||||
HSreadWord(devAddr, A1846S_CTCSS_FREQ_REG, radio_dat_buf);
|
HSreadWord(devAddr, A1846S_CTCSS_FREQ_REG, radio_i2c_buf);
|
||||||
float f = (float) radio_dat_buf[0];
|
float f = (float) radio_i2c_buf[0];
|
||||||
return (f/m-b)/100;
|
return (f/m-b)/100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -810,8 +810,8 @@ void HamShield::setCtcssDetThreshIn(uint8_t thresh) {
|
||||||
HSwriteBitsW(devAddr, A1846S_CTCSS_THRESH_REG, 15, 8, thresh);
|
HSwriteBitsW(devAddr, A1846S_CTCSS_THRESH_REG, 15, 8, thresh);
|
||||||
}
|
}
|
||||||
uint8_t HamShield::getCtcssDetThreshIn() {
|
uint8_t HamShield::getCtcssDetThreshIn() {
|
||||||
HSreadBitsW(devAddr, A1846S_CTCSS_THRESH_REG, 15, 8, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_CTCSS_THRESH_REG, 15, 8, radio_i2c_buf);
|
||||||
return (uint8_t) radio_dat_buf[0];
|
return (uint8_t) radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// unmatch threshold
|
// unmatch threshold
|
||||||
|
@ -819,13 +819,13 @@ void HamShield::setCtcssDetThreshOut(uint8_t thresh) {
|
||||||
HSwriteBitsW(devAddr, A1846S_CTCSS_THRESH_REG, 7, 8, thresh);
|
HSwriteBitsW(devAddr, A1846S_CTCSS_THRESH_REG, 7, 8, thresh);
|
||||||
}
|
}
|
||||||
uint8_t HamShield::getCtcssDetThreshOut() {
|
uint8_t HamShield::getCtcssDetThreshOut() {
|
||||||
HSreadBitsW(devAddr, A1846S_CTCSS_THRESH_REG, 7, 8, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_CTCSS_THRESH_REG, 7, 8, radio_i2c_buf);
|
||||||
return (uint8_t) radio_dat_buf[0];
|
return (uint8_t) radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HamShield::getCtcssToneDetected() {
|
bool HamShield::getCtcssToneDetected() {
|
||||||
HSreadBitW(devAddr, A1846S_FLAG_REG, A1846S_CTCSS1_FLAG_BIT, radio_dat_buf);
|
HSreadBitW(devAddr, A1846S_FLAG_REG, A1846S_CTCSS1_FLAG_BIT, radio_i2c_buf);
|
||||||
return (radio_dat_buf[0] != 0);
|
return (radio_i2c_buf[0] != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cdcss codes
|
// cdcss codes
|
||||||
|
@ -856,10 +856,10 @@ void HamShield::setCdcssCode(uint16_t code) {
|
||||||
}
|
}
|
||||||
uint16_t HamShield::getCdcssCode() {
|
uint16_t HamShield::getCdcssCode() {
|
||||||
uint32_t oct_code;
|
uint32_t oct_code;
|
||||||
HSreadWord(devAddr, A1846S_CDCSS_CODE_HI_REG, radio_dat_buf);
|
HSreadWord(devAddr, A1846S_CDCSS_CODE_HI_REG, radio_i2c_buf);
|
||||||
oct_code = ((uint32_t)radio_dat_buf[0] << 16);
|
oct_code = ((uint32_t)radio_i2c_buf[0] << 16);
|
||||||
HSreadWord(devAddr, A1846S_CDCSS_CODE_LO_REG, radio_dat_buf);
|
HSreadWord(devAddr, A1846S_CDCSS_CODE_LO_REG, radio_i2c_buf);
|
||||||
oct_code += radio_dat_buf[0];
|
oct_code += radio_i2c_buf[0];
|
||||||
|
|
||||||
oct_code = oct_code >> 12;
|
oct_code = oct_code >> 12;
|
||||||
uint16_t code = (oct_code & 0x3);
|
uint16_t code = (oct_code & 0x3);
|
||||||
|
@ -879,8 +879,8 @@ void HamShield::setSQOff(){
|
||||||
HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_SQ_ON_BIT, 0);
|
HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_SQ_ON_BIT, 0);
|
||||||
}
|
}
|
||||||
bool HamShield::getSQState(){
|
bool HamShield::getSQState(){
|
||||||
HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_SQ_ON_BIT, radio_dat_buf);
|
HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_SQ_ON_BIT, radio_i2c_buf);
|
||||||
return (radio_dat_buf[0] != 0);
|
return (radio_i2c_buf[0] != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SQ threshold
|
// SQ threshold
|
||||||
|
@ -890,9 +890,9 @@ void HamShield::setSQHiThresh(int16_t sq_hi_threshold){
|
||||||
HSwriteBitsW(devAddr, A1846S_SQ_OPEN_THRESH_REG, A1846S_SQ_OPEN_THRESH_BIT, A1846S_SQ_OPEN_THRESH_LENGTH, sq);
|
HSwriteBitsW(devAddr, A1846S_SQ_OPEN_THRESH_REG, A1846S_SQ_OPEN_THRESH_BIT, A1846S_SQ_OPEN_THRESH_LENGTH, sq);
|
||||||
}
|
}
|
||||||
int16_t HamShield::getSQHiThresh(){
|
int16_t HamShield::getSQHiThresh(){
|
||||||
HSreadBitsW(devAddr, A1846S_SQ_OPEN_THRESH_REG, A1846S_SQ_OPEN_THRESH_BIT, A1846S_SQ_OPEN_THRESH_LENGTH, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_SQ_OPEN_THRESH_REG, A1846S_SQ_OPEN_THRESH_BIT, A1846S_SQ_OPEN_THRESH_LENGTH, radio_i2c_buf);
|
||||||
|
|
||||||
return radio_dat_buf[0] - 137;
|
return radio_i2c_buf[0] - 137;
|
||||||
}
|
}
|
||||||
void HamShield::setSQLoThresh(int16_t sq_lo_threshold){
|
void HamShield::setSQLoThresh(int16_t sq_lo_threshold){
|
||||||
// Sq detect low th, rssi_cmp will be 0 when rssi<th_l_sq && time delay meet, unit 1 dB
|
// Sq detect low th, rssi_cmp will be 0 when rssi<th_l_sq && time delay meet, unit 1 dB
|
||||||
|
@ -900,14 +900,14 @@ void HamShield::setSQLoThresh(int16_t sq_lo_threshold){
|
||||||
HSwriteBitsW(devAddr, A1846S_SQ_SHUT_THRESH_REG, A1846S_SQ_SHUT_THRESH_BIT, A1846S_SQ_SHUT_THRESH_LENGTH, sq);
|
HSwriteBitsW(devAddr, A1846S_SQ_SHUT_THRESH_REG, A1846S_SQ_SHUT_THRESH_BIT, A1846S_SQ_SHUT_THRESH_LENGTH, sq);
|
||||||
}
|
}
|
||||||
int16_t HamShield::getSQLoThresh(){
|
int16_t HamShield::getSQLoThresh(){
|
||||||
HSreadBitsW(devAddr, A1846S_SQ_SHUT_THRESH_REG, A1846S_SQ_SHUT_THRESH_BIT, A1846S_SQ_SHUT_THRESH_LENGTH, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_SQ_SHUT_THRESH_REG, A1846S_SQ_SHUT_THRESH_BIT, A1846S_SQ_SHUT_THRESH_LENGTH, radio_i2c_buf);
|
||||||
|
|
||||||
return radio_dat_buf[0] - 137;
|
return radio_i2c_buf[0] - 137;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HamShield::getSquelching() {
|
bool HamShield::getSquelching() {
|
||||||
HSreadBitW(devAddr, A1846S_FLAG_REG, A1846S_SQ_FLAG_BIT, radio_dat_buf);
|
HSreadBitW(devAddr, A1846S_FLAG_REG, A1846S_SQ_FLAG_BIT, radio_i2c_buf);
|
||||||
return (radio_dat_buf[0] != 0);
|
return (radio_i2c_buf[0] != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -919,8 +919,8 @@ void HamShield::clearSQOutSel(){
|
||||||
HSwriteBitW(devAddr, A1846S_SQ_OUT_SEL_REG, A1846S_SQ_OUT_SEL_BIT, 0);
|
HSwriteBitW(devAddr, A1846S_SQ_OUT_SEL_REG, A1846S_SQ_OUT_SEL_BIT, 0);
|
||||||
}
|
}
|
||||||
bool HamShield::getSQOutSel(){
|
bool HamShield::getSQOutSel(){
|
||||||
HSreadBitW(devAddr, A1846S_SQ_OUT_SEL_REG, A1846S_SQ_OUT_SEL_BIT, radio_dat_buf);
|
HSreadBitW(devAddr, A1846S_SQ_OUT_SEL_REG, A1846S_SQ_OUT_SEL_BIT, radio_i2c_buf);
|
||||||
return (radio_dat_buf[0] != 0);
|
return (radio_i2c_buf[0] != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// VOX
|
// VOX
|
||||||
|
@ -931,8 +931,8 @@ void HamShield::setVoxOff(){
|
||||||
HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_VOX_ON_BIT, 0);
|
HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_VOX_ON_BIT, 0);
|
||||||
}
|
}
|
||||||
bool HamShield::getVoxOn(){
|
bool HamShield::getVoxOn(){
|
||||||
HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_VOX_ON_BIT, radio_dat_buf);
|
HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_VOX_ON_BIT, radio_i2c_buf);
|
||||||
return (radio_dat_buf[0] != 0);
|
return (radio_i2c_buf[0] != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vox Threshold
|
// Vox Threshold
|
||||||
|
@ -942,16 +942,16 @@ void HamShield::setVoxOpenThresh(uint16_t vox_open_thresh){
|
||||||
|
|
||||||
}
|
}
|
||||||
uint16_t HamShield::getVoxOpenThresh(){
|
uint16_t HamShield::getVoxOpenThresh(){
|
||||||
HSreadBitsW(devAddr, A1846S_TH_H_VOX_REG, A1846S_TH_H_VOX_BIT, A1846S_TH_H_VOX_LEN, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_TH_H_VOX_REG, A1846S_TH_H_VOX_BIT, A1846S_TH_H_VOX_LEN, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
void HamShield::setVoxShutThresh(uint16_t vox_shut_thresh){
|
void HamShield::setVoxShutThresh(uint16_t vox_shut_thresh){
|
||||||
// When vssi < th_l_vox && time delay meet, then vox will be 0 (unit mV )
|
// When vssi < th_l_vox && time delay meet, then vox will be 0 (unit mV )
|
||||||
HSwriteBitsW(devAddr, A1846S_TH_L_VOX_REG, A1846S_TH_L_VOX_BIT, A1846S_TH_L_VOX_LEN, vox_shut_thresh);
|
HSwriteBitsW(devAddr, A1846S_TH_L_VOX_REG, A1846S_TH_L_VOX_BIT, A1846S_TH_L_VOX_LEN, vox_shut_thresh);
|
||||||
}
|
}
|
||||||
uint16_t HamShield::getVoxShutThresh(){
|
uint16_t HamShield::getVoxShutThresh(){
|
||||||
HSreadBitsW(devAddr, A1846S_TH_L_VOX_REG, A1846S_TH_L_VOX_BIT, A1846S_TH_L_VOX_LEN, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_TH_L_VOX_REG, A1846S_TH_L_VOX_BIT, A1846S_TH_L_VOX_LEN, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tail Noise
|
// Tail Noise
|
||||||
|
@ -962,8 +962,8 @@ void HamShield::disableTailNoiseElim(){
|
||||||
HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_TAIL_ELIM_EN_BIT, 1);
|
HSwriteBitW(devAddr, A1846S_CTL_REG, A1846S_TAIL_ELIM_EN_BIT, 1);
|
||||||
}
|
}
|
||||||
bool HamShield::getTailNoiseElimEnabled(){
|
bool HamShield::getTailNoiseElimEnabled(){
|
||||||
HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_TAIL_ELIM_EN_BIT, radio_dat_buf);
|
HSreadBitW(devAddr, A1846S_CTL_REG, A1846S_TAIL_ELIM_EN_BIT, radio_i2c_buf);
|
||||||
return (radio_dat_buf[0] != 0);
|
return (radio_i2c_buf[0] != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// tail noise shift select
|
// tail noise shift select
|
||||||
|
@ -976,8 +976,8 @@ void HamShield::setShiftSelect(uint16_t shift_sel){
|
||||||
HSwriteBitsW(devAddr, A1846S_CTCSS_MODE_REG, A1846S_SHIFT_SEL_BIT, A1846S_SHIFT_SEL_LEN, shift_sel);
|
HSwriteBitsW(devAddr, A1846S_CTCSS_MODE_REG, A1846S_SHIFT_SEL_BIT, A1846S_SHIFT_SEL_LEN, shift_sel);
|
||||||
}
|
}
|
||||||
uint16_t HamShield::getShiftSelect(){
|
uint16_t HamShield::getShiftSelect(){
|
||||||
HSreadBitsW(devAddr, A1846S_CTCSS_MODE_REG, A1846S_SHIFT_SEL_BIT, A1846S_SHIFT_SEL_LEN, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_CTCSS_MODE_REG, A1846S_SHIFT_SEL_BIT, A1846S_SHIFT_SEL_LEN, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// DTMF
|
// DTMF
|
||||||
|
@ -1006,8 +1006,8 @@ void HamShield::setDTMFDetectTime(uint16_t detect_time) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t HamShield::getDTMFDetectTime() {
|
uint16_t HamShield::getDTMFDetectTime() {
|
||||||
HSreadBitsW(devAddr, A1846S_DTMF_ENABLE_REG, A18462_DTMF_DET_TIME_BIT, A18462_DTMF_DET_TIME_LEN, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_DTMF_ENABLE_REG, A18462_DTMF_DET_TIME_BIT, A18462_DTMF_DET_TIME_LEN, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
void HamShield::setDTMFIdleTime(uint16_t idle_time) {
|
void HamShield::setDTMFIdleTime(uint16_t idle_time) {
|
||||||
|
@ -1017,8 +1017,8 @@ void HamShield::setDTMFIdleTime(uint16_t idle_time) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t HamShield::getDTMFIdleTime() {
|
uint16_t HamShield::getDTMFIdleTime() {
|
||||||
HSreadBitsW(devAddr, A1846S_DTMF_TIME_REG, A1846S_DTMF_IDLE_TIME_BIT, A1846S_DTMF_IDLE_TIME_LEN, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_DTMF_TIME_REG, A1846S_DTMF_IDLE_TIME_BIT, A1846S_DTMF_IDLE_TIME_LEN, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
char HamShield::DTMFRxLoop() {
|
char HamShield::DTMFRxLoop() {
|
||||||
|
@ -1089,8 +1089,8 @@ void HamShield::setDTMFTxTime(uint16_t tx_time) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t HamShield::getDTMFTxTime() {
|
uint16_t HamShield::getDTMFTxTime() {
|
||||||
HSreadBitsW(devAddr, A1846S_DTMF_TIME_REG, A1846S_DUALTONE_TX_TIME_BIT, A1846S_DUALTONE_TX_TIME_LEN, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_DTMF_TIME_REG, A1846S_DUALTONE_TX_TIME_BIT, A1846S_DUALTONE_TX_TIME_LEN, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t HamShield::disableDTMF(){
|
uint16_t HamShield::disableDTMF(){
|
||||||
|
@ -1098,18 +1098,18 @@ uint16_t HamShield::disableDTMF(){
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t HamShield::getDTMFSample(){
|
uint16_t HamShield::getDTMFSample(){
|
||||||
HSreadBitsW(devAddr, A1846S_DTMF_CODE_REG, A1846S_DTMF_SAMPLE_BIT, 1, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_DTMF_CODE_REG, A1846S_DTMF_SAMPLE_BIT, 1, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t HamShield::getDTMFTxActive(){
|
uint16_t HamShield::getDTMFTxActive(){
|
||||||
HSreadBitsW(devAddr, A1846S_DTMF_CODE_REG, A1846S_DTMF_TX_IDLE_BIT, 1, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_DTMF_CODE_REG, A1846S_DTMF_TX_IDLE_BIT, 1, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t HamShield::getDTMFCode(){
|
uint16_t HamShield::getDTMFCode(){
|
||||||
HSreadBitsW(devAddr, A1846S_DTMF_CODE_REG, A1846S_DTMF_CODE_BIT, A1846S_DTMF_CODE_LEN, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_DTMF_CODE_REG, A1846S_DTMF_CODE_BIT, A1846S_DTMF_CODE_LEN, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
void HamShield::setDTMFCode(uint16_t code){
|
void HamShield::setDTMFCode(uint16_t code){
|
||||||
|
@ -1155,8 +1155,8 @@ void HamShield::setDTMFCode(uint16_t code){
|
||||||
|
|
||||||
void HamShield::HStone(uint8_t pin, unsigned int frequency) {
|
void HamShield::HStone(uint8_t pin, unsigned int frequency) {
|
||||||
// store old dtmf reg for noTone
|
// store old dtmf reg for noTone
|
||||||
// HSreadWord(devAddr, A1846S_DTMF_ENABLE_REG, radio_dat_buf);
|
// HSreadWord(devAddr, A1846S_DTMF_ENABLE_REG, radio_i2c_buf);
|
||||||
// old_dtmf_reg = radio_dat_buf[0];
|
// old_dtmf_reg = radio_i2c_buf[0];
|
||||||
|
|
||||||
// set frequency
|
// set frequency
|
||||||
HSwriteWord(devAddr, A1846S_TONE1_FREQ, frequency*10);
|
HSwriteWord(devAddr, A1846S_TONE1_FREQ, frequency*10);
|
||||||
|
@ -1209,12 +1209,12 @@ void HamShield::lookForTone(uint16_t t_hz) {
|
||||||
bool redetect = false;
|
bool redetect = false;
|
||||||
uint8_t last_tone_detected = 0;
|
uint8_t last_tone_detected = 0;
|
||||||
uint8_t HamShield::toneDetected() {
|
uint8_t HamShield::toneDetected() {
|
||||||
HSreadBitsW(devAddr, A1846S_DTMF_CODE_REG, A1846S_DTMF_SAMPLE_BIT, 1, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_DTMF_CODE_REG, A1846S_DTMF_SAMPLE_BIT, 1, radio_i2c_buf);
|
||||||
if (radio_dat_buf[0] != 0) {
|
if (radio_i2c_buf[0] != 0) {
|
||||||
if (!redetect) {
|
if (!redetect) {
|
||||||
redetect = true;
|
redetect = true;
|
||||||
HSreadBitsW(devAddr, A1846S_DTMF_CODE_REG, A1846S_DTMF_CODE_BIT, A1846S_DTMF_CODE_LEN, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_DTMF_CODE_REG, A1846S_DTMF_CODE_BIT, A1846S_DTMF_CODE_LEN, radio_i2c_buf);
|
||||||
last_tone_detected = radio_dat_buf[0];
|
last_tone_detected = radio_i2c_buf[0];
|
||||||
//Serial.print("t: ");
|
//Serial.print("t: ");
|
||||||
//Serial.println(last_tone_detected);
|
//Serial.println(last_tone_detected);
|
||||||
}
|
}
|
||||||
|
@ -1235,15 +1235,15 @@ void HamShield::setFMVoiceCssDeviation(uint16_t deviation){
|
||||||
HSwriteBitsW(devAddr, A1846S_FM_DEV_REG, A1846S_FM_DEV_VOICE_BIT, A1846S_FM_DEV_VOICE_LENGTH, deviation);
|
HSwriteBitsW(devAddr, A1846S_FM_DEV_REG, A1846S_FM_DEV_VOICE_BIT, A1846S_FM_DEV_VOICE_LENGTH, deviation);
|
||||||
}
|
}
|
||||||
uint16_t HamShield::getFMVoiceCssDeviation(){
|
uint16_t HamShield::getFMVoiceCssDeviation(){
|
||||||
HSreadBitsW(devAddr, A1846S_FM_DEV_REG, A1846S_FM_DEV_VOICE_BIT, A1846S_FM_DEV_VOICE_LENGTH, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_FM_DEV_REG, A1846S_FM_DEV_VOICE_BIT, A1846S_FM_DEV_VOICE_LENGTH, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
void HamShield::setFMCssDeviation(uint16_t deviation){
|
void HamShield::setFMCssDeviation(uint16_t deviation){
|
||||||
HSwriteBitsW(devAddr, A1846S_FM_DEV_REG, A1846S_FM_DEV_CSS_BIT, A1846S_FM_DEV_CSS_LENGTH, deviation);
|
HSwriteBitsW(devAddr, A1846S_FM_DEV_REG, A1846S_FM_DEV_CSS_BIT, A1846S_FM_DEV_CSS_LENGTH, deviation);
|
||||||
}
|
}
|
||||||
uint16_t HamShield::getFMCssDeviation(){
|
uint16_t HamShield::getFMCssDeviation(){
|
||||||
HSreadBitsW(devAddr, A1846S_FM_DEV_REG, A1846S_FM_DEV_CSS_BIT, A1846S_FM_DEV_CSS_LENGTH, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_FM_DEV_REG, A1846S_FM_DEV_CSS_BIT, A1846S_FM_DEV_CSS_LENGTH, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// RX voice range
|
// RX voice range
|
||||||
|
@ -1258,15 +1258,15 @@ void HamShield::setVolume1(uint16_t volume){
|
||||||
HSwriteBitsW(devAddr, A1846S_RX_VOLUME_REG, A1846S_RX_VOL_1_BIT, A1846S_RX_VOL_1_LENGTH, volume);
|
HSwriteBitsW(devAddr, A1846S_RX_VOLUME_REG, A1846S_RX_VOL_1_BIT, A1846S_RX_VOL_1_LENGTH, volume);
|
||||||
}
|
}
|
||||||
uint16_t HamShield::getVolume1(){
|
uint16_t HamShield::getVolume1(){
|
||||||
HSreadBitsW(devAddr, A1846S_RX_VOLUME_REG, A1846S_RX_VOL_1_BIT, A1846S_RX_VOL_1_LENGTH, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_RX_VOLUME_REG, A1846S_RX_VOL_1_BIT, A1846S_RX_VOL_1_LENGTH, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
void HamShield::setVolume2(uint16_t volume){
|
void HamShield::setVolume2(uint16_t volume){
|
||||||
HSwriteBitsW(devAddr, A1846S_RX_VOLUME_REG, A1846S_RX_VOL_2_BIT, A1846S_RX_VOL_2_LENGTH, volume);
|
HSwriteBitsW(devAddr, A1846S_RX_VOLUME_REG, A1846S_RX_VOL_2_BIT, A1846S_RX_VOL_2_LENGTH, volume);
|
||||||
}
|
}
|
||||||
uint16_t HamShield::getVolume2(){
|
uint16_t HamShield::getVolume2(){
|
||||||
HSreadBitsW(devAddr, A1846S_RX_VOLUME_REG, A1846S_RX_VOL_2_BIT, A1846S_RX_VOL_2_LENGTH, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_RX_VOLUME_REG, A1846S_RX_VOL_2_BIT, A1846S_RX_VOL_2_LENGTH, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// GPIO
|
// GPIO
|
||||||
|
@ -1292,8 +1292,8 @@ uint16_t HamShield::getGpioMode(uint16_t gpio){
|
||||||
uint16_t mode_len = 2;
|
uint16_t mode_len = 2;
|
||||||
uint16_t bit = gpio*2 + 1;
|
uint16_t bit = gpio*2 + 1;
|
||||||
|
|
||||||
HSreadBitsW(devAddr, A1846S_GPIO_MODE_REG, bit, mode_len, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_GPIO_MODE_REG, bit, mode_len, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
void HamShield::setGpios(uint16_t mode){
|
void HamShield::setGpios(uint16_t mode){
|
||||||
|
@ -1301,8 +1301,8 @@ void HamShield::setGpios(uint16_t mode){
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t HamShield::getGpios(){
|
uint16_t HamShield::getGpios(){
|
||||||
HSreadWord(devAddr, A1846S_GPIO_MODE_REG, radio_dat_buf);
|
HSreadWord(devAddr, A1846S_GPIO_MODE_REG, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Int
|
// Int
|
||||||
|
@ -1313,8 +1313,8 @@ void HamShield::disableInterrupt(uint16_t interrupt){
|
||||||
HSwriteBitW(devAddr, A1846S_INT_MODE_REG, interrupt, 0);
|
HSwriteBitW(devAddr, A1846S_INT_MODE_REG, interrupt, 0);
|
||||||
}
|
}
|
||||||
bool HamShield::getInterruptEnabled(uint16_t interrupt){
|
bool HamShield::getInterruptEnabled(uint16_t interrupt){
|
||||||
HSreadBitW(devAddr, A1846S_INT_MODE_REG, interrupt, radio_dat_buf);
|
HSreadBitW(devAddr, A1846S_INT_MODE_REG, interrupt, radio_i2c_buf);
|
||||||
return (radio_dat_buf[0] != 0);
|
return (radio_i2c_buf[0] != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ST mode
|
// ST mode
|
||||||
|
@ -1322,8 +1322,8 @@ void HamShield::setStMode(uint16_t mode){
|
||||||
HSwriteBitsW(devAddr, A1846S_CTL_REG, A1846S_ST_MODE_BIT, A1846S_ST_MODE_LENGTH, mode);
|
HSwriteBitsW(devAddr, A1846S_CTL_REG, A1846S_ST_MODE_BIT, A1846S_ST_MODE_LENGTH, mode);
|
||||||
}
|
}
|
||||||
uint16_t HamShield::getStMode(){
|
uint16_t HamShield::getStMode(){
|
||||||
HSreadBitsW(devAddr, A1846S_CTL_REG, A1846S_ST_MODE_BIT, A1846S_ST_MODE_LENGTH, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_CTL_REG, A1846S_ST_MODE_BIT, A1846S_ST_MODE_LENGTH, radio_i2c_buf);
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
void HamShield::setStFullAuto(){
|
void HamShield::setStFullAuto(){
|
||||||
setStMode(2);
|
setStMode(2);
|
||||||
|
@ -1343,8 +1343,8 @@ void HamShield::usePreDeEmph(){
|
||||||
HSwriteBitW(devAddr, A1846S_FILTER_REG, A1846S_EMPH_FILTER_EN, 0);
|
HSwriteBitW(devAddr, A1846S_FILTER_REG, A1846S_EMPH_FILTER_EN, 0);
|
||||||
}
|
}
|
||||||
bool HamShield::getPreDeEmphEnabled(){
|
bool HamShield::getPreDeEmphEnabled(){
|
||||||
HSreadBitW(devAddr, A1846S_FILTER_REG, A1846S_EMPH_FILTER_EN, radio_dat_buf);
|
HSreadBitW(devAddr, A1846S_FILTER_REG, A1846S_EMPH_FILTER_EN, radio_i2c_buf);
|
||||||
return (radio_dat_buf[0] == 0);
|
return (radio_i2c_buf[0] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Voice Filters
|
// Voice Filters
|
||||||
|
@ -1355,8 +1355,8 @@ void HamShield::useVoiceHpf(){
|
||||||
HSwriteBitW(devAddr, A1846S_FILTER_REG, A1846S_VHPF_FILTER_EN, 0);
|
HSwriteBitW(devAddr, A1846S_FILTER_REG, A1846S_VHPF_FILTER_EN, 0);
|
||||||
}
|
}
|
||||||
bool HamShield::getVoiceHpfEnabled(){
|
bool HamShield::getVoiceHpfEnabled(){
|
||||||
HSreadBitW(devAddr, A1846S_FILTER_REG, A1846S_VHPF_FILTER_EN, radio_dat_buf);
|
HSreadBitW(devAddr, A1846S_FILTER_REG, A1846S_VHPF_FILTER_EN, radio_i2c_buf);
|
||||||
return (radio_dat_buf[0] == 0);
|
return (radio_i2c_buf[0] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HamShield::bypassVoiceLpf(){
|
void HamShield::bypassVoiceLpf(){
|
||||||
|
@ -1366,8 +1366,8 @@ void HamShield::useVoiceLpf(){
|
||||||
HSwriteBitW(devAddr, A1846S_FILTER_REG, A1846S_VLPF_FILTER_EN, 0);
|
HSwriteBitW(devAddr, A1846S_FILTER_REG, A1846S_VLPF_FILTER_EN, 0);
|
||||||
}
|
}
|
||||||
bool HamShield::getVoiceLpfEnabled(){
|
bool HamShield::getVoiceLpfEnabled(){
|
||||||
HSreadBitW(devAddr, A1846S_FILTER_REG, A1846S_VLPF_FILTER_EN, radio_dat_buf);
|
HSreadBitW(devAddr, A1846S_FILTER_REG, A1846S_VLPF_FILTER_EN, radio_i2c_buf);
|
||||||
return (radio_dat_buf[0] == 0);
|
return (radio_i2c_buf[0] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vox filters
|
// Vox filters
|
||||||
|
@ -1379,8 +1379,8 @@ void HamShield::useVoxHpf(){
|
||||||
HSwriteBitW(devAddr, A1846S_FILTER_REG, A1846S_VXHPF_FILTER_EN, 0);
|
HSwriteBitW(devAddr, A1846S_FILTER_REG, A1846S_VXHPF_FILTER_EN, 0);
|
||||||
}
|
}
|
||||||
bool HamShield::getVoxHpfEnabled(){
|
bool HamShield::getVoxHpfEnabled(){
|
||||||
HSreadBitW(devAddr, A1846S_FILTER_REG, A1846S_VXHPF_FILTER_EN, radio_dat_buf);
|
HSreadBitW(devAddr, A1846S_FILTER_REG, A1846S_VXHPF_FILTER_EN, radio_i2c_buf);
|
||||||
return (radio_dat_buf[0] == 0);
|
return (radio_i2c_buf[0] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HamShield::bypassVoxLpf(){
|
void HamShield::bypassVoxLpf(){
|
||||||
|
@ -1390,28 +1390,28 @@ void HamShield::useVoxLpf(){
|
||||||
HSwriteBitW(devAddr, A1846S_FILTER_REG, A1846S_VXLPF_FILTER_EN, 0);
|
HSwriteBitW(devAddr, A1846S_FILTER_REG, A1846S_VXLPF_FILTER_EN, 0);
|
||||||
}
|
}
|
||||||
bool HamShield::getVoxLpfEnabled(){
|
bool HamShield::getVoxLpfEnabled(){
|
||||||
HSreadBitW(devAddr, A1846S_FILTER_REG, A1846S_VXLPF_FILTER_EN, radio_dat_buf);
|
HSreadBitW(devAddr, A1846S_FILTER_REG, A1846S_VXLPF_FILTER_EN, radio_i2c_buf);
|
||||||
return (radio_dat_buf[0] == 0);
|
return (radio_i2c_buf[0] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Read Only Status Registers
|
// Read Only Status Registers
|
||||||
int16_t HamShield::readRSSI(){
|
int16_t HamShield::readRSSI(){
|
||||||
HSreadBitsW(devAddr, A1846S_RSSI_REG, A1846S_RSSI_BIT, A1846S_RSSI_LENGTH, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_RSSI_REG, A1846S_RSSI_BIT, A1846S_RSSI_LENGTH, radio_i2c_buf);
|
||||||
|
|
||||||
int16_t rssi = (radio_dat_buf[0] & 0xFF) - 137;
|
int16_t rssi = (radio_i2c_buf[0] & 0xFF) - 137;
|
||||||
return rssi;
|
return rssi;
|
||||||
}
|
}
|
||||||
uint16_t HamShield::readVSSI(){
|
uint16_t HamShield::readVSSI(){
|
||||||
HSreadBitsW(devAddr, A1846S_VSSI_REG, A1846S_VSSI_BIT, A1846S_VSSI_LENGTH, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_VSSI_REG, A1846S_VSSI_BIT, A1846S_VSSI_LENGTH, radio_i2c_buf);
|
||||||
|
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
uint16_t HamShield::readMSSI(){
|
uint16_t HamShield::readMSSI(){
|
||||||
HSreadBitsW(devAddr, A1846S_VSSI_REG, A1846S_MSSI_BIT, A1846S_MSSI_LENGTH, radio_dat_buf);
|
HSreadBitsW(devAddr, A1846S_VSSI_REG, A1846S_MSSI_BIT, A1846S_MSSI_LENGTH, radio_i2c_buf);
|
||||||
|
|
||||||
return radio_dat_buf[0];
|
return radio_i2c_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1682,7 +1682,7 @@ Does not take in account the millis() overflow
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool HamShield::waitForChannel(long timeout, long breakwindow, int setRSSI) {
|
bool HamShield::waitForChannel(long timeout = 0, long breakwindow = 0, int setRSSI = HAMSHIELD_EMPTY_CHANNEL_RSSI) {
|
||||||
int16_t rssi = 0; // Set RSSI to max received signal
|
int16_t rssi = 0; // Set RSSI to max received signal
|
||||||
for(int x = 0; x < 20; x++) { rssi = readRSSI(); } // "warm up" to get past RSSI hysteresis
|
for(int x = 0; x < 20; x++) { rssi = readRSSI(); } // "warm up" to get past RSSI hysteresis
|
||||||
long timer = HSmillis() + timeout; // Setup the timeout value
|
long timer = HSmillis() + timeout; // Setup the timeout value
|
||||||
|
|
|
@ -515,7 +515,7 @@ class HamShield {
|
||||||
char parseMorse(uint8_t rx_morse_char, uint8_t rx_morse_bit);
|
char parseMorse(uint8_t rx_morse_char, uint8_t rx_morse_bit);
|
||||||
uint8_t morseLookup(char letter);
|
uint8_t morseLookup(char letter);
|
||||||
uint8_t morseReverseLookup(uint8_t itu);
|
uint8_t morseReverseLookup(uint8_t itu);
|
||||||
bool waitForChannel(long timeout = 0, long breakwindow = 0, int setRSSI = HAMSHIELD_EMPTY_CHANNEL_RSSI);
|
bool waitForChannel(long timeout, long breakwindow, int setRSSI);
|
||||||
void SSTVVISCode(int code);
|
void SSTVVISCode(int code);
|
||||||
void SSTVTestPattern(int code);
|
void SSTVTestPattern(int code);
|
||||||
void toneWait(uint16_t freq, long timer);
|
void toneWait(uint16_t freq, long timer);
|
||||||
|
@ -527,7 +527,7 @@ class HamShield {
|
||||||
private:
|
private:
|
||||||
uint8_t devAddr;
|
uint8_t devAddr;
|
||||||
uint8_t hs_mic_pin;
|
uint8_t hs_mic_pin;
|
||||||
uint16_t radio_dat_buf[4];
|
uint16_t radio_i2c_buf[4];
|
||||||
bool tx_active;
|
bool tx_active;
|
||||||
bool rx_active;
|
bool rx_active;
|
||||||
float radio_frequency;
|
float radio_frequency;
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Based loosely on I2Cdev by Jeff Rowberg, except for all kludgy bit-banging
|
* Based loosely on I2Cdev by Jeff Rowberg, except for all kludgy bit-banging
|
||||||
*
|
|
||||||
* Note that while the Radio IC (AU1846) does have an I2C interface, we've found
|
|
||||||
* it to be a bit buggy. Instead, we are using a secondary interface to communicate
|
|
||||||
* with it. The secondary interface is a bit of a hybrid between I2C and SPI.
|
|
||||||
* uses a Chip-Select pin like SPI, but has bi-directional data like I2C. In order
|
|
||||||
* to deal with this, we bit-bang the interface.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "HamShield_comms.h"
|
#include "HamShield_comms.h"
|
||||||
|
@ -69,20 +63,16 @@ int8_t HSreadWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data)
|
||||||
temp = ((regAddr & (0x80 >> i)) != 0);
|
temp = ((regAddr & (0x80 >> i)) != 0);
|
||||||
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
|
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
|
||||||
digitalWrite(dat_pin, temp);
|
digitalWrite(dat_pin, temp);
|
||||||
HSdelayMicroseconds(1);
|
|
||||||
digitalWrite(clk_pin, 1); //PORTC |= (1<<5); //
|
digitalWrite(clk_pin, 1); //PORTC |= (1<<5); //
|
||||||
HSdelayMicroseconds(1);
|
|
||||||
}
|
}
|
||||||
// change direction of dat_pin
|
// change direction of dat_pin
|
||||||
pinMode(dat_pin, INPUT); // DDRC &= ~(1<<4); //
|
pinMode(dat_pin, INPUT); // DDRC &= ~(1<<4); //
|
||||||
for (int i = 15; i >= 0; i--) {
|
for (int i = 15; i >= 0; i--) {
|
||||||
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
|
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
|
||||||
HSdelayMicroseconds(1);
|
|
||||||
digitalWrite(clk_pin, 1); //PORTC |= (1<<5); //
|
digitalWrite(clk_pin, 1); //PORTC |= (1<<5); //
|
||||||
temp_dat = digitalRead(dat_pin); //((PINC & (1<<4)) != 0);
|
temp_dat = digitalRead(dat_pin); //((PINC & (1<<4)) != 0);
|
||||||
temp_dat = temp_dat << i;
|
temp_dat = temp_dat << i;
|
||||||
*data |= temp_dat;
|
*data |= temp_dat;
|
||||||
HSdelayMicroseconds(1);
|
|
||||||
}
|
}
|
||||||
digitalWrite(devAddr, 1); //PORTC |= (1<<1);// CS
|
digitalWrite(devAddr, 1); //PORTC |= (1<<1);// CS
|
||||||
|
|
||||||
|
@ -131,17 +121,13 @@ bool HSwriteWord(uint8_t devAddr, uint8_t regAddr, uint16_t data)
|
||||||
temp_reg = ((regAddr & (0x80 >> i)) != 0);
|
temp_reg = ((regAddr & (0x80 >> i)) != 0);
|
||||||
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
|
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
|
||||||
digitalWrite(dat_pin, regAddr & (0x80 >> i));
|
digitalWrite(dat_pin, regAddr & (0x80 >> i));
|
||||||
HSdelayMicroseconds(1);
|
|
||||||
digitalWrite(clk_pin, 1); // PORTC |= (1<<5); //
|
digitalWrite(clk_pin, 1); // PORTC |= (1<<5); //
|
||||||
HSdelayMicroseconds(1);
|
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
temp_dat = ((data & (0x8000 >> i)) != 0);
|
temp_dat = ((data & (0x8000 >> i)) != 0);
|
||||||
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
|
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
|
||||||
digitalWrite(dat_pin, temp_dat);
|
digitalWrite(dat_pin, temp_dat);
|
||||||
HSdelayMicroseconds(1);
|
|
||||||
digitalWrite(clk_pin, 1); // PORTC |= (1<<5); //
|
digitalWrite(clk_pin, 1); // PORTC |= (1<<5); //
|
||||||
HSdelayMicroseconds(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
digitalWrite(devAddr, 1); //PORTC |= (1<<1); //CS
|
digitalWrite(devAddr, 1); //PORTC |= (1<<1); //CS
|
||||||
|
|
Loading…
Reference in New Issue