@@ -45,6 +45,7 @@ def get(self):
4545 """Returns the current state of the LED"""
4646 return self .state
4747
48+ ## Future Functionality
4849##class gpioEdit(tkSimpleDialog.Dialog):
4950## """Dialog to be expanded to support advanced gpio features like
5051## - Pull Up / Pull Down Resistor Config
@@ -79,7 +80,7 @@ class GPIO(Frame):
7980 def __init__ (self ,parent ,pin = 0 ,name = None ,** kw ):
8081 self .pin = pin
8182 if name == None :
82- self .name = "GPIO %s " % (str ( self .pin ) )
83+ self .name = "GPIO %02d " % (self .pin )
8384 Frame .__init__ (self ,parent ,width = 150 ,height = 20 ,relief = SUNKEN ,bd = 1 ,padx = 5 ,pady = 5 )
8485 ##Future capability
8586 ##self.bind('<Double-Button-1>', lambda e, s=self: self._configurePin(e.y))
@@ -95,14 +96,15 @@ def __init__(self,parent,pin=0,name=None,**kw):
9596 self .mode_sel .grid (column = 1 ,row = 0 )
9697 self .set_state .grid (column = 2 ,row = 0 )
9798 self .current_mode = StringVar ()
98- self .lblCurrentMode = Label (self ,textvariable = self .current_mode )
99- self .lblCurrentMode .grid (column = 1 ,row = 1 )
10099 self .led .grid (column = 3 ,row = 0 )
101100
102101 self .set_state .config (state = DISABLED )
103- function = self .updateCurrentFunction ()
102+ function = self .getPinFunctionName ()
104103 if function not in ['Input' ,'Output' ]:
104+ self .mode_sel .delete (0 ,'end' )
105+ self .mode_sel .insert (0 ,function )
105106 self .mode_sel ['state' ] = DISABLED
107+
106108
107109## def _configurePin(self, y):
108110## """Future capability to setup pull up/down"""
@@ -125,9 +127,9 @@ def setMode(self):
125127 self .set_state .config (state = NORMAL )
126128 pi .setup (self .pin ,pi .OUT )
127129 self .updateInput ()
128- self .updateCurrentFunction ()
129130
130- def getPinFunctionName (self ,pin ):
131+ def getPinFunctionName (self ):
132+ pin = self .pin
131133 functions = {pi .IN :'Input' ,
132134 pi .OUT :'Output' ,
133135 pi .I2C :'I2C' ,
@@ -136,15 +138,6 @@ def getPinFunctionName(self,pin):
136138 pi .SERIAL :'Serial' ,
137139 pi .UNKNOWN :'Unknown' }
138140 return functions [pi .gpio_function (pin )]
139-
140-
141-
142- def setName (self ,name = None ):
143- """Sets a new name for the GPIO port
144- setName("Hot Tub")"""
145- if name == None :
146- name = "GPIO " ,str (self .pin )
147- self .Label .config (text = name )
148141
149142## Future Functionality
150143## def setPullUp(self,pullup):
@@ -175,11 +168,6 @@ def updateInput(self):
175168 state = pi .input (self .pin )
176169 self .state = state
177170 self .updateLED ()
178- def updateCurrentFunction (self ):
179- pinFunction = self .getPinFunctionName (self .pin )
180- self .current_mode .set (pinFunction )
181- return pinFunction
182- ##print("GPIO %s is an %s" % (self.pin,pinFunction))
183171
184172
185173class App (Frame ):
@@ -188,35 +176,11 @@ def __init__(self,parent=None, **kw):
188176 self .parent = parent
189177 pi .setmode (pi .BCM )
190178 self .ports = []
191- ############################################################
192- ### UPDATE gpio TO SELECT WHICH GPIO YOU WISH TO CONTROL ###
193- ### Format is (BCM Pin Number, Row, Column) ###
194- ### Row and Column set where each widget should be ###
195- ### positioned in the app. ###
196- ############################################################
197- gpio = ((2 ,0 ,0 ),
198- (3 ,1 ,0 ),
199- (4 ,2 ,0 ),
200- (7 ,3 ,0 ),
201- (8 ,4 ,0 ),
202- (9 ,5 ,0 ),
203- (10 ,6 ,0 ),
204- (11 ,7 ,0 ),
205- (14 ,8 ,0 ),
206- (15 ,0 ,1 ),
207- (17 ,1 ,1 ),
208- (18 ,2 ,1 ),
209- (22 ,3 ,1 ),
210- (23 ,4 ,1 ),
211- (24 ,5 ,1 ),
212- (25 ,6 ,1 ),
213- (27 ,7 ,1 ))
214- num_of_gpio = len (gpio )
215- ####################################################################
216- col = 0
179+ ## Get the RPI Hardware dependant list of GPIO
180+ gpio = self .getRPIVersionGPIO ()
217181 for num ,(p ,r ,c ) in enumerate (gpio ):
218182 self .ports .append (GPIO (self ,pin = p ))
219- self .ports [col - 1 ].grid (row = r ,column = c )
183+ self .ports [- 1 ].grid (row = r ,column = c )
220184 self .update ()
221185
222186 def onClose (self ):
@@ -238,6 +202,66 @@ def update(self):
238202 """Runs every 100ms to update the state of the GPIO inputs"""
239203 self .readStates ()
240204 self ._timer = self .after (100 ,self .update )
205+ def getRPIVersionGPIO (self ):
206+ """Returns the GPIO hardware config for different Pi versions
207+ Currently supports layout 1 and 3"""
208+ gpio = ((2 ,0 ,0 ),
209+ (3 ,1 ,0 ),
210+ (4 ,2 ,0 ),
211+ (7 ,3 ,0 ),
212+ (8 ,4 ,0 ),
213+ (9 ,5 ,0 ),
214+ (10 ,6 ,0 ),
215+ (11 ,7 ,0 ),
216+ (14 ,8 ,0 ),
217+ (15 ,0 ,1 ),
218+ (17 ,1 ,1 ),
219+ (18 ,2 ,1 ),
220+ (22 ,3 ,1 ),
221+ (23 ,4 ,1 ),
222+ (24 ,5 ,1 ),
223+ (25 ,6 ,1 ),
224+ (27 ,7 ,1 ))
225+ gpio3 = ((2 ,0 ,0 ),
226+ (3 ,1 ,0 ),
227+ (4 ,2 ,0 ),
228+ (17 ,3 ,0 ),
229+ (27 ,4 ,0 ),
230+ (22 ,5 ,0 ),
231+ (10 ,6 ,0 ),
232+ (9 ,7 ,0 ),
233+ (11 ,8 ,0 ),
234+ (5 ,9 ,0 ),
235+ (6 ,10 ,0 ),
236+ (13 ,11 ,0 ),
237+ (19 ,12 ,0 ),
238+ (26 ,13 ,0 ),
239+ (14 ,0 ,1 ),
240+ (15 ,1 ,1 ),
241+ (18 ,2 ,1 ),
242+ (23 ,3 ,1 ),
243+ (24 ,4 ,1 ),
244+ (25 ,5 ,1 ),
245+ (8 ,6 ,1 ),
246+ (7 ,7 ,1 ),
247+ (12 ,8 ,1 ),
248+ (16 ,9 ,1 ),
249+ (20 ,10 ,1 ),
250+ (21 ,11 ,1 ))
251+ if pi .RPI_REVISION == 3 :
252+ gpio = gpio3
253+ self .parent .title ('Raspberry Pi GPIO - A+/B+/2B+' )
254+ elif pi .RPI_REVISION == 2 :
255+ #Change this when I know the pins on RPi GPIO Version 2
256+ #gpio = gpio2
257+ self .parent .title ('Raspberry Pi GPIO - A/B Rev2' )
258+ elif pi .RPI_REVISION == 1 :
259+ self .parent .title ('Raspberry Pi GPIO - A/B' )
260+ else :
261+ self .parent .title ('Raspberry Pi GPIO - Unknown Version' )
262+ ##Assume same config as A+/B+/2B+
263+ gpio = gpio3
264+ return gpio
241265
242266
243267def main ():
@@ -247,6 +271,7 @@ def main():
247271 a .grid ()
248272 """When the window is closed, run the onClose function."""
249273 root .protocol ("WM_DELETE_WINDOW" ,a .onClose )
274+ root .resizable (False ,False )
250275 root .mainloop ()
251276
252277
0 commit comments