update ctcss getfreq and example

This commit is contained in:
Morgan Redfield 2018-08-15 19:30:20 -07:00
parent 96d02c3bd9
commit afbecf6e5e
3 changed files with 17 additions and 14 deletions

View File

@ -95,12 +95,13 @@ void setup() {
radio.setRfPower(0); radio.setRfPower(0);
// CTCSS Setup code // CTCSS Setup code
ctcss_tone = 103.5; ctcss_tone = 134.4;
radio.setCtcss(ctcss_tone); radio.setCtcss(ctcss_tone);
radio.enableCtcss(); radio.enableCtcss();
Serial.print("ctcss tone: ");
Serial.println(radio.getCtcssFreqHz());
// mute audio until we get a CTCSS tone // mute audio until we get a CTCSS tone
radio.setMute(); // radio.setMute();
muted = true; muted = true;
// configure Arduino LED for // configure Arduino LED for
@ -116,13 +117,13 @@ void loop() {
if (radio.getCtcssToneDetected()) { if (radio.getCtcssToneDetected()) {
if (muted) { if (muted) {
muted = false; muted = false;
radio.setUnmute(); // radio.setUnmute();
Serial.println("tone"); Serial.println("tone");
} }
} else { } else {
if (!muted) { if (!muted) {
muted = true; muted = true;
radio.setMute(); // radio.setMute();
Serial.println("no tone"); Serial.println("no tone");
} }
} }
@ -171,4 +172,4 @@ void loop() {
Serial.println(radio.readRSSI()); Serial.println(radio.readRSSI());
rssi_timeout = millis(); rssi_timeout = millis();
} }
} }

View File

@ -1,7 +1,7 @@
/* Hamshield /* Hamshield
* Example: Morse Code Transceiver * Example: Morse Code Transceiver
* *
* Serail to Morse transceiver. Sends characters from the Serial * Serial to Morse transceiver. Sends characters from the Serial
* port over the air, and vice versa. * port over the air, and vice versa.
* 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 wall * into the HamShield RF jack. Connect the Arduino to wall

View File

@ -770,23 +770,25 @@ void HamShield::setCtcss(float freq_Hz) {
} }
void HamShield::setCtcssFreq(uint16_t freq_milliHz){ void HamShield::setCtcssFreq(uint16_t freq_milliHz){
HSwriteWord(devAddr, A1846S_CTCSS_FREQ_REG, freq_milliHz);
// set RX Ctcss match thresholds (based on frequency) // set RX Ctcss match thresholds (based on frequency)
// calculate thresh based on freq // calculate thresh based on freq
float f = ((float) freq_milliHz)/100; float f = ((float) freq_milliHz)/100;
uint8_t thresh = (uint8_t)(-0.1*f + 25); uint8_t thresh = (uint8_t)(-0.1*f + 25);
setCtcssDetThreshIn(thresh); setCtcssDetThreshIn(thresh);
setCtcssDetThreshOut(thresh); setCtcssDetThreshOut(thresh);
HSwriteWord(devAddr, A1846S_CTCSS_FREQ_REG, freq_milliHz);
} }
uint16_t HamShield::getCtcssFreqMilliHz(){ uint16_t HamShield::getCtcssFreqMilliHz(){
HSreadWord(devAddr, A1846S_CTCSS_FREQ_REG, radio_i2c_buf); return getCtcssFreqHz()*100;
return radio_i2c_buf[0];
} }
float HamShield::getCtcssFreqHz() { float HamShield::getCtcssFreqHz() {
return ((float)(getCtcssFreqMilliHz()))/100; //y = mx + b
float m = 1.678;
float b = -3.3;
HSreadWord(devAddr, A1846S_CTCSS_FREQ_REG, radio_i2c_buf);
float f = (float) radio_i2c_buf[0];
return (f/m-b)/100;
} }
void HamShield::setCtcssFreqToStandard(){ void HamShield::setCtcssFreqToStandard(){