#!/usr/bin/env python import wx import os import sys import subprocess """ This program only supports One ibutton thermochron at present. It performs any or all of the following as needed. It creates the directory '~/button' and if required creates '~/1-wire' Then it also calls owfs which causes the OWFS fuse file system to be created and mounted if it doesn't already exist Then it finds the unique identifier for your thermochron and creates the file 'button.cfg' adding this identifier as the first line. After this it presents you with the opportunity to set the frequency of sampling and any delay before it starts sampling. Copyright (c) 2010 Norman Elliott. All rights reserved. This program or module is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or version 3 of the License, or (at your option) any later version. It is provided and is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ class MyForm(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY, title='My iButton', pos=(300,200)) # Add a panel so it looks correct on all platforms self.panel = wx.Panel(self, wx.ID_ANY) font = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT) font.SetPointSize(12) bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_OTHER, (16, 16)) titleIco = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp) title = wx.StaticText(self.panel, wx.ID_ANY, 'Time between samples ( 1-255)\n& Delay in minutes - Max 65535\n (45 days 12 hours 15 mins ) ') title.SetFont(font) lblSize = (50, -1) bmp = wx.ArtProvider.GetBitmap(wx.ART_TIP, wx.ART_OTHER, (16, 16)) inputOneIco = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp) labelOne = wx.StaticText(self.panel, wx.ID_ANY, 'Mins between samples') labelOne.SetFont(font) self.inputTxtOne = wx.TextCtrl(self.panel, wx.ID_ANY,'1') inputTwoIco = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp) labelTwo = wx.StaticText(self.panel, wx.ID_ANY, 'Delay') labelTwo.SetFont(font) self.inputTxtTwo = wx.TextCtrl(self.panel, wx.ID_ANY,'0') self.checkBtn = wx.Button(self.panel, wx.ID_ANY, 'Check') self.commitBtn = wx.Button(self.panel, wx.ID_ANY, 'Commit') self.cancelBtn = wx.Button(self.panel, wx.ID_ANY, 'Cancel') self.Bind(wx.EVT_BUTTON, self.onCheck, self.checkBtn) self.Bind(wx.EVT_BUTTON, self.onCommit, self.commitBtn) self.Bind(wx.EVT_BUTTON, self.onCancel, self.cancelBtn) topSizer = wx.BoxSizer(wx.VERTICAL) titleSizer = wx.BoxSizer(wx.HORIZONTAL) gridSizer = wx.GridSizer(rows=4, cols=2, hgap=5, vgap=5) inputOneSizer = wx.BoxSizer(wx.HORIZONTAL) inputTwoSizer = wx.BoxSizer(wx.HORIZONTAL) btnSizer = wx.BoxSizer(wx.HORIZONTAL) titleSizer.Add(title, 0, wx.ALL, 5) inputOneSizer.Add((1,-1), proportion=1) # this is a spacer inputOneSizer.Add(labelOne, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5) #Delay label inputTwoSizer.Add((20,20), 1, wx.EXPAND) # this is a spacer inputTwoSizer.Add(labelTwo, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5) gridSizer.Add(inputOneSizer, 0, wx.ALIGN_RIGHT) #Sample Rate input gridSizer.Add(self.inputTxtOne, 0, wx.EXPAND) gridSizer.Add(inputTwoSizer, 0, wx.ALIGN_RIGHT) # Delay input gridSizer.Add(self.inputTxtTwo, 0, wx.EXPAND) btnSizer.Add(self.checkBtn, 0, wx.ALL, 5) btnSizer.Add(self.commitBtn, 0, wx.ALL, 5) btnSizer.Add(self.cancelBtn, 0, wx.ALL, 5) topSizer.Add(titleSizer, 0, wx.CENTER) topSizer.Add(wx.StaticLine(self.panel), 0, wx.ALL|wx.EXPAND, 5) topSizer.Add(gridSizer, 0, wx.ALL|wx.EXPAND, 5) topSizer.Add(wx.StaticLine(self.panel), 0, wx.ALL|wx.EXPAND, 5) topSizer.Add(btnSizer, 0, wx.ALL|wx.CENTER, 5) topSizer.Add(wx.StaticLine(self.panel), 0, wx.ALL|wx.EXPAND, 5) # SetSizeHints(minW, minH, maxW, maxH) self.SetSizeHints(250,300,500,400) self.panel.SetSizer(topSizer) topSizer.Fit(self) basedir = os.path.expanduser("~") buttondir = basedir + "/button" wiredir = basedir + "/1-wire" try: os.system("clear") except ValueError: print "Houston we have a problem with permissions" try: os.mkdir( buttondir) except OSError, e: if e.errno == 17 and os.path.isdir(buttondir): "" else: raise try: os.mkdir( wiredir) except OSError, e: if e.errno == 17 and os.path.isdir(wiredir): "" else: raise directory = basedir + "/1-wire/alarm" bfind = 0 if os.path.exists(directory): "" else: try: os.system("/opt/owfs/bin/owfs " "--allow_other " "-C " "-u " "-m " "$HOME/1-wire") except ValueError, e: "" buttonconfig = basedir + "/button/mybutton.cfg" if os.path.exists(directory): "" else: message= "Cannot find your iButton.\nIs it plugged in?" msg_box = wx.MessageDialog(self.panel,message,"",wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) msg_box.ShowModal() msg_box.Destroy() quit() bfind=0 directory = basedir + "/1-wire" buttonconfig = basedir + "/button/mybutton.cfg" bf=open(buttonconfig, 'w') for name in os.listdir(directory): if os.path.isdir(os.path.join(directory, name)): if name[0:2] == "21": # print "\n\033[34m> Found ibutton " + name + " <\033[0m\n" bf.write(name) bfind=1 bf.close() if bfind > 0: "" else: message= "Cannot find your iButton.\nIs it plugged in?" dlg = wx.MessageDialog(None, message,"",wx.OK|wx.ICON_EXCLAMATION) dlg.ShowModal() dlg.Destroy() def onCheck(self, event): bfind = 0 mins=self.inputTxtOne.GetValue() startLate=self.inputTxtTwo.GetValue() if mins == "0": mins = -1 imins=int(mins) timemsg = "Sample Time outside acceptable range\n." dlymsg = "\n Delay outside range." if imins>0: if imins <256: bfind += 1 timemsg = "" else: timemsg = "Sample Time outside acceptable range\n. " dly=int(startLate) if dly > -1: if dly<65536: bfind += 1 dlymsg = "" else: dlymsg = "\n Delay outside range" if bfind < 2: fullmsg = timemsg + dlymsg msg_box = wx.MessageDialog(self.panel,fullmsg,"", wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) msg_box.ShowModal() msg_box.Destroy() return() fullMsg= "Values in range, click commit when ready." msg_box = wx.MessageDialog(self.panel,fullMsg,"", wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) msg_box.ShowModal() msg_box.Destroy() def onCancel(self, event): self.closeProgram() def closeProgram(self): self.Close() def onCommit(self, event): bfind = 0 mins=self.inputTxtOne.GetValue() startLate=self.inputTxtTwo.GetValue() if mins == "0": mins = -1 imins=int(mins) timemsg = "Sample Time outside acceptable range.\n" dlymsg = "\n Delay outside range." if imins>0: if imins <256: bfind += 1 timemsg = "" else: timemsg = "Sample Time outside acceptable range.\n " dly=int(startLate) if dly > -1: if dly<65536: bfind += 1 dlymsg = "" else: dlymsg = "Delay outside acceptable range." if bfind < 2: startfullmsg = "Sorry, but these values cannot be used.\n" fullmsg = startfullmsg + timemsg + dlymsg msg_box = wx.MessageDialog(self.panel,fullmsg,"", wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) msg_box.ShowModal() msg_box.Destroy() return() fullMsg= "Values in range, click commit when ready." msg_box = wx.MessageDialog(self.panel,fullMsg,"", wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) msg_box.ShowModal() msg_box.Destroy() mins=self.inputTxtOne.GetValue() startLate=self.inputTxtTwo.GetValue() basedir = os.path.expanduser("~") buttonconfig = basedir + "/button/mybutton.cfg" bf=open(buttonconfig, 'r') myButton = bf.readline() bf.close() mytime = basedir + "/1-wire/" + myButton + "/mission/frequency" newmins = "echo " + mins + " > " + mytime os.system(newmins) mydelay = basedir + "/1-wire/21.B5FB22000000/mission/delay" newdelay = "echo " + startLate + " > " + mydelay os.system(newdelay) msg_box = wx.MessageDialog(self.panel,"Button Programmed","", wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) msg_box.ShowModal() msg_box.Destroy() def closeProgram(self): self.Close() # Run the program if __name__ == '__main__': app = wx.PySimpleApp() frame = MyForm().Show() app.MainLoop()