# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # #mindsensors.com invests time and resources providing this open source code, #please support mindsensors.com by purchasing products from mindsensors.com! #Learn more product option visit us @ http://www.mindsensors.com/ # # History: # Date Author Comments # 04-11-16 Deepak Troubleshooting program import time from PiStorms import PiStorms print "" print "Running program 5 times, press Ctrl-C to terminate" print "" psm = PiStorms() exit = False a = 0 while (a < 5): voltVal = psm.battVoltage() print "PiStorms voltage: " + str(voltVal) time.sleep(2) a = a + 1
homefolder = config.get("msdev", "homefolder") try: with open(os.path.join(homefolder, ".version"), "r") as f: version_no = f.readline().strip() except IOError: version_no = "unknown" psm.screen.drawDisplay("About Me") psm.screen.termPrintln("Device: {}".format(psm.GetDeviceId().rstrip("\0"))) psm.screen.termPrintln("Feature: {}".format( psm.psc.GetDeviceFeatures().rstrip("\0"))) psm.screen.termPrintln("f/w version: {}".format( psm.GetFirmwareVersion().rstrip("\0"))) psm.screen.termPrintln("s/w version: {}".format(version_no)) psm.screen.termPrintln("Hostname: {}".format(socket.gethostname())) psm.screen.termPrintln("Battery: {}V".format(psm.battVoltage())) def getIP(iface): ip = os.popen("ifconfig {} | tail +2 | awk '/inet / {{print $2}}'".format( iface)).read() return ip if ip != '' else "not present" def updateNetworkInfo(): psm.screen.termPrintAt(6, "eth0: {}".format(getIP("eth0"))) psm.screen.termPrintAt(7, "wlan0: {}".format(getIP("wlan0"))) psm.untilKeyPressOrTouch(updateNetworkInfo)
import os,sys,inspect,time,thread currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0,parentdir) from PiStorms import PiStorms psm = PiStorms() psm.screen.termPrintln("Battery Voltage") psm.screen.termPrintln(" ") psm.BBS1.resetTouchesEV3() exit = False lastled = 0 while(not exit): voltVal = psm.battVoltage() psm.screen.termReplaceLastLine(str(voltVal) + "V") if(voltVal >= 8and lastled != 1): psm.led(1,0,255,0) psm.led(2,0,255,0) lastled = 1 if(voltVal < 8 and voltVal > 6 and lastled != 2): psm.led(1,0,255,0) psm.led(2,0,255,0) lastled = 2 if(voltVal <= 6 and lastled != 3): psm.led(1,255,0,0) psm.led(2,255,0,0) lastled = 3 if(psm.screen.isTouched()):
from PiStorms import PiStorms psm = PiStorms() psm.screen.termPrintln("Please wait a moment") psm.screen.termPrintln("as matplotlib loads...") psm.screen.termPrintAt(3, "Press GO to quit.") import matplotlib matplotlib.use("AGG") import matplotlib.pyplot as plt import numpy as np import tempfile plt.figure(figsize=(4, 3), dpi=80) plt.xlabel('time') plt.ylabel('Voltage (V)') plt.title('Battery Voltage') plt.grid(True) data = np.empty(0) # start with a completely empty data array image = tempfile.NamedTemporaryFile() # we will be overwriting this same file while psm.getKeyPressCount() < 1: data = np.append( data, psm.battVoltage()) # add a data point with the current battery voltage plt.plot(data, color="blue") # plot the data on the graph plt.tight_layout() # make sure the entire plot fits on screen plt.savefig(image.name, format="png") # save it psm.screen.fillBmp(0, 0, 320, 240, image.name) # show it on screen
# This program introduces the process of continually updating a graph. from PiStorms import PiStorms psm = PiStorms() psm.screen.termPrintln("Please wait a moment") psm.screen.termPrintln("as matplotlib loads...") psm.screen.termPrintAt(3, "Press GO to quit.") import matplotlib matplotlib.use("AGG") import matplotlib.pyplot as plt import numpy as np import tempfile plt.figure(figsize=(4,3), dpi=80) plt.xlabel('time') plt.ylabel('Voltage (V)') plt.title('Battery Voltage') plt.grid(True) data = np.empty(0) # start with a completely empty data array image = tempfile.NamedTemporaryFile() # we will be overwriting this same file while psm.getKeyPressCount() < 1: data = np.append(data, psm.battVoltage()) # add a data point with the current battery voltage plt.plot(data, color="blue") # plot the data on the graph plt.tight_layout() # make sure the entire plot fits on screen plt.savefig(image.name, format="png") # save it psm.screen.fillBmp(0,0, 320,240, image.name) # show it on screen
import matplotlib.pyplot as plt import numpy as np from scipy.interpolate import spline import tempfile plt.figure(figsize=(4, 3), dpi=80) plt.xlabel('time') plt.ylabel('Voltage (V)') plt.title('Battery Voltage') plt.grid(True) axis = plt.gca() # get current axis data = np.empty(0) # start with a completely empty data array image = tempfile.NamedTemporaryFile() # we will be overwriting this same file data = np.append(data, psm.battVoltage()) data = np.append(data, psm.battVoltage()) while psm.getKeyPressCount() < 1: data = np.append( data, psm.battVoltage()) # add a data point with the current battery voltage smooth_x = np.linspace( 0, len(data) - 1, len(data) * 5) # an array 5 times the length of data for the smoothed data if axis.lines: axis.lines.pop( ) # if there's already a line on the graph (old), remove it lines = plt.plot(smooth_x,
return displayFullFileList(fileList,index + 1) try: newResult = result + (index*4) except TypeError: newResult = result return newResult # # main program loop # try: while(True): result = 0 if(psm.battVoltage()<=6.5): psm.screen.askQuestion(["LOW BATTERY","Your battery is low","Change or charge your batteries"],["Ignore"]) #if(psm.isKeyPressed()): # psm.screen.refresh() files = listPrograms(PROGRAM_DIRECTORY) file_id = displayFullFileList(files) if ( isinstance( file_id, int ) ): result = runProgram(files[file_id],PROGRAM_DIRECTORY) elif ( file_id == "message"): f = open(json_file, 'r') try: data = json.loads(f.read()) m = data['message'].split("\n") s = data['status'] f.close() except:
import ConfigParser from PiStorms import PiStorms psm = PiStorms() config = ConfigParser.RawConfigParser() config.read("/usr/local/mindsensors/conf/msdev.cfg") homefolder = config.get("msdev", "homefolder") try: with open(os.path.join(homefolder, ".version"), "r") as f: version_no = f.readline().strip() except IOError: version_no = "unknown" psm.screen.drawDisplay("About Me") psm.screen.termPrintln("Device: {}".format(psm.GetDeviceId().rstrip("\0"))) psm.screen.termPrintln("Feature: {}".format(psm.psc.GetDeviceFeatures().rstrip("\0"))) psm.screen.termPrintln("f/w version: {}".format(psm.GetFirmwareVersion().rstrip("\0"))) psm.screen.termPrintln("s/w version: {}".format(version_no)) psm.screen.termPrintln("Hostname: {}".format(socket.gethostname())) psm.screen.termPrintln("Battery: {}V".format(psm.battVoltage())) def getIP(iface): ip = os.popen("ifconfig {} | tail +2 | awk '/inet / {{print $2}}'".format(iface)).read() return ip if ip != '' else "not present" def updateNetworkInfo(): psm.screen.termPrintAt(6, "eth0: {}".format(getIP("eth0"))) psm.screen.termPrintAt(7, "wlan0: {}".format(getIP("wlan0"))) psm.untilKeyPressOrTouch(updateNetworkInfo) psm.screen.termPrintAt(8, "Exiting to menu")
try: newResult = result + (index * 4) except TypeError: newResult = result return newResult # # main program loop # try: while (True): result = 0 if (psm.battVoltage() <= 6.5): psm.screen.askQuestion([ "LOW BATTERY", "Your battery is low", "Change or charge your batteries" ], ["Ignore"]) #if(psm.isKeyPressed()): # psm.screen.refresh() files = listPrograms(PROGRAM_DIRECTORY) file_id = displayFullFileList(files) if (isinstance(file_id, int)): result = runProgram(files[file_id], PROGRAM_DIRECTORY) elif (file_id == "message"): f = open(json_file, 'r') try: data = json.loads(f.read()) m = data['message'].split("\n")