Firstly, I have a system much like yours. I have a manual override on the gearbox control switch, so I can lock it in high or low.
You don't need that. Can you trust the operator to know when to ignore the request to change gear?
G-code can read back the mode:
linuxcnc.org/docs/2.8/html/gcode/overvie...ub:system-parameters
As can Python:
linuxcnc.org/docs/2.8/html/config/python...xcnc_stat_attributes
(see the "gcodes" attribute)
If you want the mode as a HAL pin, then you can probably use Gstat to create it, see the first example here:
linuxcnc.org/docs/2.8/html/gui/GStat.html
And the "css-mode"callback.
I am not 100% sure that the GStat HAL pin and the change in S would be synchronised.
What might work better would be to remap the S command to call a Python script. This could look at the speed command and the css mode and set things accordingly.
linuxcnc.org/docs/2.8/html/remap/remap.h...ng_codes_s_m0_m1_m60
(Remapping is a big and complex subject, however)
What should also work is a modified version of hal_manualtoolchange that is triggered by the spindle turning on, and which looks at the G-codes status before deciding which message to display.
So, in summary I can think of at least 5 ways to do what you ask, and I am not sure which would work best for you.
At this point I would suggest separating the messaging from the motor speed calculation. Leave the HAL component as it is, just calculating motor speed based on lever position.