mirror of
https://codeberg.org/mclemens/ubitxv6.git
synced 2025-02-21 06:57:27 -05:00
Merge master into one_stop_settings to get the interrupt encoders
This commit is contained in:
commit
2fc534f12a
1
ubitx.h
1
ubitx.h
@ -109,6 +109,7 @@ void cwKeyer(void);
|
|||||||
void switchVFO(Vfo_e vfoSelect);
|
void switchVFO(Vfo_e 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
@ -568,7 +568,6 @@ void updateDisplay() {
|
|||||||
displayVFO(globalSettings.activeVfo);
|
displayVFO(globalSettings.activeVfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
@ -588,11 +587,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;
|
||||||
@ -630,6 +633,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(!globalSettings.ritOn){
|
if(!globalSettings.ritOn){
|
||||||
@ -1029,4 +1108,3 @@ void doCommands(){
|
|||||||
|
|
||||||
checkCAT();
|
checkCAT();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,7 +359,7 @@ void doTuning(){
|
|||||||
|
|
||||||
if (now >= nextFrequencyUpdate && prev_freq != GetActiveVfoFreq()){
|
if (now >= nextFrequencyUpdate && prev_freq != GetActiveVfoFreq()){
|
||||||
updateDisplay();
|
updateDisplay();
|
||||||
nextFrequencyUpdate = now + 500;
|
nextFrequencyUpdate = now + 100;
|
||||||
prev_freq = GetActiveVfoFreq();
|
prev_freq = GetActiveVfoFreq();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,6 +367,8 @@ 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 = GetActiveVfoFreq();
|
prev_freq = GetActiveVfoFreq();
|
||||||
uint32_t new_freq = prev_freq;
|
uint32_t new_freq = prev_freq;
|
||||||
@ -432,6 +434,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…
x
Reference in New Issue
Block a user