Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.32 KB | None | 0 0
  1.  
  2. unit gpio;
  3.  
  4. interface
  5.  
  6. procedure setup_input(port : string);
  7. procedure setup_output(port : string);
  8. procedure port_write(port : string; value : string);
  9. function port_read(port : string) : string;
  10. procedure release(port : string);
  11.  
  12. implementation
  13.  
  14. procedure write_to_file(filename : string; msg : string);
  15. var
  16.   f : text;
  17. begin
  18.   Assign(f, filename);
  19.   Append(f);
  20.   Writeln(f, msg);
  21.   Close(f);
  22. end;
  23.  
  24. function read_from_file(filename : string) : string;
  25. var
  26.   f : text;
  27.   res : string;
  28. begin
  29.   Assign(f, filename);
  30.   Reset(f);
  31.   Readln(f, res);
  32.   read_from_file := res;
  33. end;
  34.  
  35. procedure setup_input(port : string);
  36. begin
  37.   write_to_file ('/sys/class/gpio/export', port);
  38.   write_to_file ('/sys/class/gpio/gpio' + port + '/direction', 'in');
  39. end;
  40.  
  41. procedure setup_output(port : string);
  42. begin
  43.   write_to_file ('/sys/class/gpio/export', port);
  44.   write_to_file ('/sys/class/gpio/gpio' + port + '/direction', 'out');
  45. end;
  46.  
  47. procedure port_write(port : string; value : string);
  48. begin
  49.   write_to_file ('/sys/class/gpio/gpio' + port + '/value', value);
  50. end;
  51.  
  52. function port_read(port : string) : string;
  53. begin
  54.   port_read := read_from_file ('/sys/class/gpio/gpio' + port + '/value');
  55. end;
  56.  
  57. procedure release(port : string);
  58. begin
  59.   write_to_file ('/sys/class/gpio/unexport', port);
  60. end;
  61.  
  62.  
  63. begin
  64. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement