diff --git a/ubitx_20/cw_autokey.ino b/ubitx_20/cw_autokey.ino index 7f20461..01c2564 100644 --- a/ubitx_20/cw_autokey.ino +++ b/ubitx_20/cw_autokey.ino @@ -1,5 +1,5 @@ /************************************************************************* - KD8CEC'S Memory Keyer for HAM + KD8CEC's Memory Keyer for HAM This source code is written for All amateur radio operator, I have not had amateur radio communication for a long time. CW has been diff --git a/ubitx_20/ubitx_20.ino b/ubitx_20/ubitx_20.ino index f5d986e..fc791a4 100644 --- a/ubitx_20/ubitx_20.ino +++ b/ubitx_20/ubitx_20.ino @@ -158,7 +158,17 @@ int count = 0; //to generally count ticks, loops, etc #define TX_TUNE_TYPE 261 // #define HAM_BAND_RANGE 262 //FROM (2BYTE) TO (2BYTE) * 10 = 40byte #define HAM_BAND_FREQS 302 //40, 1 BAND = 4Byte most bit is mode -#define TUNING_STEP 342 //TUNING STEP * 6 (index 1 + STEPS 5) +#define TUNING_STEP 342 //TUNING STEP * 6 (index 1 + STEPS 5) + +//for reduce cw key error, eeprom address +#define CW_ADC_ST_FROM 348 //CW ADC Range STRAIGHT KEY from +#define CW_ADC_ST_TO 349 //CW ADC Range STRAIGHT KEY to +#define CW_ADC_DOT_FROM 350 //CW ADC Range DOT from +#define CW_ADC_DOT_TO 351 //CW ADC Range DOT to +#define CW_ADC_DASH_FROM 352 //CW ADC Range DASH from +#define CW_ADC_DASH_TO 353 //CW ADC Range DASH to +#define CW_ADC_BOTH_FROM 354 //CW ADC Range BOTH from +#define CW_ADC_BOTH_TO 355 //CW ADC Range BOTH to //Check Firmware type and version #define FIRMWAR_ID_ADDR 776 //776 : 0x59, 777 :0x58, 778 : 0x68 : Id Number, if not found id, erase eeprom(32~1023) for prevent system error. @@ -245,6 +255,16 @@ byte isTxType = 0; //000000[0 - isSplit] [0 - isTXStop] byte arTuneStep[5]; byte tuneStepIndex; //default Value 0, start Offset is 0 because of check new user +//CW ADC Range +byte cwAdcSTFrom = 0; +byte cwAdcSTTo = 0; +byte cwAdcDotFrom = 0; +byte cwAdcDotTo = 0; +byte cwAdcDashtFrom = 0; +byte cwAdcDashTo = 0; +byte cwAdcBothFrom = 0; +byte cwAdcBothTo = 0; + //Variables for auto cw mode byte isCWAutoMode = 0; //0 : none, 1 : CW_AutoMode_Menu_Selection, 2 : CW_AutoMode Sending byte cwAutoTextCount = 0; //cwAutoText Count @@ -686,7 +706,10 @@ void initSettings(){ EEPROM.get(VFO_B, vfoB); EEPROM.get(CW_SIDETONE, sideTone); EEPROM.get(CW_SPEED, cwSpeed); - + //End of original code + + //---------------------------------------------------------------- + //Add Lines by KD8CEC //for custom source Section ============================= //ID & Version Check from EEProm //if found different firmware, erase eeprom (32 @@ -787,6 +810,44 @@ void initSettings(){ if (tuneStepIndex == 0) //New User tuneStepIndex = 3; + + //CW Key ADC Range ======= adjust set value for reduce cw keying error + //by KD8CEC + EEPROM.get(CW_ADC_ST_FROM, cwAdcSTFrom); + EEPROM.get(CW_ADC_ST_TO, cwAdcSTTo); + + EEPROM.get(CW_ADC_DOT_FROM, cwAdcDotFrom); + EEPROM.get(CW_ADC_DOT_TO, cwAdcDotTo); + + EEPROM.get(CW_ADC_DASH_FROM, cwAdcDashtFrom); + EEPROM.get(CW_ADC_DASH_TO, cwAdcDashTo); + + EEPROM.get(CW_ADC_BOTH_FROM, cwAdcBothFrom); + EEPROM.get(CW_ADC_BOTH_TO, cwAdcBothTo); + + //default Value (for original hardware) + if (cwAdcSTFrom >= cwAdcSTTo) + { + cwAdcSTFrom = 0; + cwAdcSTTo = 50; + } + + if (cwAdcBothFrom >= cwAdcBothTo) + { + cwAdcBothFrom = 51; + cwAdcBothTo = 300; + } + + if (cwAdcDotFrom >= cwAdcDotTo) + { + cwAdcDotFrom = 301; + cwAdcDotTo = 600; + } + if (cwAdcDashtFrom >= cwAdcDashTo) + { + cwAdcDashtFrom = 601; + cwAdcDashTo = 800; + } if (cwDelayTime < 1 || cwDelayTime > 250) @@ -798,6 +859,7 @@ void initSettings(){ if (vfoB_mode < 2) vfoB_mode = 3; + //original code with modified by kd8cec if (usbCarrier > 12010000l || usbCarrier < 11990000l) usbCarrier = 11995000l; @@ -810,8 +872,9 @@ void initSettings(){ vfoB = 14150000l; vfoB_mode = 3; } + //end of original code section - //for protect eeprom life + //for protect eeprom life by KD8CEC vfoA_eeprom = vfoA; vfoB_eeprom = vfoB; vfoA_mode_eeprom = vfoA_mode; diff --git a/ubitx_20/ubitx_keyer.ino b/ubitx_20/ubitx_keyer.ino index bae1396..0611f58 100644 --- a/ubitx_20/ubitx_keyer.ino +++ b/ubitx_20/ubitx_keyer.ino @@ -83,41 +83,45 @@ void cwKeyUp(){ cwTimeout = millis() + cwDelayTime * 10; } -/***************************************************************************** -// New logic, by RON -// modified by KD8CEC -******************************************************************************/ +//Variables for Ron's new logic #define DIT_L 0x01 // DIT latch #define DAH_L 0x02 // DAH latch #define DIT_PROC 0x04 // DIT is being processed #define PDLSWAP 0x08 // 0 for normal, 1 for swap #define IAMBICB 0x10 // 0 for Iambic A, 1 for Iambic B enum KSTYPE {IDLE, CHK_DIT, CHK_DAH, KEYED_PREP, KEYED, INTER_ELEMENT }; - static long ktimer; - bool Iambic_Key = true; unsigned char keyerControl = IAMBICB; unsigned char keyerState = IDLE; -//Below is a test to reduce the keying error. -/* +//Below is a test to reduce the keying error. do not delete lines +//create by KD8CEC for compatible with new CW Logic char update_PaddleLatch(byte isUpdateKeyState) { int paddle = analogRead(ANALOG_KEYER); unsigned char tmpKeyerControl; - if (paddle > 800) // above 4v is up - tmpKeyerControl = 0; + //if (paddle > 800) // above 4v is up + // tmpKeyerControl = 0; //else if (paddle > 600) // 4-3v is DASH - else if (paddle > 693 && paddle < 700) // 4-3v is DASH + if (paddle > cwAdcDashtFrom && cwAdcDashTo < 700) // 4-3v is DASH tmpKeyerControl |= DAH_L; //else if (paddle > 300) //1-2v is DOT - else if (paddle > 323 && paddle < 328) //1-2v is DOT + else if (paddle > cwAdcDotFrom && paddle < cwAdcDotTo) //1-2v is DOT tmpKeyerControl |= DIT_L; //else if (paddle > 50) - else if (paddle > 280 && paddle < 290) + else if (paddle > cwAdcBothFrom && paddle < cwAdcBothTo) tmpKeyerControl |= (DAH_L | DIT_L) ; //both are between 1 and 2v - else + else + { + if (Iambic_Key) + tmpKeyerControl = 0 ; + else if (paddle > cwAdcSTFrom && paddle < cwAdcSTTo) + tmpKeyerControl = DIT_L ; + else + tmpKeyerControl = 0 ; + } + tmpKeyerControl = 0 ; //STRAIGHT KEY in original code //keyerControl |= (DAH_L | DIT_L) ; //STRAIGHT KEY in original code @@ -135,8 +139,8 @@ char update_PaddleLatch(byte isUpdateKeyState) { //if (analogRead(ANALOG_DOT) < 600 ) keyerControl |= DIT_L; //if (analogRead(ANALOG_DASH) < 600 ) keyerControl |= DAH_L; } -*/ +/* //create by KD8CEC for compatible with new CW Logic char update_PaddleLatch(byte isUpdateKeyState) { int paddle = analogRead(ANALOG_KEYER); @@ -163,8 +167,12 @@ char update_PaddleLatch(byte isUpdateKeyState) { return tmpKeyerControl; } +*/ -//This function is Ron's Logic. +/***************************************************************************** +// New logic, by RON +// modified by KD8CEC +******************************************************************************/ void cwKeyer(void){ byte paddle; lastPaddle = 0; diff --git a/ubitx_20/ubitx_menu.ino b/ubitx_20/ubitx_menu.ino index 117dca7..ffd2394 100644 --- a/ubitx_20/ubitx_menu.ino +++ b/ubitx_20/ubitx_menu.ino @@ -13,6 +13,7 @@ #define printLineF1(x) (printLineF(1, x)) #define printLineF2(x) (printLineF(0, x)) +//Ham band move by KD8CEC void menuBand(int btn){ int knob = 0; int stepChangeCount = 0; @@ -117,6 +118,7 @@ void menuBand(int btn){ menuOn = 0; } +//Convert Mode, Number by KD8CEC //0: default, 1:not use, 2:LSB, 3:USB, 4:CW, 5:AM, 6:FM byte modeToByte(){ if (isUSB) @@ -125,12 +127,15 @@ byte modeToByte(){ return 2; } +//Convert Number to Mode by KD8CEC void byteToMode(byte modeValue){ if (modeValue == 3) isUSB = 1; else isUSB = 0; } + +//Convert Number to Mode by KD8CEC void byteWithFreqToMode(byte modeValue){ if (modeValue == 3) isUSB = 1; @@ -140,6 +145,7 @@ void byteWithFreqToMode(byte modeValue){ isUSB = 0; } +//VFO Toggle and save VFO Information, modified by KD8CEC void menuVfoToggle(int btn, char isUseDelayTime) { if (!btn){ @@ -229,6 +235,7 @@ void menuSidebandToggle(int btn){ } } +//Select CW Key Type by KD8CEC void menuSetupKeyType(int btn){ if (!btn && digitalRead(PTT) == HIGH){ if (Iambic_Key) @@ -263,7 +270,88 @@ void menuSetupKeyType(int btn){ } } +//Analog pin monitoring with CW Key and function keys connected. +//by KD8CEC +void menuADCMonitor(int btn){ + int adcPinA0 = 0; //A0(BLACK, EncoderA) + int adcPinA1 = 0; //A1(BROWN, EncoderB) + int adcPinA2 = 0; //A2(RED, Function Key) + int adcPinA3 = 0; //A3(ORANGE, CW Key) + int adcPinA6 = 0; //A6(BLUE, Ptt) + int adcPinA7 = 0; //A7(VIOLET, Spare) + unsigned long pressKeyTime = 0; + + if (!btn){ + printLineF2(F("ADC Line Monitor")); + return; + } + + printLineF2(F("Exit:Long PTT")); + delay_background(2000, 0); + printLineF1(F("A0 A1 A2")); + printLineF2(F("A3 A6 A7")); + delay_background(3000, 0); + + while (true) { + adcPinA0 = analogRead(A0); //A0(BLACK, EncoderA) + adcPinA1 = analogRead(A1); //A1(BROWN, EncoderB) + adcPinA2 = analogRead(A2); //A2(RED, Function Key) + adcPinA3 = analogRead(A3); //A3(ORANGE, CW Key) + adcPinA6 = analogRead(A6); //A6(BLUE, Ptt) + adcPinA7 = analogRead(A7); //A7(VIOLET, Spare) +/* + sprintf(c, "%4d %4d %4d", adcPinA0, adcPinA1, adcPinA2); + printLine1(c); + sprintf(c, "%4d %4d %4d", adcPinA3, adcPinA6, adcPinA7); + printLine2(c); +*/ + + if (adcPinA6 < 10) { + if (pressKeyTime == 0) + pressKeyTime = millis(); + else if (pressKeyTime < (millis() - 3000)) + break; + } + else + pressKeyTime = 0; + + ltoa(adcPinA0, c, 10); + //strcat(b, c); + strcpy(b, c); + strcat(b, ", "); + + ltoa(adcPinA1, c, 10); + strcat(b, c); + strcat(b, ", "); + + ltoa(adcPinA2, c, 10); + strcat(b, c); + + printLine1(b); + + //strcpy(b, " "); + ltoa(adcPinA3, c, 10); + strcpy(b, c); + strcat(b, ", "); + + ltoa(adcPinA6, c, 10); + strcat(b, c); + strcat(b, ", "); + + ltoa(adcPinA7, c, 10); + strcat(b, c); + printLine2(b); + + delay_background(200, 0); + } //end of while + + printLine2ClearAndUpdate(); + menuOn = 0; +} + +//Function to disbled transmission +//by KD8CEC void menuTxOnOff(int btn, byte optionType){ if (!btn){ if ((isTxType & optionType) == 0) @@ -377,6 +465,7 @@ void menuCWSpeed(int btn){ menuOn = 0; } +//Builtin CW Keyer Logic by KD8CEC void menuCWAutoKey(int btn){ if (!btn){ printLineF2(F("CW AutoKey Mode?")); @@ -400,6 +489,7 @@ void menuCWAutoKey(int btn){ menuOn = 0; } +//Modified by KD8CEC void menuSetupCwDelay(int btn){ int knob = 0; int tmpCWDelay = cwDelayTime * 10; @@ -448,6 +538,7 @@ void menuSetupCwDelay(int btn){ menuOn = 0; } +//CW Time delay by KD8CEC void menuSetupTXCWInterval(int btn){ int knob = 0; int tmpTXCWInterval = delayBeforeCWStartTime * 2; @@ -659,6 +750,7 @@ void printCarrierFreq(unsigned long freq){ printLine2(c); } +//modified by KD8CEC (just 1 line remarked //usbCarrier = ... void menuSetupCarrier(int btn){ int knob = 0; unsigned long prevCarrier; @@ -712,6 +804,7 @@ void menuSetupCarrier(int btn){ menuOn = 0; } +//Modified by KD8CEC void menuSetupCwTone(int btn){ int knob = 0; int prev_sideTone; @@ -760,6 +853,7 @@ void menuSetupCwTone(int btn){ menuOn = 0; } +//Lock Dial move by KD8CEC void setDialLock(byte tmpLock, byte fromMode) { if (tmpLock == 1) isDialLock |= (vfoActive == VFO_A ? 0x01 : 0x02); @@ -782,6 +876,7 @@ unsigned int btnDownTimeCount; #define PRESS_ADJUST_TUNE 1000 #define PRESS_LOCK_CONTROL 2000 +//Modified by KD8CEC void doMenu(){ int select=0, i,btnState; char isNeedDisplay = 0; @@ -865,7 +960,7 @@ void doMenu(){ btnState = btnDown(); if (i > 0){ - if (modeCalibrate && select + i < 160) + if (modeCalibrate && select + i < 170) select += i; if (!modeCalibrate && select + i < 80) select += i; @@ -905,8 +1000,10 @@ void doMenu(){ else if (select < 140 && modeCalibrate) menuSetupKeyType(btnState); else if (select < 150 && modeCalibrate) - menuTxOnOff(btnState, 0x01); //TX OFF / ON + menuADCMonitor(btnState); else if (select < 160 && modeCalibrate) + menuTxOnOff(btnState, 0x01); //TX OFF / ON + else if (select < 170 && modeCalibrate) menuExit(btnState); Check_Cat(0); //To prevent disconnections