1st Test new CW Keyer and add cat message processing

This commit is contained in:
phdlee 2018-01-27 18:05:08 +09:00
parent cc7dd752e6
commit 8d4c788e11
2 changed files with 121 additions and 106 deletions

View File

@ -597,8 +597,13 @@ applied Threshold for reduct errors, dial Lock, dynamic Step
byte threshold = 2; //noe action for count byte threshold = 2; //noe action for count
unsigned long lastEncInputtime = 0; unsigned long lastEncInputtime = 0;
int encodedSumValue = 0; int encodedSumValue = 0;
unsigned long lastTunetime = 0; //if continous moving, skip threshold processing
byte lastMovedirection = 0; //0 : stop, 1 : cw, 2 : ccw
#define skipThresholdTime 100
#define encodeTimeOut 1000 #define encodeTimeOut 1000
void doTuning(){
void doTuningWithThresHold(){
int s = 0; int s = 0;
unsigned long prev_freq; unsigned long prev_freq;
long incdecValue = 0; long incdecValue = 0;
@ -615,6 +620,8 @@ void doTuning(){
if (s == 0) { if (s == 0) {
if (encodedSumValue != 0 && (millis() - encodeTimeOut) > lastEncInputtime) if (encodedSumValue != 0 && (millis() - encodeTimeOut) > lastEncInputtime)
encodedSumValue = 0; encodedSumValue = 0;
lastMovedirection = 0;
return; return;
} }
lastEncInputtime = millis(); lastEncInputtime = millis();
@ -622,23 +629,25 @@ void doTuning(){
//for check moving direction //for check moving direction
encodedSumValue += (s > 0 ? 1 : -1); encodedSumValue += (s > 0 ? 1 : -1);
//check threshold //check threshold and operator actions (hold dial speed = continous moving, skip threshold check)
if ((encodedSumValue * encodedSumValue) <= (threshold * threshold)) if ((lastTunetime < millis() - skipThresholdTime) && ((encodedSumValue * encodedSumValue) <= (threshold * threshold)))
return; return;
lastTunetime = millis();
//Valid Action without noise //Valid Action without noise
encodedSumValue = 0; encodedSumValue = 0;
prev_freq = frequency; prev_freq = frequency;
//incdecValue = tuningStep * s; //incdecValue = tuningStep * s;
frequency += (arTuneStep[tuneStepIndex -1] * s); frequency += (arTuneStep[tuneStepIndex -1] * s * (s * s < 10 ? 1 : 3)); //appield weight (s is speed)
if (prev_freq < 10000000l && frequency > 10000000l) if (prev_freq < 10000000l && frequency > 10000000l)
isUSB = true; isUSB = true;
if (prev_freq > 10000000l && frequency < 10000000l) if (prev_freq > 10000000l && frequency < 10000000l)
isUSB = false; isUSB = false;
setFrequency(frequency); setFrequency(frequency);
updateDisplay(); updateDisplay();
} }
@ -1036,7 +1045,7 @@ void loop(){
if (ritOn) if (ritOn)
doRIT(); doRIT();
else else
doTuning(); doTuningWithThresHold();
} }
//we check CAT after the encoder as it might put the radio into TX //we check CAT after the encoder as it might put the radio into TX

View File

@ -133,112 +133,118 @@ void cwKeyer(void){
int dot,dash; int dot,dash;
bool continue_loop = true; bool continue_loop = true;
unsigned tmpKeyControl = 0; unsigned tmpKeyControl = 0;
if( Iambic_Key ){
if( Iambic_Key ) {
while(continue_loop){ while(continue_loop) {
switch (keyerState) { switch (keyerState) {
case IDLE: case IDLE:
tmpKeyControl = update_PaddleLatch(0); tmpKeyControl = update_PaddleLatch(0);
if ( tmpKeyControl == DAH_L || tmpKeyControl == DIT_L || if ( tmpKeyControl == DAH_L || tmpKeyControl == DIT_L ||
tmpKeyControl == (DAH_L | DIT_L) || (keyerControl & 0x03)) { tmpKeyControl == (DAH_L | DIT_L) || (keyerControl & 0x03)) {
update_PaddleLatch(1); update_PaddleLatch(1);
keyerState = CHK_DIT; keyerState = CHK_DIT;
}else{ }else{
if (0 < cwTimeout && cwTimeout < millis()){
cwTimeout = 0;
stopTx();
}
continue_loop = false;
}
break;
case CHK_DIT:
if (keyerControl & DIT_L) {
keyerControl |= DIT_PROC;
ktimer = cwSpeed;
keyerState = KEYED_PREP;
}else{
keyerState = CHK_DAH;
}
break;
case CHK_DAH:
if (keyerControl & DAH_L) {
ktimer = cwSpeed*3;
keyerState = KEYED_PREP;
}else{
keyerState = IDLE;
}
break;
case KEYED_PREP:
ktimer += millis(); // set ktimer to interval end time
keyerControl &= ~(DIT_L + DAH_L); // clear both paddle latch bits
keyerState = KEYED; // next state
if (!inTx){
keyDown = 0;
cwTimeout = millis() + cwDelayTime * 10; //+ CW_TIMEOUT;
startTx(TX_CW, 1);
}
cwKeydown();
break;
case KEYED:
if (millis() > ktimer) { // are we at end of key down ?
cwKeyUp();
ktimer = millis() + cwSpeed; // inter-element time
keyerState = INTER_ELEMENT; // next state
}else if (keyerControl & IAMBICB) {
update_PaddleLatch(1); // early paddle latch in Iambic B mode
}
break;
case INTER_ELEMENT:
// Insert time between dits/dahs
update_PaddleLatch(1); // latch paddle state
if (millis() > ktimer) { // are we at end of inter-space ?
if (keyerControl & DIT_PROC) { // was it a dit or dah ?
keyerControl &= ~(DIT_L + DIT_PROC); // clear two bits
keyerState = CHK_DAH; // dit done, check for dah
}else{
keyerControl &= ~(DAH_L); // clear dah latch
keyerState = IDLE; // go idle
}
}
break;
}
Check_Cat(3);
} //end of while
}
else{
while(1){
if (update_PaddleLatch(0) == DIT_L) {
// if we are here, it is only because the key is pressed
if (!inTx){
keyDown = 0;
cwTimeout = millis() + cwDelayTime * 10; //+ CW_TIMEOUT;
startTx(TX_CW, 1);
}
cwKeydown();
while ( update_PaddleLatch(0) == DIT_L )
delay_background(1, 3);
cwKeyUp();
}
else{
if (0 < cwTimeout && cwTimeout < millis()){ if (0 < cwTimeout && cwTimeout < millis()){
cwTimeout = 0; cwTimeout = 0;
keyDown = 0;
stopTx(); stopTx();
} }
continue_loop = false; if (!cwTimeout)
return;
// got back to the beginning of the loop, if no further activity happens on straight key
// we will time out, and return out of this routine
//delay(5);
delay_background(5, 3);
continue;
} }
break;
case CHK_DIT: Check_Cat(2);
if (keyerControl & DIT_L) { } //end of while
keyerControl |= DIT_PROC; } //end of elese
ktimer = cwSpeed;
keyerState = KEYED_PREP;
}else{
keyerState = CHK_DAH;
}
break;
case CHK_DAH:
if (keyerControl & DAH_L) {
ktimer = cwSpeed*3;
keyerState = KEYED_PREP;
}else{
keyerState = IDLE;
}
break;
case KEYED_PREP:
ktimer += millis(); // set ktimer to interval end time
keyerControl &= ~(DIT_L + DAH_L); // clear both paddle latch bits
keyerState = KEYED; // next state
if (!inTx){
keyDown = 0;
cwTimeout = millis() + cwDelayTime * 10; //+ CW_TIMEOUT;
startTx(TX_CW, 1);
}
cwKeydown();
break;
case KEYED:
if (millis() > ktimer) { // are we at end of key down ?
cwKeyUp();
ktimer = millis() + cwSpeed; // inter-element time
keyerState = INTER_ELEMENT; // next state
}else if (keyerControl & IAMBICB) {
update_PaddleLatch(1); // early paddle latch in Iambic B mode
}
break;
case INTER_ELEMENT:
// Insert time between dits/dahs
update_PaddleLatch(1); // latch paddle state
if (millis() > ktimer) { // are we at end of inter-space ?
if (keyerControl & DIT_PROC) { // was it a dit or dah ?
keyerControl &= ~(DIT_L + DIT_PROC); // clear two bits
keyerState = CHK_DAH; // dit done, check for dah
}else{
keyerControl &= ~(DAH_L); // clear dah latch
keyerState = IDLE; // go idle
}
}
break;
}
} //end of while
}else{
while(1){
//if (analogRead(ANALOG_DOT) < 600){
if (update_PaddleLatch(0) == DIT_L) {
// if we are here, it is only because the key is pressed
if (!inTx){
keyDown = 0;
cwTimeout = millis() + cwDelayTime * 10; //+ CW_TIMEOUT;
startTx(TX_CW, 1);
}
// start the transmission)
cwKeydown();
//while ( analogRead(ANALOG_DOT) < 600 ) delay(1);
while ( update_PaddleLatch(0) == DIT_L ) delay(1);
cwKeyUp();
}else{
if (0 < cwTimeout && cwTimeout < millis()){
cwTimeout = 0;
keyDown = 0;
stopTx();
}
if (!cwTimeout)
return;
// got back to the beginning of the loop, if no further activity happens on straight key
// we will time out, and return out of this routine
delay(5);
continue;
}
} //end of else
}
} }