From 12fd074aed7553dcdde08444fdeb8ae001d4f3c3 Mon Sep 17 00:00:00 2001 From: Morgan Redfield Date: Sun, 28 Apr 2019 11:41:29 -0700 Subject: [PATCH] let HSTone be generated by HamShield itself --- .../AFSK_SerialMessenger.ino | 2 +- src/HamShield.cpp | 18 +++++++++++++++++ src/HamShield.h | 2 ++ src/HamShield_comms.cpp | 20 ------------------- src/HamShield_comms.h | 3 --- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/examples/AFSK_SerialMessenger/AFSK_SerialMessenger.ino b/examples/AFSK_SerialMessenger/AFSK_SerialMessenger.ino index f349d11..2a8015d 100644 --- a/examples/AFSK_SerialMessenger/AFSK_SerialMessenger.ino +++ b/examples/AFSK_SerialMessenger/AFSK_SerialMessenger.ino @@ -74,6 +74,7 @@ void loop() { //Serial.println(messagebuff); prepMessage(); msgptr = 0; + messagebuff = ""; Serial.print("!!"); } else { @@ -140,7 +141,6 @@ void prepMessage() { } Serial.println("Done sending"); radio.setModeReceive(); - messagebuff = ""; } diff --git a/src/HamShield.cpp b/src/HamShield.cpp index 2078b60..246fa5f 100644 --- a/src/HamShield.cpp +++ b/src/HamShield.cpp @@ -1062,6 +1062,24 @@ void HamShield::setDTMFCode(uint16_t code){ } +// Tone Transmission + + +void HamShield::HStone(uint8_t pin, unsigned int frequency) { + HSwriteBitsW(devAddr, 0x79, 15, 2, 0x3); // transmit single tone (not dtmf) + HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, 15, 2, 0x1); // transmit single tone (not dtmf) + + // bypass pre/de-emphasis + HSwriteBitsW(devAddr, A1846S_FILTER_REG, A1846S_EMPH_FILTER_EN, 1, 1); + + HSwriteWord(devAddr, A1846S_TONE1_FREQ, frequency*10); + setTxSourceTone1(); +} +void HamShield::HSnoTone(uint8_t pin) { + HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, 15, 2, 0x0); // disable tone and dtmf + setTxSourceMic(); +} + // Tone detection void HamShield::lookForTone(uint16_t t_hz) { float tone_hz = (float) t_hz; diff --git a/src/HamShield.h b/src/HamShield.h index b520e04..e089bbe 100644 --- a/src/HamShield.h +++ b/src/HamShield.h @@ -398,6 +398,8 @@ class HamShield { void setDTMFCode(uint16_t code); // Tone + void HStone(uint8_t pin, unsigned int frequency); + void HSnoTone(uint8_t pin); void lookForTone(uint16_t tone_hz); uint8_t toneDetected(); diff --git a/src/HamShield_comms.cpp b/src/HamShield_comms.cpp index 0c66803..3924f6d 100644 --- a/src/HamShield_comms.cpp +++ b/src/HamShield_comms.cpp @@ -145,23 +145,3 @@ void HSdelay(unsigned long ms) { void HSdelayMicroseconds(unsigned int us) { delayMicroseconds(us); } - -void HStone(uint8_t pin, unsigned int frequency) { -#if defined(ARDUINO_ARCH_NRF52) -//TODO -#elif defined(ARDUINO) - tone(pin, frequency); -#else - softToneCreate(pin); - softToneWrite(pin, frequency); -#endif -} -void HSnoTone(uint8_t pin) { -#if defined(ARDUINO_ARCH_NRF52) -//TODO -#elif defined(ARDUINO) - noTone(pin); -#else - softToneWrite(pin, 0); -#endif -} \ No newline at end of file diff --git a/src/HamShield_comms.h b/src/HamShield_comms.h index f4dc017..017df9d 100644 --- a/src/HamShield_comms.h +++ b/src/HamShield_comms.h @@ -41,8 +41,5 @@ unsigned long HSmillis(); void HSdelay(unsigned long ms); void HSdelayMicroseconds(unsigned int us); -void HStone(uint8_t pin, unsigned int frequency); -void HSnoTone(uint8_t pin); - #endif /* _HAMSHIELD_COMMS_H_ */