Advertisement
Guest User

beaglebone python gpio polling

a guest
Sep 15th, 2012
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.66 KB | None | 0 0
  1. import select, os                                                                                                                                                                                                                      
  2.                                                                                                                                                                                                                                        
  3. PATH = '/sys/class/gpio/gpio47/{0}'                                                                                                                                                                                                    
  4. os.system('echo 27 > /sys/kernel/debug/omap_mux/gpmc_ad15')                                                                                                                                                                            
  5. os.system('echo in > {0}'.format(PATH.format('direction')))                                                                                                                                                                            
  6. os.system('echo rising > {0}'.format(PATH.format('edge')))                                                                                                                                                                            
  7. fd = os.open(PATH.format('value'), os.O_RDONLY | os.O_NONBLOCK)                                                                                                                                                                        
  8. READ_ONLY = select.POLLPRI                                                                                                                                                                                                            
  9. poller = select.poll()                                                                                                                                                                                                                
  10. poller.register(fd, READ_ONLY)                                                                                                                                                                                                        
  11. count = 0                                                                                                                                                                                                                              
  12. while True:                                                                                                                                                                                                                            
  13.     events = poller.poll(-1)                                                                                                                                                                                                          
  14.     os.lseek(fd, 0, 0)                                                                                                                                                                                                                
  15.     if os.read(fd, 2) == '1\n':                                                                                                                                                                                                        
  16.         count += 1                                                                                                                                                                                                                    
  17.     print count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement