Created
December 14, 2018 16:16
-
-
Save KurtJacobson/10e4bbff7b2af4366496e876b107a506 to your computer and use it in GitHub Desktop.
LinuxCNC HAL pokeys.comp, edited per Andy P to support scaled anolog outputs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component pokeys "PoKeys IO driver, by Mit Zot"; | |
option userspace yes; | |
pin out bit in-# [55]; | |
pin out float ain-# [3]; | |
pin out bit err; | |
pin in float analog-scale-# [3]; | |
pin in unsigned devSerial; | |
pin out bit alive; | |
license "GPL"; | |
;; | |
#include "PoKeysLib.h" | |
#include <unistd.h> /* UNIX standard function definitions */ | |
sPoKeysDevice * dev=0; | |
int i=0; | |
void user_mainloop(void) | |
{ | |
while(0xb){ | |
FOR_ALL_INSTS() { | |
while(dev == NULL)dev = PK_ConnectToDeviceWSerial(devSerial, 2000); //waits for usb device | |
alive=1; | |
if ((PK_DigitalIOGet(dev) == PK_OK) && (PK_AnalogIOGet(dev) == PK_OK)){ //gets IO data and checks return value | |
err=0; | |
for(i=0;i<54;i++)in(i)=!dev->Pins[i].DigitalValueGet; //just transfers values | |
for(i=0;i<3;i++)ain(i)=(dev->Pins[i+44].AnalogValue * analog_scale(i)) /4096.0; | |
} | |
else{ //on connection error | |
PK_DisconnectDevice(dev); | |
dev=NULL; //tries to reconnect | |
err=1; | |
for(i=0;i<54;i++)in(i)=0; | |
for(i=0;i<3;i++)ain(i)=0; | |
} | |
alive=0; | |
usleep(40000); | |
} | |
} | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment