All the Hal files are useful, with what you supplied there is no telling how your mesa card was setup.
More time wasted with using AI. You don't requires script to assemble the logic for a simple pendant with buttons and an mpg, it can all be done via Hal.
A mesa card does require a seperate Hal component to be loaded for an encoder, if you are using the on board encoder and don't require it for any spindle speed or position feedback. The encoder Hal component is usually used with the parallel port, when no encoder is available, ie with with a mesa card, tho you could set one by using mesa input pins as would you would do via a parallel port.
To tell the truth I did write a Hal component that takes the count from a encoder on the mesa card and some other pin inputs for scale and such, but this was just a way to simplify the Hal file for myself, it is not really required, all the connections can be made using seperate Hal components.
If you do want to use a script, the best way to get the values of the input pins and the encoder counts is to simply create the pins needed.
I would honestly browse the forum, I'm sure a topic came up recently regarding a configuration for a pendant.
Forget AI for Linuxcnc, I have seen some very upset people when it is pointed out the code produced is more or less useless.
One reason for the concept of Hal in Linuxcnc is so that a non programmer can just join this bit to this and this bit to that without having to indulge in programming.
Now my thoughts usually don't run in an ordered manner, what you best might is to describe by words, schematics, drawing on the back of an envelope, blackboard or for us more of a Luddite bent maybe a drawing on a cavewall. Once we know how you want to connect this bit to that bit answers will come.
But yeah read the docs, have a browse of some of the supplied components and see what best fits what you need to do.
What follows is the ranting old man, can be ignored. Or hysterically laughed at.

It does seem quite ironic that AI isn't a great help with a project such as Linuxcnc. CNC controlling the machines and AI replacing the use of the human mind.
Once humanity achieves Actual Intelligence may Artificial Intelligence maybe of some use.