Multiswitch component, one button multiple outputs
This component just demonstrates a one button toggling switch as discussed in this thread.
Can be expanded for more outputs if required.
www.linuxcnc.org/index.php/english/compo...10&id=10272&start=12
regards
(see post 15809 for updated version)
Please Log in or Create an account to join the conversation.
That is pretty neat! Should that comp be added to master?
John
Please Log in or Create an account to join the conversation.
Cool, I will have to try that, I am running out of buttons on my joypad.
Rick G
Please Log in or Create an account to join the conversation.
This component just demonstrates a one button toggling switch as discussed in this thread.
Can be expanded for more outputs if required.
Can we make it take a modparam for number of outputs?
Give me an hour, I will make a version which does it that way for evaluation.
Please Log in or Create an account to join the conversation.
Should that comp be added to master?
I have tested in simulation, setting the pins with halcmd and verifying it cycles and sets flags as it should.
It could do with a real world trial, if Rick is thinking of trying it, I can wait for any feedback first.
I will also wait to see what Andy comes up with, don't know if it is worth a modparam argv / argc type interface when there is only one settable param, but it would make it easier to use and more consistent with other components interfaces I suppose.
regards
Updated version of my offering with toggle set back to input here
Please Log in or Create an account to join the conversation.
[Give me an hour.
Make that three. I got distracted.
The only real advantage to doing it this way is that it supports up to 32 output bits.
It probably needs to support "names=" to be well-behaved component.
/*******************************************************************************
EMC2 HAL component to implement Multistate toggle switch
(c) ArcEye 15122011 schooner30@tiscali.co.uk
example Hal linkages required:-
################################
loadrt multiswitch cfg=4,6,8
addf multiswitch.0 servo-thread
...
net toggle-switch multiswitch.0.toggle <= parport.N.pin-nn-out
net state1 multiswitch.0.state1 => parport.N.pin-nn-in
net state1 multiswitch.0.state2 => parport.N.pin-nn-in
net state1 multiswitch.0.state3 => parport.N.pin-nn-in
If you require an "all off" state, then make the component one bit oversize and
don't connect the extra pin.
*******************************************************************************/
component multiswitch """This component toggles between a specified number of output bits""";
pin in bit up = false "Receives signal to toggle up";
pin in bit down = false "Receives signal to toggle down";
param rw unsigned top-position "Number of positions";
param rw signed position "Current state (may be set in the HAL)";
pin out bit bit-##[32:personality] = false "Output bits";
modparam dummy cfg """cfg should be a comma-separated list of sizes
for example cfg=2,4,6 would create 3 instances of 2, 4 and 6 bits respectively.
Ignore the "personality" parameter, that is auto-generated""";
function _ ;
option extra_setup yes;
option count_function yes;
variable int old_up = 0;
variable int old_down = 0;
author "ArcEye schooner30@tiscali.co.uk";
license "GPL";
;;
#define MAX_COUNT 32
int cfg[MAX_COUNT];
RTAPI_MP_ARRAY_INT(cfg, MAX_COUNT, "array of function sizes");
FUNCTION(_) {
int i;
// debounce
if (up && !old_up) { position++; }
if (down && !old_down) { position--;}
old_up = up;
old_down = down;
if (position < 0) position = top_position;
if (position > top_position) position = 0;
for (i = 0 ; i < personality; i++){
bit(i) = (i == position);
}
}
EXTRA_SETUP(){
personality = cfg[extra_arg];
top_position = personality - 1;
return 0;
}
int get_count(void){
int i;
for (i=0; cfg[i] != 0 && i < MAX_COUNT; i++){}
if (i == 0){
cfg[0] = 4;
i = 1;
}
return i;
}
Please Log in or Create an account to join the conversation.
Personalities and modparams are not something I have played with yet in .comp programming.
The components I have written have been either, only intended for use as singletons, or I have manually set params etc.
It didn't make complete sense until I expanded the macros and generated a C file.
You polish it and publish as your own, there is nothing in there of mine, save the concept, which is hardly unique.
regards
Please Log in or Create an account to join the conversation.
It didn't make complete sense until I expanded the macros and generated a C file.
Indeed. I am using at least two undocumented features there.
It is a pity that there is no way to omit "personality" from the auto-generated docs in cases where you are not using it (actually, it would also be nice to be able to alias "personality" to a modparam name of your choosing.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
For example
loadrt or2 count=2
loads 2 or2 components.
Some good reading...
linuxcnc.org/docs/2.4/HAL_User_Manual.pdf
Rick G
Please Log in or Create an account to join the conversation.