renamed Absolute Encoder to Binary Selector Switch

This commit is contained in:
Alexander Richter 2023-05-02 19:16:06 +02:00
parent b86797cb95
commit 2bf2dfba4f
3 changed files with 40 additions and 38 deletions

View File

@ -12,9 +12,11 @@
Currently the Software provides: Currently the Software provides:
- analog Inputs - analog Inputs
- latching Potentiometers - latching Potentiometers
- 1 absolute encoder input - 1 binary encoded selector Switch
- digital Inputs - digital Inputs
- digital Outputs - digital Outputs
- Matrix Keypad
The Send and receive Protocol is <Signal><PinNumber>:<Pin State> The Send and receive Protocol is <Signal><PinNumber>:<Pin State>
To begin Transmitting Ready is send out and expects to receive E: to establish connection. Afterwards Data is exchanged. To begin Transmitting Ready is send out and expects to receive E: to establish connection. Afterwards Data is exchanged.
@ -26,7 +28,7 @@
Digital LED Outputs = 'D' -read only -Pin State: 0,1 Digital LED Outputs = 'D' -read only -Pin State: 0,1
Analog Inputs = 'A' -write only -Pin State: 0-1024 Analog Inputs = 'A' -write only -Pin State: 0-1024
Latching Potentiometers = 'L' -write only -Pin State: 0-max Position Latching Potentiometers = 'L' -write only -Pin State: 0-max Position
Absolute Encoder input = 'K' -write only -Pin State: 0-32 binary encoded Selector = 'K' -write only -Pin State: 0-32
Keyboard Input: Keyboard Input:
Matrix Keypad = 'M' -write only -Pin State: Number of Matrix Key. Matrix Keypad = 'M' -write only -Pin State: Number of Matrix Key.
@ -118,9 +120,9 @@ Note that Analog Pin numbering is different to the Print on the PCB.
int margin = 20; //giving it some margin so Numbers dont jitter, make this number smaller if your knob has more than 50 Positions int margin = 20; //giving it some margin so Numbers dont jitter, make this number smaller if your knob has more than 50 Positions
#endif #endif
//#define ABSENCODER //Support of an Rotating Knob that was build in my Machine. It encodes 32 Positions with 5 Pins in Binary. This will generate 32 Pins in LinuxCNC Hal. //#define BINSEL //Support of an Rotating Knob that was build in my Machine. It encodes 32 Positions with 5 Pins in Binary. This will generate 32 Pins in LinuxCNC Hal.
#ifdef ABSENCODER #ifdef BINSEL
const int AbsEncPins[] = {27,28,31,29,30}; //1,2,4,8,16 const int BinSelKnobPins[] = {27,28,31,29,30}; //1,2,4,8,16
#endif #endif
@ -257,7 +259,7 @@ const int debounceDelay = 50;
int Lpoti[LPotis]; int Lpoti[LPotis];
int oldLpoti[LPotis]; int oldLpoti[LPotis];
#endif #endif
#ifdef ABSENCODER #ifdef BINSEL
int oldAbsEncState; int oldAbsEncState;
#endif #endif
#ifdef KEYPAD #ifdef KEYPAD
@ -328,12 +330,12 @@ void setup() {
pinMode(StatLedPin, OUTPUT); pinMode(StatLedPin, OUTPUT);
#endif #endif
#ifdef ABSENCODER #ifdef BINSEL
pinMode(AbsEncPins[0], INPUT_PULLUP); pinMode(BinSelKnobPins[0], INPUT_PULLUP);
pinMode(AbsEncPins[1], INPUT_PULLUP); pinMode(BinSelKnobPins[1], INPUT_PULLUP);
pinMode(AbsEncPins[2], INPUT_PULLUP); pinMode(BinSelKnobPins[2], INPUT_PULLUP);
pinMode(AbsEncPins[3], INPUT_PULLUP); pinMode(BinSelKnobPins[3], INPUT_PULLUP);
pinMode(AbsEncPins[4], INPUT_PULLUP); pinMode(BinSelKnobPins[4], INPUT_PULLUP);
#endif #endif
#ifdef DLED #ifdef DLED
@ -380,7 +382,7 @@ void loop() {
#ifdef LPOTIS #ifdef LPOTIS
readLPoti(); //read LPotis & send data readLPoti(); //read LPotis & send data
#endif #endif
#ifdef ABSENCODER #ifdef BINSEL
readAbsKnob(); //read ABS Encoder & send data readAbsKnob(); //read ABS Encoder & send data
#endif #endif
@ -561,22 +563,22 @@ void readsInputs(){
} }
#endif #endif
#ifdef ABSENCODER #ifdef BINSEL
int readAbsKnob(){ int readAbsKnob(){
int var = 0; int var = 0;
if(digitalRead(AbsEncPins[0])==1){ if(digitalRead(BinSelKnobPins[0])==1){
var += 1; var += 1;
} }
if(digitalRead(AbsEncPins[1])==1){ if(digitalRead(BinSelKnobPins[1])==1){
var += 2; var += 2;
} }
if(digitalRead(AbsEncPins[2])==1){ if(digitalRead(BinSelKnobPins[2])==1){
var += 4; var += 4;
} }
if(digitalRead(AbsEncPins[3])==1){ if(digitalRead(BinSelKnobPins[3])==1){
var += 8; var += 8;
} }
if(digitalRead(AbsEncPins[4])==1){ if(digitalRead(BinSelKnobPins[4])==1){
var += 16; var += 16;
} }
if(var != oldAbsEncState){ if(var != oldAbsEncState){

View File

@ -30,13 +30,13 @@ Currently the Software Supports:
- PWM Outputs - PWM Outputs
- Digital RGB LEDs like WS2812 or PL9823 - Digital RGB LEDs like WS2812 or PL9823
- latching Potentiometers / Selector Switches - latching Potentiometers / Selector Switches
- 1 absolute encoder Selector Switch - 1 binary encoded Selector Switch
- Matrix Keyboard Support
TODO TODO
- Matrix Keyboard Support
- Rotary Encoder Input - Rotary Encoder Input
Should this be supported? Should this be supported?
- RC Servo Support - RC Servo Support
@ -124,7 +124,7 @@ You can mix both in one chain, just modify the color values accordingly.
This is a special Feature for rotary Selector Switches. Instead of loosing one Pin per Selection you can turn your Switch in a Potentiometer by soldering 10K resistors between the Pins and connecting the Selector Pin to an Analog Input. This is a special Feature for rotary Selector Switches. Instead of loosing one Pin per Selection you can turn your Switch in a Potentiometer by soldering 10K resistors between the Pins and connecting the Selector Pin to an Analog Input.
The Software will divide the Measured Value and create Hal Pins from it. This way you can have Selector Switches with many positions while only needing one Pin for it. The Software will divide the Measured Value and create Hal Pins from it. This way you can have Selector Switches with many positions while only needing one Pin for it.
# 1 binary encoded Selector Switch input / absolute encoder # 1 binary encoded Selector Switch input
Some rotary Selector Switches work with Binary Encoded Positions. The Software Supports Encoders with 32 Positions. (this could be more if requested) Some rotary Selector Switches work with Binary Encoded Positions. The Software Supports Encoders with 32 Positions. (this could be more if requested)
For each Bit one Pin is needed. So for all 32 Positions 5 Pins are needed = 1,2,4,8,16 For each Bit one Pin is needed. So for all 32 Positions 5 Pins are needed = 1,2,4,8,16
If this feature is enabled, 32 Hal Pins will be created in LinuxCNC. If this feature is enabled, 32 Hal Pins will be created in LinuxCNC.

View File

@ -13,7 +13,7 @@ import serial, time, hal
# Currently the Software provides: # Currently the Software provides:
# - analog Inputs # - analog Inputs
# - latching Potentiometers # - latching Potentiometers
# - 1 absolute encoder input # - 1 binary encoded Selector Switch
# - digital Inputs # - digital Inputs
# - digital Outputs # - digital Outputs
@ -27,7 +27,7 @@ import serial, time, hal
# Digital LED Outputs = 'D' -read only -Pin State: 0,1 # Digital LED Outputs = 'D' -read only -Pin State: 0,1
# Analog Inputs = 'A' -write only -Pin State: 0-1024 # Analog Inputs = 'A' -write only -Pin State: 0-1024
# Latching Potentiometers = 'L' -write only -Pin State: 0-max Position # Latching Potentiometers = 'L' -write only -Pin State: 0-max Position
# Absolute Encoder input = 'K' -write only -Pin State: 0-32 # binary encoded Selector = 'K' -write only -Pin State: 0-32
# Matrix Keypad = 'M' -write only -Pin State: 0,1 # Matrix Keypad = 'M' -write only -Pin State: 0,1
@ -77,10 +77,10 @@ LPoti = 0 #number of LPotis, Set LPoti = 0 to disable
LPotiLatches = [[2,9], #Poti is connected to Pin 2 (A1) and has 9 positions LPotiLatches = [[2,9], #Poti is connected to Pin 2 (A1) and has 9 positions
[3,4]] #Poti is connected to Pin 3 (A2) and has 4 positions [3,4]] #Poti is connected to Pin 3 (A2) and has 4 positions
# Set if you have an Absolute Encoder Knob and how many positions it has (only one supported, as i don't think they are very common and propably nobody uses these anyway) # Set if you have an binary encoded Selector Switch and how many positions it has (only one supported, as i don't think they are very common and propably nobody uses these anyway)
# Set AbsKnob = 0 to disable # Set BinSelKnob = 0 to disable
AbsKnob = 0 #1 enable BinSelKnob = 0 #1 enable
AbsKnobPos = 32 BinSelKnobPos = 32
# Set how many Digital LED's you have connected. # Set how many Digital LED's you have connected.
DLEDcount = 0 DLEDcount = 0
@ -169,9 +169,9 @@ for Poti in range(LPoti):
c.newpin("LPoti.{}.{}" .format(LPotiLatches[Poti][0],Pin), hal.HAL_BIT, hal.HAL_OUT) c.newpin("LPoti.{}.{}" .format(LPotiLatches[Poti][0],Pin), hal.HAL_BIT, hal.HAL_OUT)
# setup Absolute Encoder Knob halpins # setup Absolute Encoder Knob halpins
if AbsKnob: if BinSelKnob:
for port in range(AbsKnobPos): for port in range(BinSelKnobPos):
c.newpin("AbsKnob.{}".format(port), hal.HAL_BIT, hal.HAL_OUT) c.newpin("BinSelKnob.{}".format(port), hal.HAL_BIT, hal.HAL_OUT)
# setup Digital LED halpins # setup Digital LED halpins
if DLEDcount > 0: if DLEDcount > 0:
@ -304,13 +304,13 @@ while True:
elif cmd == "K": elif cmd == "K":
firstcom = 1 firstcom = 1
for port in range(AbsKnobPos): for port in range(BinSelKnobPos):
if port == value: if port == value:
c["AbsKnob.{}".format(port)] = 1 c["BinSelKnob.{}".format(port)] = 1
if(Debug):print("AbsKnob.{}:{}".format(port,1)) if(Debug):print("BinSelKnob.{}:{}".format(port,1))
else: else:
c["AbsKnob.{}".format(port)] = 0 c["BinSelKnob.{}".format(port)] = 0
if(Debug):print("AbsKnob.{}:{}".format(port,0)) if(Debug):print("BinSelKnob.{}:{}".format(port,0))
elif cmd == "M": elif cmd == "M":
firstcom = 1 firstcom = 1