Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.82 KB | None | 0 0
  1. from readings import Reading
  2. from motors import Motors
  3. from gpiozero import OutputDevice, Button
  4. from time import sleep
  5. import threading, multiprocessing
  6. from multiprocessing import Value
  7.  
  8. reading = Reading()
  9. motors = Motors()
  10.  
  11. button = Button(24)
  12.  
  13. m1 = Value('d',0)
  14. m2 = Value('d',0)
  15.  
  16.  
  17.  
  18. def constant_button ():
  19.     flag = True
  20.     global button
  21.     while True:
  22.         if button.is_pressed:
  23.             print('CHANGING INDICATORS')
  24.             flag = not flag
  25.             sleep(1)
  26.         while (len(multiprocessing.active_children()) > 0):
  27.             sleep(.01)
  28.         if flag:
  29.             multiprocessing.Process(target=gauge1(m1,m2))
  30.         else:
  31.             multiprocessing.Process(target=gauge2(m1,m2))
  32.            
  33. def gauge1 (m1,m2):
  34.  
  35.     reading = Reading()
  36.     print('GAUGE 1')
  37.     print(f'CPU Usage:  {reading.getCpuUsage()}')
  38.     print(f'CPU Temp:   {reading.getCpuTemp()}')
  39.     print(f'Disk Usage: {reading.getDiskUsage()}')
  40.     print(f'RAM Usage:  {reading.getRamUsage()}')
  41.     #print()
  42.     #print(m1.value)
  43.     #print(m2.value)
  44.     print('----------------------------------')
  45.    
  46.    
  47.    
  48.     ms1 = threading.Thread(target=motors.moveStep1, args=(reading.getCpuUsage() - m1.value,))
  49.     ms2 = threading.Thread(target=motors.moveStep2, args=(reading.getCpuTemp() - m2.value,))
  50.    
  51.     m1.value = reading.getCpuUsage()
  52.     m2.value = reading.getCpuTemp()
  53.    
  54.     ms1.start()
  55.     ms2.start()
  56.    
  57.     ms1.join()
  58.     ms2.join()
  59.     sleep(1)
  60.  
  61. def gauge2 (m1,m2):
  62.     reading = Reading()
  63.     print('GAUGE 2')
  64.     print(f'CPU Usage:  {reading.getCpuUsage()}')
  65.     print(f'CPU Temp:   {reading.getCpuTemp()}')
  66.     print(f'Disk Usage: {reading.getDiskUsage()}')
  67.     print(f'RAM Usage:  {reading.getRamUsage()}')
  68.     #print()
  69.     #print(m1.value)
  70.     #print(m2.value)
  71.     print('----------------------------------')
  72.    
  73.     ms1 = threading.Thread(target=motors.moveStep1, args=(reading.getDiskUsage()+180 - m1.value,))
  74.     ms2 = threading.Thread(target=motors.moveStep2, args=(reading.getRamUsage()+180 - m2.value,))
  75.    
  76.     m1.value = reading.getDiskUsage()+180
  77.     m2.value = reading.getRamUsage()+180
  78.    
  79.     ms1.start()
  80.     ms2.start()
  81.    
  82.     ms1.join()
  83.     ms2.join()
  84.     sleep(1)
  85.  
  86. constant_button()
  87.  
  88.    
  89.    
  90.    
  91.    
  92.            
  93.        
  94. '''bcheck = multiprocessing.Process(target=constant_button)
  95. bcheck.start()'''
  96.  
  97. '''while True:
  98.    if (flag == 1):
  99.        reading = Reading()
  100.        print(f'CPU Usage:  {reading.getCpuUsage()}')
  101.        print(f'CPU Temp:   {reading.getCpuTemp()}')
  102.        print(f'Disk Usage: {reading.getDiskUsage()}')
  103.        print(f'RAM Usage:  {reading.getRamUsage()}')
  104.        print(f'Flag: {flag}')
  105.        print('----------------------------------')
  106.        
  107.        ms1 = threading.Thread(target=motors.moveStep1, args=(reading.getCpuUsage(),))
  108.        ms2 = threading.Thread(target=motors.moveStep2, args=(reading.getCpuTemp(),))
  109.        
  110.        ms1.start()
  111.        ms2.start()
  112.        
  113.        ms1.join()
  114.        ms2.join()
  115.        sleep(1)
  116.        
  117.    else:
  118.        reading = Reading()
  119.        print(f'CPU Usage:  {reading.getCpuUsage()}')
  120.        print(f'CPU Temp:   {reading.getCpuTemp()}')
  121.        print(f'Disk Usage: {reading.getDiskUsage()}')
  122.        print(f'RAM Usage:  {reading.getRamUsage()}')
  123.        print(f'Flag: {flag}')
  124.        print('----------------------------------')
  125.        
  126.        ms1 = threading.Thread(target=motors.moveStep1, args=(reading.getDiskUsage(),))
  127.        ms2 = threading.Thread(target=motors.moveStep2, args=(reading.getRamUsage(),))
  128.        
  129.        ms1.start()
  130.        ms2.start()
  131.        
  132.        ms1.join()
  133.        ms2.join()
  134.        sleep(1)'''
  135.    
  136. '''
  137. make a button to switch from the first two to the last two
  138. make code to make it reset to 0 when we have the switch'''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement