Guest User

Untitled

a guest
Dec 14th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. component pokeys "PoKeys IO driver, by Mit Zot";
  2.  
  3. option userspace yes;
  4.  
  5.  
  6. pin out bit in-# [55];
  7. pin out float ain-# [3];
  8. pin out bit err;
  9. pin in float analog-scale-# [3];
  10. pin in unsigned devSerial;
  11. pin out bit alive;
  12.  
  13. license "GPL";
  14. ;;
  15.  
  16. #include "PoKeysLib.h"
  17. #include <unistd.h> /* UNIX standard function definitions */
  18.  
  19. sPoKeysDevice * dev=0;
  20. int i=0;
  21.  
  22. void user_mainloop(void)
  23. {
  24.  
  25. while(0xb){
  26. FOR_ALL_INSTS() {
  27.  
  28. while(dev == NULL)dev = PK_ConnectToDeviceWSerial(devSerial, 2000); //waits for usb device
  29.  
  30.  
  31. alive=1;
  32. if ((PK_DigitalIOGet(dev) == PK_OK) && (PK_AnalogIOGet(dev) == PK_OK)){ //gets IO data and checks return value
  33. err=0;
  34. for(i=0;i<54;i++)in(i)=!dev->Pins[i].DigitalValueGet; //just transfers values
  35. for(i=0;i<3;i++)ain(i)=(dev->Pins[i+44].AnalogValue * analog_scale(i)) /4096.0;
  36. }
  37. else{ //on connection error
  38. PK_DisconnectDevice(dev);
  39. dev=NULL; //tries to reconnect
  40. err=1;
  41. for(i=0;i<54;i++)in(i)=0;
  42. for(i=0;i<3;i++)ain(i)=0;
  43. }
  44. alive=0;
  45. usleep(40000);
  46. }
  47. }
  48.  
  49. exit(0);
  50. }
Add Comment
Please, Sign In to add comment