Trying to change a button's color ("Highlight") based on Virtual Bit 55. This button will eventually run a KMotion C program (Initialize file - Script not set up yet in attached pictures - forever loop sets Bit55 after initializing, clears same if need to re-initialize occurs).
The button's "Highlight" doesn't change when I cycle Bit 55 (as the Label for Tool Length, But30, does).
If I change the Style (e.g. to Label, then click Set, then back to Button, click Set), it does change, but not as expected (see attached);
Bit55=0 (57=1). Note black button.
Bit55=1 (57=0) . Note Red button but with yellow font.
From https://www.dynomotion.com/wiki/index.p ... een_Editor;
Buttons can have all 4 options (foreground and background colors in on- and off-state) or they can also be bitmaps. Labels can load actions/scripts when the main screen is loaded.
What am I missing?
Bit Driven Button Highlight
Moderators: TomKerekes, dynomotion
-
- Posts: 21
- Joined: Tue Nov 20, 2018 5:39 pm
- Location: Sharonville, Ohio
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Bit Driven Button Highlight
Try using a Toggle Button.
Also don't set the text color and text background both to the same color (0 = black)
Also don't set the text color and text background both to the same color (0 = black)
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 21
- Joined: Tue Nov 20, 2018 5:39 pm
- Location: Sharonville, Ohio
Re: Bit Driven Button Highlight
Thanks for the quick reply.
I was using your color fields incorrectly. Here is how I think they work for a Style=ToggleButton button;
If the bit changes later, so does the button's text and fill attributes.
Since I don't want the button click events to determine the assigned bit's state (I want that to be dependent on successful completion of the assigned action - a C file, and subsequent events, like an axis disabling, etc.), I added code to clear the bit state at the beginning of my C file (presuming the ToggleButton's toggle event precedes my C code's ClearBit statement - perhaps I'll see it flash).
Please let me know if I'm missing anything.
What awesome support!
I was using your color fields incorrectly. Here is how I think they work for a Style=ToggleButton button;
- First column of color fields is for the text color (top when bit=0, bottom when bit=1),
- Second column of fields is for the fill color.
If the bit changes later, so does the button's text and fill attributes.
Since I don't want the button click events to determine the assigned bit's state (I want that to be dependent on successful completion of the assigned action - a C file, and subsequent events, like an axis disabling, etc.), I added code to clear the bit state at the beginning of my C file (presuming the ToggleButton's toggle event precedes my C code's ClearBit statement - perhaps I'll see it flash).
Please let me know if I'm missing anything.
What awesome support!
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Bit Driven Button Highlight
Hello,
I'm trying to do something similar but the c code is not running when I toggle the button. If I change the button type to button from togglebutton then the c code runs but then the bitmaps don't update based on the bit state and the bit doesn't toggle. I tried "Program" and "Program/wait" as the action type, neither worked.
I'm running an older version 4.34j, with a slightly updated screen builder (that added scaling).
If I update can you confirm that the toggle button will run C code? Just don't want to go through the updating if the bug is still there. Or perhaps I'm doing something wrong
Thanks.
FWIW the goal is to add a toggle button that displays the state of the axis enabled. If a limit switch is tripped, and the axis is disabled, the toggle button could be used to re-enable the axis so it can be moved away from the limit switch. I have code that runs in the main thread that updates the bit state based on the enabled state of the axis.
code that gets run when the toggle button is pressed:
main thread code, ReadAxisEnabledState() called in forever loop
I'm trying to do something similar but the c code is not running when I toggle the button. If I change the button type to button from togglebutton then the c code runs but then the bitmaps don't update based on the bit state and the bit doesn't toggle. I tried "Program" and "Program/wait" as the action type, neither worked.
I'm running an older version 4.34j, with a slightly updated screen builder (that added scaling).
If I update can you confirm that the toggle button will run C code? Just don't want to go through the updating if the bug is still there. Or perhaps I'm doing something wrong
Thanks.
FWIW the goal is to add a toggle button that displays the state of the axis enabled. If a limit switch is tripped, and the axis is disabled, the toggle button could be used to re-enable the axis so it can be moved away from the limit switch. I have code that runs in the main thread that updates the bit state based on the enabled state of the axis.
code that gets run when the toggle button is pressed:
Code: Select all
#include "GregCommon.h"
int Enabled(int axis_num)
{
return chan[axis_num].Enable;
}
main()
{
// this is to allow the user to re-enable the axis after a limit switch fault, axis can be moved away from limit
int desiredState = ReadBit(XAXIS_ENABLED_BIT);
int currentState = Enabled(XAXIS_NUM); // chan[axis_num].Enable;
printf("Current axis enabled state: %d, desired axis enabled state: %d\n", currentState, desiredState);
if (desiredState == 1) {
EnableAxis(XAXIS_NUM);
} else {
DisableAxis(XAXIS_NUM);
}
currentState = Enabled(XAXIS_NUM);
printf("Axis state: %d\n", currentState);
}
Code: Select all
void SetAxisEnabledStatusBit(int axisEnableBit, int enabled)
{
if (enabled) {
SetBit(axisEnableBit);
}
else {
ClearBit(axisEnableBit);
}
}
void ReadAxisEnabledState()
{
int xstate = Enabled(XAXIS_NUM);
int ystate = Enabled(YAXIS_NUM);
int astate = Enabled(AAXIS_NUM);
SetAxisEnabledStatusBit(XAXIS_ENABLED_BIT, xstate);
SetAxisEnabledStatusBit(YAXIS_ENABLED_BIT, ystate);
SetAxisEnabledStatusBit(AAXIS_ENABLED_BIT, astate);
}
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Bit Driven Button Highlight
Yes toggle buttons were changed to also execute Actions in V4.35c
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.