diff --git a/src/HamShield.cpp b/src/HamShield.cpp index 4dff007..dcc80d9 100644 --- a/src/HamShield.cpp +++ b/src/HamShield.cpp @@ -985,6 +985,20 @@ void HamShield::enableDTMFReceive(){ HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, 7, 8, 0x18); HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, A1846S_DTMF_ENABLE_BIT, 1, 1); + + HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, A18462_DTMF_DET_TIME_BIT, A18462_DTMF_DET_TIME_LEN, 24); + + // idle time + HSwriteBitsW(devAddr, A1846S_DTMF_TIME_REG, A1846S_DTMF_IDLE_TIME_BIT, A1846S_DTMF_IDLE_TIME_LEN, 50); + + HSreadWord(devAddr, 0x6F, radio_i2c_buf); + Serial.println(radio_i2c_buf[0]); + + // tx time + HSwriteBitsW(devAddr, A1846S_DTMF_TIME_REG, A1846S_DUALTONE_TX_TIME_BIT, A1846S_DUALTONE_TX_TIME_LEN, 50); + + HSwriteBitsW(devAddr, 0x57, 0, 1, 1); // send dtmf to speaker out + } uint16_t HamShield::disableDTMF(){ @@ -996,11 +1010,53 @@ uint16_t HamShield::getDTMFSample(){ return radio_i2c_buf[0]; } +uint16_t HamShield::getDTMFTxActive(){ + HSreadBitsW(devAddr, A1846S_DTMF_CODE_REG, A1846S_DTMF_TX_IDLE_BIT, 1, radio_i2c_buf); + return radio_i2c_buf[0]; +} + uint16_t HamShield::getDTMFCode(){ HSreadBitsW(devAddr, A1846S_DTMF_CODE_REG, A1846S_DTMF_CODE_BIT, A1846S_DTMF_CODE_LEN, radio_i2c_buf); return radio_i2c_buf[0]; } +void HamShield::setDTMFCode(uint16_t code){ + uint16_t tone1, tone2; + + /* + * F4 F5 F6 F7 + * F0 1 2 3 A + * F1 4 5 6 B + * F2 7 8 9 C + * F3 E(*) 0 F(#) D + */ + + // determine tone 1 + if ((code >= 1 && code <= 3) || code == 0xA) { + tone1 = 697*10; + } else if ((code >= 4 && code <= 6) || code == 0xB) { + tone1 = 770*10; + } else if ((code >= 7 && code <= 9) || code == 0xC) { + tone1 = 852*10; + } else if (code >= 0xD) { + tone1 = 941*10; + } + + // determine tone 2 + if (code == 1 || code == 4 || code == 7 || code == 0xE) { + tone2 = 1209*10; + } else if (code == 2 || code == 5 || code == 8 || code == 0) { + tone2 = 1336*10; + } else if (code == 3 || code == 6 || code == 9 || code == 0xF) { + tone2 = 1477*10; + } else if (code >= 0xA && code <= 0xD) { + tone2 = 1633*10; + } + + HSwriteWord(devAddr, A1846S_TONE1_FREQ, tone1); + HSwriteWord(devAddr, A1846S_TONE2_FREQ, tone2); + +} // TX FM deviation void HamShield::setFMVoiceCssDeviation(uint16_t deviation){ diff --git a/src/HamShield.h b/src/HamShield.h index 4113220..9993be9 100644 --- a/src/HamShield.h +++ b/src/HamShield.h @@ -56,7 +56,9 @@ #define A1846S_DTMF_ENABLE_REG 0x7A // holds dtmf_enable #define A1846S_DTMF_CODE_REG 0x7E // holds dtmf_sample and dtmf_code - +#define A1846S_TONE1_FREQ 0x35 // holds frequency of tone 1 (in 0.1Hz increments) +#define A1846S_TONE2_FREQ 0x36 // holds frequency of tone 2 (in 0.1Hz increments) +#define A1846S_DTMF_TIME_REG 0x7B // holds time intervals for DTMF // Device Bit Fields @@ -181,12 +183,20 @@ // Bitfields for A1846S_DTMF_ENABLE_REG #define A1846S_DTMF_ENABLE_BIT 15 +#define A18462_DTMF_DET_TIME_BIT 7 +#define A18462_DTMF_DET_TIME_LEN 8 // Bitfields for A1846S_DTMF_SAMPLE_REG #define A1846S_DTMF_SAMPLE_BIT 4 #define A1846S_DTMF_CODE_BIT 3 #define A1846S_DTMF_CODE_LEN 4 +#define A1846S_DTMF_TX_IDLE_BIT 5 +// Bitfields for A1846S_DTMF_TIME_REG +#define A1846S_DUALTONE_TX_TIME_BIT 5 // duration of dual tone TX (via DTMF) in 2.5ms increments +#define A1846S_DUALTONE_TX_TIME_LEN 6 +#define A1846S_DTMF_IDLE_TIME_BIT 11 +#define A1846S_DTMF_IDLE_TIME_LEN 6 // SSTV VIS Codes @@ -379,10 +389,15 @@ class HamShield { // uint16_t code = getDTMFCode(); // while (getDTMFSample() == 1) { delay(10); } // disableDTMF(); + // Writing a single DTMF code: + // setDTMFCode(code); // code is a uint16_t from 0x0 to 0xF void enableDTMFReceive(); uint16_t disableDTMF(); uint16_t getDTMFSample(); uint16_t getDTMFCode(); + uint16_t getDTMFTxActive(); + void setDTMFCode(uint16_t code); + // TX FM deviation void setFMVoiceCssDeviation(uint16_t deviation); @@ -460,15 +475,6 @@ class HamShield { - //TODO: split AFSK out so it can be left out - // AFSK routines - //bool AFSKStart(); - //bool AFSKEnabled() { return afsk.enabled(); } - //bool AFSKStop(); - //bool AFSKOut(const char *); - - //class AFSK afsk; - private: uint8_t devAddr; uint16_t radio_i2c_buf[4];