Single execution HAL function

More
01 Apr 2021 01:51 #204346 by Limedodge
Update:

After spending several hours trying to figure out why pass through variables (PXXX) were not working I came up with an even more elegant solution. Turns out, P and Q numbers are float so unless you convert them to integers, nothing works. Then I just hard coded a BASH script that set the pins skipping the bitslice altogether. Peoblems solved

The integer converter is kinda hokey, but should work since the input on PXXX should only ever be between 0 and 255.

Here's what I did
#!/bin/bash
# M102 file to convert power input into 8 bit output

# store pass through number into shell
pow=$1

# number come through as float so convert to integer
power=${pow/\.*}

#set pins based on bitwise AND logic
if ((1 & $power)); then halcmd setp hm2_7i96.0.gpio.040.out True; else halcmd setp hm2_7i96.0.gpio.040.out False; fi
if ((2 & $power)); then halcmd setp hm2_7i96.0.gpio.041.out True; else halcmd setp hm2_7i96.0.gpio.041.out False; fi
if ((4 & $power)); then halcmd setp hm2_7i96.0.gpio.042.out True; else halcmd setp hm2_7i96.0.gpio.042.out False; fi
if ((8 & $power)); then halcmd setp hm2_7i96.0.gpio.043.out True; else halcmd setp hm2_7i96.0.gpio.043.out False; fi
if ((16 & $power)); then halcmd setp hm2_7i96.0.gpio.044.out True; else halcmd setp hm2_7i96.0.gpio.044.out False; fi
if ((32 & $power)); then halcmd setp hm2_7i96.0.gpio.045.out True; else halcmd setp hm2_7i96.0.gpio.045.out False; fi
if ((64 & $power)); then halcmd setp hm2_7i96.0.gpio.046.out True; else halcmd setp hm2_7i96.0.gpio.046.out False; fi
if ((128 & $power)); then halcmd setp hm2_7i96.0.gpio.047.out True; else halcmd setp hm2_7i96.0.gpio.047.out False; fi

exit 0

Thanks again for everyone's input!

Please Log in or Create an account to join the conversation.

Time to create page: 0.078 seconds
Powered by Kunena Forum