-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfocuser.py
118 lines (96 loc) · 4.55 KB
/
focuser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
''' Module to handle the motorised focuser via an Arduino
'''
import logging
from tkinter import N, S, E, W, HORIZONTAL, StringVar, Tk
import tkinter.ttk
import tkinter.messagebox
import arduino
log = logging.getLogger(__name__)
class Focuser(object):
''' Class to handle the user interface for interfacing with the focuser
via the arduino.
'''
def __init__(self, frame):
''' Draw the frame and widgets and set up handlers.
'''
self.uno = arduino.Arduino()
self.frame = frame
self.comport = StringVar()
rframe = tkinter.ttk.Frame(self.frame)
rframe.grid(sticky=(N, S, E, W))
sliders = tkinter.ttk.Frame(rframe)
sliders.grid(column=0, row=0, sticky=(N, E, W))
sliders.columnconfigure(1, weight=3)
self.__sliders(sliders)
buttons = tkinter.ttk.Frame(rframe)
buttons.grid(column=0, row=1, sticky=(N, E, W))
buttons.rowconfigure(0, weight=3)
self.__buttons(buttons)
def __sliders(self, sliders):
''' Private function to handle the sliders.
'''
speed_text = tkinter.ttk.Label(sliders, text="Motor Speed ")
speed_text.grid(column=0, row=0)
self.speed_slider = tkinter.ttk.Scale(sliders, orient=HORIZONTAL,
length=500, from_=1.0, to=255.0)
self.speed_slider.grid(column=1, row=0)
self.speed_slider.set(255)
pulse_text = tkinter.ttk.Label(sliders, text="Pulse Time(ms) ")
pulse_text.grid(column=0, row=1)
self.pulse_slider = tkinter.ttk.Scale(sliders, orient=HORIZONTAL,
length=500, from_=1.0, to=1000.0)
self.pulse_slider.grid(column=1, row=1)
self.pulse_slider.set(30)
def __buttons(self, buttons):
''' Private function to handle the buttons.
'''
full_reverse = tkinter.ttk.Button(buttons, text="Motor\nReverse\nFull",
command=self.__full_reverse)
full_reverse.grid(column=0, row=0, padx=5, sticky=(N, S, E, W))
# TODO These may not need to be self.
self.click_hold_reverse = tkinter.ttk.Button(buttons,
text="Motor\nReverse\nClick/Hold",
command=self.__click_reverse)
self.click_hold_reverse.bind("<Button-1>", self.__click_reverse)
self.click_hold_reverse.bind("<ButtonRelease-1>", self.__motor_off)
self.click_hold_reverse.grid(column=1, row=0, padx=5,
sticky=(N, S, E, W))
pulse_reverse = tkinter.ttk.Button(buttons, text="Motor\nReverse\nPulse",
command=self.__pulse_reverse)
pulse_reverse.grid(column=2, row=0, padx=5, sticky=(N, S, E, W))
motor_off = tkinter.ttk.Button(buttons, text="Motor Off",
command=self.__motor_off)
motor_off.grid(column=3, row=0, padx=5, sticky=(N, S, E, W))
pulse = tkinter.ttk.Button(buttons, text="Motor\nForward\nPulse",
command=self.__pulse_forward)
pulse.grid(column=4, row=0, padx=5, sticky=(N, S, E, W))
self.click_hold = tkinter.ttk.Button(buttons, text="Motor\nForward\nClick/Hold",
command=self.__click_forward)
self.click_hold.grid(column=5, row=0, padx=5, sticky=(N, S, E, W))
self.click_hold_reverse.bind("<Button-1>", self.__click_forward)
self.click_hold_reverse.bind("<ButtonRelease-1>", self.__motor_off)
full = tkinter.ttk.Button(buttons, text="Motor\nForward\nFull",
command=self.__full_forward)
full.grid(column=6, row=0, padx=5, sticky=(N, S, E, W))
def __full_reverse(self):
self.uno.send_char("q")
def __click_reverse(self, *args):
self.uno.send_char("w")
def __pulse_reverse(self):
log.debug(self.uno.set_speed(self.speed_slider.get()))
log.debug(self.uno.set_pulse_duration(self.pulse_slider.get()))
log.debug(self.uno.send_char("e"))
def __motor_off(self, *args):
self.uno.send_char("r")
def __pulse_forward(self):
log.debug(self.uno.set_speed(self.speed_slider.get()))
log.debug(self.uno.set_pulse_duration(self.pulse_slider.get()))
log.debug(self.uno.send_char("t"))
def __click_forward(self, *args):
self.uno.send_char("y")
def __full_forward(self):
self.uno.send_char("u")
if __name__ == "__main__":
ROOT = Tk()
Focuser(ROOT)
ROOT.mainloop()