diff --git a/Messenger/DTMF_Shield/DTMF_Shield.pde b/Messenger/DTMF_Shield/DTMF_Shield.pde new file mode 100644 index 0000000..a45a784 --- /dev/null +++ b/Messenger/DTMF_Shield/DTMF_Shield.pde @@ -0,0 +1,312 @@ + #include + + Messenger message = Messenger(); + + const int CLK_PIN = 10; + const int DATA_PIN = 9; + const int ENABLE_PIN = 13; + // + const int UP_PIN = 2; + const int DOWN_PIN = 3; + const int PF_PIN = 4; + const int MR_PIN = 5; + const int CALL_PIN = 6; + const int VFO_PIN = 7; + + const byte DTMF_ZERO = 0x0A; + const byte DTMF_ONE = 0x01; + const byte DTMF_TWO = 0x02; + const byte DTMF_THREE = 0x03; + const byte DTMF_FOUR = 0x04; + const byte DTMF_FIVE = 0x05; + const byte DTMF_SIX = 0x06; + const byte DTMF_SEVEN = 0x07; + const byte DTMF_EIGHT = 0x08; + const byte DTMF_NINE = 0x09; + const byte DTMF_STAR = 0x0B; + const byte DTMF_POUND = 0x0C; + const byte DTMF_A = 0x0D; + const byte DTMF_B = 0x0E; + const byte DTMF_C = 0x0F; + const byte DTMF_D = 0x00; + const byte DTMF_OFF = 0x1F; + const byte DTMF_697 = 0x10; + const byte DTMF_770 = 0x11; + const byte DTMF_852 = 0x12; + const byte DTMF_941 = 0x13; + const byte DTMF_1209 = 0x14; + const byte DTMF_1336 = 0x15; + const byte DTMF_1477 = 0x16; + const byte DTMF_1633 = 0x17; + + + int TONE_DELAY = 75; //length of time in ms to leave tone on + int BUTTON_DELAY = 75; //length of time in ms to leave button on + const int ENABLE_DELAY = 1; //length of time in ms to apply enable before clocking in data + bool getToneTime = false; + bool getButtonTime = false; + +void setup() { + Serial.begin(9600); + + pinMode(CLK_PIN, OUTPUT); + pinMode(DATA_PIN, OUTPUT); + pinMode(ENABLE_PIN, OUTPUT); + // + digitalWrite(CLK_PIN, LOW); + digitalWrite(DATA_PIN, LOW); + digitalWrite(ENABLE_PIN, HIGH); + + pinMode(UP_PIN, INPUT); + pinMode(DOWN_PIN, INPUT); + pinMode(PF_PIN, INPUT); + pinMode(MR_PIN, INPUT); + pinMode(CALL_PIN, INPUT); + pinMode(VFO_PIN, INPUT); + // + digitalWrite(UP_PIN, LOW); + digitalWrite(DOWN_PIN, LOW); + digitalWrite(PF_PIN, LOW); + digitalWrite(MR_PIN, LOW); + digitalWrite(CALL_PIN, LOW); + digitalWrite(VFO_PIN, LOW); + + message.attach(messageCompleted); +} + +void setEnableOn() +{ + digitalWrite(ENABLE_PIN, LOW); + delay(ENABLE_DELAY); +} + +void setEnableOff() +{ + digitalWrite(ENABLE_PIN, HIGH); +} + +void myShiftOut (byte dataOut) +{ + digitalWrite(CLK_PIN, HIGH); + digitalWrite(DATA_PIN, LOW); + setEnableOn(); + for (int x=0; x<10; x++) + { + if (x % 2 == 0) + { + digitalWrite(CLK_PIN, HIGH); + digitalWrite(DATA_PIN, bitRead(dataOut, 0)); + dataOut >>= 1; + } + else + { + digitalWrite(CLK_PIN, LOW); + } + } + + digitalWrite(CLK_PIN, HIGH); + delay(TONE_DELAY); + + dataOut = DTMF_OFF; + for (int x=0; x<10; x++) + { + if (x % 2 == 0) + { + digitalWrite(CLK_PIN, HIGH); + digitalWrite(DATA_PIN, bitRead(dataOut, 0)); + dataOut >>= 1; + } + else + { + digitalWrite(CLK_PIN, LOW); + } + } + + delay(TONE_DELAY); + setEnableOff(); + digitalWrite(CLK_PIN, HIGH); + digitalWrite(DATA_PIN, LOW); +} + +void pressButton(const int pin) + { + pinMode(pin, OUTPUT); + delay(BUTTON_DELAY); + pinMode(pin, INPUT); + } + +void loop() { + + while ( Serial.available( ) ) message.process(Serial.read( ) ); +} + +void messageCompleted() +{ + do + { + if (getToneTime == true) + { + getToneTime = false; + TONE_DELAY = message.readInt(); + //Serial.println(TONE_DELAY); + break; + } + + if (getButtonTime == true) + { + getButtonTime = false; + BUTTON_DELAY = message.readInt(); + //Serial.println(BUTTON_DELAY); + break; + } + + if (message.checkString("SET_TONE_TIME:")) + { + getToneTime = true; + break; + } + + if (message.checkString("SET_BUTTON_TIME:")) + { + getButtonTime = true; + break; + } + + if (message.checkString("PAUSE: ")) + { + delay(TONE_DELAY); + break; + } + + if (message.checkString("0")) + { + myShiftOut(DTMF_ZERO); + break; + } + + if (message.checkString("1")) + { + myShiftOut(DTMF_ONE); + break; + } + + if (message.checkString("2")) + { + myShiftOut(DTMF_TWO); + break; + } + + if (message.checkString("3")) + { + myShiftOut(DTMF_THREE); + break; + } + + if (message.checkString("4")) + { + myShiftOut(DTMF_FOUR); + break; + } + + if (message.checkString("0")) + { + myShiftOut(DTMF_ZERO); + break; + } + + if (message.checkString("5")) + { + myShiftOut(DTMF_FIVE); + break; + } + + if (message.checkString("6")) + { + myShiftOut(DTMF_SIX); + break; + } + + if (message.checkString("7")) + { + myShiftOut(DTMF_SEVEN); + break; + } + + if (message.checkString("8")) + { + myShiftOut(DTMF_EIGHT); + break; + } + + if (message.checkString("9")) + { + myShiftOut(DTMF_NINE); + break; + } + + if (message.checkString("A")) + { + myShiftOut(DTMF_A); + break; + } + + if (message.checkString("B")) + { + myShiftOut(DTMF_B); + break; + } + + if (message.checkString("C")) + { + myShiftOut(DTMF_C); + break; + } + + if (message.checkString("D")) + { + myShiftOut(DTMF_D); + break; + } + + if (message.checkString("UP")) + { + pressButton(UP_PIN); + break; + } + + if (message.checkString("DOWN")) + { + pressButton(DOWN_PIN); + break; + } + + if (message.checkString("MR")) + { + pressButton(MR_PIN); + break; + } + + if (message.checkString("VFO")) + { + pressButton(VFO_PIN); + break; + } + + if (message.checkString("CALL")) + { + pressButton(CALL_PIN); + break; + } + + //if we get to here, just clear out buffer + char trash[30]; + message.copyString(trash, 30); + + } while(false); + + Serial.print("READY"); + Serial.println(); +} + + + diff --git a/Messenger/Messenger.cpp b/Messenger/Messenger.cpp new file mode 100644 index 0000000..18ed644 --- /dev/null +++ b/Messenger/Messenger.cpp @@ -0,0 +1,163 @@ + + +//ADDED FOR COMPATIBILITY WITH WIRING +extern "C" { + #include +} + +#include "Arduino.h" +#include "Messenger.h" + + + + +Messenger::Messenger() +{ + init(' '); +} + +Messenger::Messenger(char separator) +{ + if (separator == 10 || separator == 13 || separator == 0) separator = 32; + init(separator); +} + +void Messenger::init(char separator) +{ + callback = NULL; + token[0] = separator; + token[1] = 0; + bufferLength = MESSENGERBUFFERSIZE; + bufferLastIndex = MESSENGERBUFFERSIZE -1; + reset(); +} + +void Messenger::attach(messengerCallbackFunction newFunction) { + callback = newFunction; +} + +void Messenger::reset() { + bufferIndex = 0; + messageState = 0; + current = NULL; + last = NULL; + dumped = 1; +} + +int Messenger::readInt() { + + if (next()) { + dumped = 1; + return atoi(current); + } + return 0; + +} + +// Added based on a suggestion by G. Paolo Sanino +long Messenger::readLong() { + + if (next()) { + dumped = 1; + return atol(current); // atol for long instead of atoi for int variables + } + return 0; + +} + +char Messenger::readChar() { + + if (next()) { + dumped = 1; + return current[0]; + } + return 0; + +} + +double Messenger::readDouble() { + if(next()) { + dumped = 1; + return atof(current); + } + return 0; +} + +void Messenger::copyString(char *string, uint8_t size) { + + if (next()) { + dumped = 1; + strlcpy(string,current,size); + } else { + if ( size ) string[0] = '\0'; + } +} + +uint8_t Messenger::checkString(char *string) { + + if (next()) { + if ( strcmp(string,current) == 0 ) { + dumped = 1; + return 1; + } else { + return 0; + } + } +} + + + +uint8_t Messenger::next() { + + char * temppointer= NULL; + switch (messageState) { + case 0: + return 0; + case 1: + temppointer = buffer; + messageState = 2; + default: + if (dumped) current = strtok_r(temppointer,token,&last); + if (current != NULL) { + dumped = 0; + return 1; + } + } + + return 0; +} + +uint8_t Messenger::available() { + + return next(); + +} + + +uint8_t Messenger::process(int serialByte) { + messageState = 0; + if (serialByte > 0) { + + switch (serialByte) { + case 0: + break; + case 10: // LF + break; + case 13: // CR + buffer[bufferIndex]=0; + reset(); + messageState = 1; + current = buffer; + break; + default: + buffer[bufferIndex]=serialByte; + bufferIndex++; + if (bufferIndex >= bufferLastIndex) reset(); + } + } + if ( messageState == 1 && callback != NULL) (*callback)(); + return messageState; + } + + + diff --git a/Messenger/Messenger.h b/Messenger/Messenger.h new file mode 100644 index 0000000..7ede2c1 --- /dev/null +++ b/Messenger/Messenger.h @@ -0,0 +1,52 @@ + +#ifndef Messenger_h +#define Messenger_h +#define MESSENGERBUFFERSIZE 64 + +#include + +extern "C" { +// callback function + typedef void (*messengerCallbackFunction)(void); +} + + +class Messenger +{ + +public: + Messenger(); + Messenger(char separator); + int readInt(); + long readLong(); // Added based on a suggestion by G. Paolo Sani + char readChar(); + double readDouble(); // Added based on a suggestion by Lorenzo C. + void copyString(char *string, uint8_t size); + uint8_t checkString(char *string); + uint8_t process(int serialByte); + uint8_t available(); + void attach(messengerCallbackFunction newFunction); + +private: + void init(char separator); + uint8_t next(); + void reset(); + + uint8_t messageState; + + messengerCallbackFunction callback; + + char* current; // Pointer to current data + char* last; + + char token[2]; + uint8_t dumped; + + uint8_t bufferIndex; // Index where to write the data + char buffer[MESSENGERBUFFERSIZE]; // Buffer that holds the data + uint8_t bufferLength; // The length of the buffer (defaults to 64) + uint8_t bufferLastIndex; // The last index of the buffer +}; + +#endif + diff --git a/Messenger/keywords.txt b/Messenger/keywords.txt new file mode 100644 index 0000000..079ab65 --- /dev/null +++ b/Messenger/keywords.txt @@ -0,0 +1,29 @@ +####################################### +# Syntax Coloring Map For Messenger +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +Messenger KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +process KEYWORD2 +readInt KEYWORD2 +readLong KEYWORD2 +readChar KEYWORD2 +copyString KEYWORD2 +checkString KEYWORD2 + +####################################### +# Instances (KEYWORD2) +####################################### + +####################################### +# Constants (LITERAL1) +####################################### + diff --git a/TM742 Programmer - Rev 1 candidate Jul1 1, 2014.zip b/TM742 Programmer - Rev 1 candidate Jul1 1, 2014.zip new file mode 100644 index 0000000..6f375db Binary files /dev/null and b/TM742 Programmer - Rev 1 candidate Jul1 1, 2014.zip differ diff --git a/TM742ApplicationSln.zip b/TM742ApplicationSln.zip new file mode 100644 index 0000000..3605e4c Binary files /dev/null and b/TM742ApplicationSln.zip differ