mirror of
https://codeberg.org/mclemens/ubitxv6.git
synced 2024-11-04 03:57:16 -05:00
Merge pull request #1 from SmittyHalibut/pdq_gfx_update
Interrupt Encoder Update
This commit is contained in:
commit
baf880c7ae
1
ubitx.h
1
ubitx.h
@ -179,6 +179,7 @@ void cwKeyer(void);
|
|||||||
void switchVFO(int vfoSelect);
|
void switchVFO(int vfoSelect);
|
||||||
|
|
||||||
int enc_read(void); // returns the number of ticks in a short interval, +ve in clockwise, -ve in anti-clockwise
|
int enc_read(void); // returns the number of ticks in a short interval, +ve in clockwise, -ve in anti-clockwise
|
||||||
|
void enc_setup(void); // Setups up initial values and interrupts.
|
||||||
int btnDown(); //returns true if the encoder button is pressed
|
int btnDown(); //returns true if the encoder button is pressed
|
||||||
|
|
||||||
/* these functions are called universally to update the display */
|
/* these functions are called universally to update the display */
|
||||||
|
82
ubitx_ui.cpp
82
ubitx_ui.cpp
@ -565,7 +565,6 @@ void updateDisplay() {
|
|||||||
displayVFO(vfoActive);
|
displayVFO(vfoActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
int enc_prev_state = 3;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The A7 And A6 are purely analog lines on the Arduino Nano
|
* The A7 And A6 are purely analog lines on the Arduino Nano
|
||||||
@ -585,11 +584,15 @@ int enc_prev_state = 3;
|
|||||||
* at which the enccoder was spun
|
* at which the enccoder was spun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
int enc_prev_state = 3;
|
||||||
|
|
||||||
byte enc_state (void) {
|
byte enc_state (void) {
|
||||||
//Serial.print(digitalRead(ENC_A)); Serial.print(":");Serial.println(digitalRead(ENC_B));
|
//Serial.print(digitalRead(ENC_A)); Serial.print(":");Serial.println(digitalRead(ENC_B));
|
||||||
return (digitalRead(ENC_A) == 1 ? 1 : 0) + (digitalRead(ENC_B) == 1 ? 2: 0);
|
return (digitalRead(ENC_A) == 1 ? 1 : 0) + (digitalRead(ENC_B) == 1 ? 2: 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int enc_read(void) {
|
int enc_read(void) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
byte newState;
|
byte newState;
|
||||||
@ -627,6 +630,82 @@ int enc_read(void) {
|
|||||||
// Serial.println(result);
|
// Serial.println(result);
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SmittyHalibut's encoder handling, using interrupts. Should be quicker, smoother handling.
|
||||||
|
*/
|
||||||
|
int8_t enc_count;
|
||||||
|
uint8_t prev_enc;
|
||||||
|
|
||||||
|
uint8_t enc_state (void) {
|
||||||
|
return (digitalRead(ENC_A)?1:0 + digitalRead(ENC_B)?2:0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Setup the encoder interrupts and global variables.
|
||||||
|
*/
|
||||||
|
void pci_setup(byte pin) {
|
||||||
|
*digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin)); // enable pin
|
||||||
|
PCIFR |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
|
||||||
|
PCICR |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group
|
||||||
|
}
|
||||||
|
|
||||||
|
void enc_setup(void) {
|
||||||
|
enc_count = 0;
|
||||||
|
// This is already done in setup() ?
|
||||||
|
//pinMode(ENC_A, INPUT);
|
||||||
|
//pinMode(ENC_B, INPUT);
|
||||||
|
prev_enc = enc_state();
|
||||||
|
|
||||||
|
// Setup Pin Change Interrupts for the encoder inputs
|
||||||
|
pci_setup(ENC_A);
|
||||||
|
pci_setup(ENC_B);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The Interrupt Service Routine for Pin Change Interrupts on A0-A5.
|
||||||
|
*/
|
||||||
|
ISR (PCINT1_vect) {
|
||||||
|
uint8_t cur_enc = enc_state();
|
||||||
|
if (prev_enc == cur_enc) {
|
||||||
|
//Serial.println("unnecessary ISR");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//Serial.print(prev_enc);
|
||||||
|
//Serial.println(cur_enc);
|
||||||
|
|
||||||
|
//these transitions point to the enccoder being rotated anti-clockwise
|
||||||
|
if ((prev_enc == 0 && cur_enc == 2) ||
|
||||||
|
(prev_enc == 2 && cur_enc == 3) ||
|
||||||
|
(prev_enc == 3 && cur_enc == 1) ||
|
||||||
|
(prev_enc == 1 && cur_enc == 0))
|
||||||
|
{
|
||||||
|
enc_count-=1;
|
||||||
|
}
|
||||||
|
//these transitions point to the enccoder being rotated clockwise
|
||||||
|
else if ((prev_enc == 0 && cur_enc == 1) ||
|
||||||
|
(prev_enc == 1 && cur_enc == 3) ||
|
||||||
|
(prev_enc == 3 && cur_enc == 2) ||
|
||||||
|
(prev_enc == 2 && cur_enc == 0))
|
||||||
|
{
|
||||||
|
enc_count+=1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// A change to two states, we can't tell whether it was forward or backward, so we skip it.
|
||||||
|
//Serial.println("skip");
|
||||||
|
}
|
||||||
|
prev_enc = cur_enc; // Record state for next pulse interpretation
|
||||||
|
}
|
||||||
|
|
||||||
|
int enc_read(void) {
|
||||||
|
int8_t ret = enc_count;
|
||||||
|
enc_count = 0;
|
||||||
|
return int(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ritToggle(struct Button *button){
|
void ritToggle(struct Button *button){
|
||||||
if (ritOn == 0){
|
if (ritOn == 0){
|
||||||
@ -1021,4 +1100,3 @@ void doCommands(){
|
|||||||
|
|
||||||
checkCAT();
|
checkCAT();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -524,7 +524,7 @@ void doTuning(){
|
|||||||
|
|
||||||
if (now >= nextFrequencyUpdate && prev_freq != frequency){
|
if (now >= nextFrequencyUpdate && prev_freq != frequency){
|
||||||
updateDisplay();
|
updateDisplay();
|
||||||
nextFrequencyUpdate = now + 500;
|
nextFrequencyUpdate = now + 100;
|
||||||
prev_freq = frequency;
|
prev_freq = frequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -532,22 +532,26 @@ void doTuning(){
|
|||||||
if (!s)
|
if (!s)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
//Serial.println(s);
|
||||||
|
|
||||||
doingCAT = 0; // go back to manual mode if you were doing CAT
|
doingCAT = 0; // go back to manual mode if you were doing CAT
|
||||||
prev_freq = frequency;
|
prev_freq = frequency;
|
||||||
|
|
||||||
|
// TODO With the new more responsive tuning, 5 and 10 are nearly useless
|
||||||
if (s > 10)
|
// thresholds for acceleration. I rarely see above 2 or 3 even when turning
|
||||||
frequency += 200l * s;
|
// the knob quickly.
|
||||||
else if (s > 5)
|
if (s < 5 && s > -5) {
|
||||||
frequency += 100l * s;
|
|
||||||
else if (s > 0)
|
|
||||||
frequency += 50l * s;
|
frequency += 50l * s;
|
||||||
else if (s < -10)
|
//Serial.println(" 5");
|
||||||
frequency += 200l * s;
|
}
|
||||||
else if (s < -5)
|
else if (s < 10 && s > -10) {
|
||||||
frequency += 100l * s;
|
frequency += 100l * s;
|
||||||
else if (s < 0)
|
//Serial.println(" 10");
|
||||||
frequency += 50l * s;
|
}
|
||||||
|
else { // if (s >= 10 || s <= -10)
|
||||||
|
frequency += 200l * s;
|
||||||
|
//Serial.println(" <");
|
||||||
|
}
|
||||||
|
|
||||||
if (prev_freq < 10000000l && frequency > 10000000l)
|
if (prev_freq < 10000000l && frequency > 10000000l)
|
||||||
isUSB = true;
|
isUSB = true;
|
||||||
@ -676,6 +680,7 @@ void initPorts(){
|
|||||||
pinMode(ENC_A, INPUT_PULLUP);
|
pinMode(ENC_A, INPUT_PULLUP);
|
||||||
pinMode(ENC_B, INPUT_PULLUP);
|
pinMode(ENC_B, INPUT_PULLUP);
|
||||||
pinMode(FBUTTON, INPUT_PULLUP);
|
pinMode(FBUTTON, INPUT_PULLUP);
|
||||||
|
enc_setup();
|
||||||
|
|
||||||
//configure the function button to use the external pull-up
|
//configure the function button to use the external pull-up
|
||||||
// pinMode(FBUTTON, INPUT);
|
// pinMode(FBUTTON, INPUT);
|
||||||
|
Loading…
Reference in New Issue
Block a user