Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from readings import Reading
- from motors import Motors
- from gpiozero import OutputDevice, Button
- from time import sleep
- import threading, multiprocessing
- from multiprocessing import Value
- reading = Reading()
- motors = Motors()
- button = Button(24)
- m1 = Value('d',0)
- m2 = Value('d',0)
- def constant_button ():
- flag = True
- global button
- while True:
- if button.is_pressed:
- print('CHANGING INDICATORS')
- flag = not flag
- sleep(1)
- while (len(multiprocessing.active_children()) > 0):
- sleep(.01)
- if flag:
- multiprocessing.Process(target=gauge1(m1,m2))
- else:
- multiprocessing.Process(target=gauge2(m1,m2))
- def gauge1 (m1,m2):
- reading = Reading()
- print('GAUGE 1')
- print(f'CPU Usage: {reading.getCpuUsage()}')
- print(f'CPU Temp: {reading.getCpuTemp()}')
- print(f'Disk Usage: {reading.getDiskUsage()}')
- print(f'RAM Usage: {reading.getRamUsage()}')
- #print()
- #print(m1.value)
- #print(m2.value)
- print('----------------------------------')
- ms1 = threading.Thread(target=motors.moveStep1, args=(reading.getCpuUsage() - m1.value,))
- ms2 = threading.Thread(target=motors.moveStep2, args=(reading.getCpuTemp() - m2.value,))
- m1.value = reading.getCpuUsage()
- m2.value = reading.getCpuTemp()
- ms1.start()
- ms2.start()
- ms1.join()
- ms2.join()
- sleep(1)
- def gauge2 (m1,m2):
- reading = Reading()
- print('GAUGE 2')
- print(f'CPU Usage: {reading.getCpuUsage()}')
- print(f'CPU Temp: {reading.getCpuTemp()}')
- print(f'Disk Usage: {reading.getDiskUsage()}')
- print(f'RAM Usage: {reading.getRamUsage()}')
- #print()
- #print(m1.value)
- #print(m2.value)
- print('----------------------------------')
- ms1 = threading.Thread(target=motors.moveStep1, args=(reading.getDiskUsage()+180 - m1.value,))
- ms2 = threading.Thread(target=motors.moveStep2, args=(reading.getRamUsage()+180 - m2.value,))
- m1.value = reading.getDiskUsage()+180
- m2.value = reading.getRamUsage()+180
- ms1.start()
- ms2.start()
- ms1.join()
- ms2.join()
- sleep(1)
- constant_button()
- '''bcheck = multiprocessing.Process(target=constant_button)
- bcheck.start()'''
- '''while True:
- if (flag == 1):
- reading = Reading()
- print(f'CPU Usage: {reading.getCpuUsage()}')
- print(f'CPU Temp: {reading.getCpuTemp()}')
- print(f'Disk Usage: {reading.getDiskUsage()}')
- print(f'RAM Usage: {reading.getRamUsage()}')
- print(f'Flag: {flag}')
- print('----------------------------------')
- ms1 = threading.Thread(target=motors.moveStep1, args=(reading.getCpuUsage(),))
- ms2 = threading.Thread(target=motors.moveStep2, args=(reading.getCpuTemp(),))
- ms1.start()
- ms2.start()
- ms1.join()
- ms2.join()
- sleep(1)
- else:
- reading = Reading()
- print(f'CPU Usage: {reading.getCpuUsage()}')
- print(f'CPU Temp: {reading.getCpuTemp()}')
- print(f'Disk Usage: {reading.getDiskUsage()}')
- print(f'RAM Usage: {reading.getRamUsage()}')
- print(f'Flag: {flag}')
- print('----------------------------------')
- ms1 = threading.Thread(target=motors.moveStep1, args=(reading.getDiskUsage(),))
- ms2 = threading.Thread(target=motors.moveStep2, args=(reading.getRamUsage(),))
- ms1.start()
- ms2.start()
- ms1.join()
- ms2.join()
- sleep(1)'''
- '''
- make a button to switch from the first two to the last two
- make code to make it reset to 0 when we have the switch'''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement