def initScreen(): try: bootmode = mindsensors_i2c(0xEA>>1) bootmode.readbyte() scrn = mindsensorsUI(deviceName, rotation) scrn.termPrintAt(4, "PiStorms in fw upgrade mode") return scrn except: return mindsensorsUI(deviceName, rotation)
def initScreen(): try: bootmode = mindsensors_i2c(0xEA >> 1) bootmode.readbyte() scrn = mindsensorsUI(deviceName, rotation) scrn.termPrintAt(4, "PiStorms in fw upgrade mode") return scrn except: return mindsensorsUI(deviceName, rotation)
def __init__(self, name="PiStorms", rotation=3, device=Dev_PiStorms): if device == Dev_SensorShield: self.PS_ADDRESS = 0x16 self.PS_TSX = 0x56 self.PS_TSY = 0x58 self.i2c = mindsensors_i2c(self.PS_ADDRESS >> 1) self.disp.begin() self.clearScreen() try: self.touchIgnoreX = self.TS_X() self.touchIgnoreY = self.TS_Y() self.calibrateTouched() except: pass if (rotation > 0 and rotation < 4): self.currentRotation = rotation self.refresh() self.myname = name self.drawDisplay(name, display=False)
def __init__(self,name = "PiStorms", rotation = 3,device = Dev_PiStorms ): if device == Dev_SensorShield : self.PS_ADDRESS = 0x16 self.PS_TSX = 0x56 self.PS_TSY = 0x58 self.i2c = mindsensors_i2c(self.PS_ADDRESS >> 1) self.disp.begin() self.clearScreen() try: self.touchIgnoreX = self.TS_X() self.touchIgnoreY = self.TS_Y() self.calibrateTouched() except: pass if(rotation > 0 and rotation < 4): self.currentRotation = rotation self.refresh() self.myname = name self.drawDisplay(name,display = False)
from mindsensors_i2c import mindsensors_i2c import sys,os,time import ConfigParser config = ConfigParser.RawConfigParser() config.read("/usr/local/mindsensors/conf/msdev.cfg") if "GRX" in config.get('msdev', 'device'): KEY_COUNT = 0xC0 else: KEY_COUNT = 0xDB lckfile = "/tmp/.psm_shutdown.lck" print "starting..." driver = mindsensors_i2c(0x34 >> 1) count = 0 while (True): time.sleep(0.4) try: keypress = driver.readByte(KEY_COUNT) #print keypress if keypress == 253: #print "sudo halt -p" try: os.remove(lckfile) except OSError: pass f = open(lckfile, 'w') f.write("go_pressed") f.close()
rotation = 3 #print os.getcwd() device_number = 1 if ( device_name == "PiStorms"): device_number = 1 elif ( device_name == "SensorShield"): device_number = 2 elif ( device_name == "SRVController"): device_number = 3 else: print "Unknown device in configuration file, exiting..." sys.exit(1) try: bootmode = mindsensors_i2c(0xEA>>1) bootmode.readbyte() #psm = PiStorms("PiStorms",rotation) scrn = mindsensorsUI(host_name, rotation, device=device_number) scrn.termPrintAt(4,"PiStorms in fw upgrade mode") except: scrn = mindsensorsUI(host_name, rotation, device=device_number) #sudo def listPrograms(directory): files = os.listdir(directory) x = 0 returnFiles = list() while(x<len(files)):
# # History: # Date Author Comments # 04/21/17 Seth Tenembaum Initial development. # import os, time from mindsensorsUI import mindsensorsUI from mindsensors_i2c import mindsensors_i2c from PiStormsCom import PiStormsCom from PiStormsCom import PSSensor s = mindsensorsUI() # screen psc = PiStormsCom() i2c = mindsensors_i2c(0x22 >> 1) PSSensor(psc.bankA, 1).activateCustomSensorI2C() s.drawDisplay("ABSIMU Calibration") s.termGotoLine(0) s.termPrintln("Beginning AbsoluteIMU compass") s.termPrintln("calibration program.") s.termPrintln("") s.termPrintln("Connect AbsoluteIMU-ACG") s.termPrintln("to BAS1.") s.termPrintln("") s.termReplaceLastLine("Press GO to begin.") startKeyPressCount = psc.getKeyPressCount()
from mindsensors_i2c import mindsensors_i2c import sys, os, time import configparser config = configparser.RawConfigParser() config.read("/usr/local/mindsensors/conf/msdev.cfg") if "GRX" in config.get('msdev', 'device'): KEY_COUNT = 0xC0 else: KEY_COUNT = 0xDB lckfile = "/tmp/.psm_shutdown.lck" print("starting...") driver = mindsensors_i2c(0x34 >> 1) count = 0 while (True): time.sleep(0.4) try: keypress = driver.readByte(KEY_COUNT) #print keypress if keypress == 253: #print "sudo halt -p" try: os.remove(lckfile) except OSError: pass f = open(lckfile, 'w') f.write("go_pressed") f.close()
class I2C: A = mindsensors_i2c(0x34 >> 1) B = mindsensors_i2c(0x36 >> 1) class __metaclass__(type): def __iter__(self): return iter([self.A, self.B])
class PiStormsCom(): PS_A_ADDRESS = 0x34 PS_B_ADDRESS = 0x36 # Registers PS_Command = 0x41 PS_SetPoint_M1 = 0x42 PS_Speed_M1 = 0x46 PS_Time_M1 = 0x47 PS_CMDB_M1 = 0x48 PS_CMDA_M1 = 0x49 PS_SetPoint_M2 = 0x4A PS_Speed_M2 = 0x4E PS_Time_M2 = 0x4F PS_CMDB_M2 = 0x50 PS_CMDA_M2 = 0x51 PS_Position_M1 = 0x52 PS_Position_M2 = 0x56 PS_Status_M1 = 0x5A PS_Status_M2 = 0x5B PS_Tasks_M1 = 0x5C PS_Tasks_M2 = 0x5D PS_P_Kp = 0x5E PS_P_Ki = 0x60 PS_P_Kd = 0x62 PS_S_Kp = 0x64 PS_S_Ki = 0x66 PS_S_Kd = 0x68 PS_PassCount = 0x6A PS_PassTolerance = 0x6B PS_ChkSum = 0x6C PS_BattV = 0x6E # Sensor 1 PS_S1_Mode = 0x6F # EV3 PS_S1EV_Ready = 0x70 PS_S1EV_SensorID = 0x71 PS_S1EV_Mode = 0x81 PS_S1EV_Length = 0x82 PS_S1EV_Data = 0x83 # LEGO Analog PS_S1AN_Read = 0x70 # LEGO Color PS_S1C_Color = 0x70 PS_S1C_R_cal = 0x71 PS_S1C_G_cal = 0x72 PS_S1C_B_cal = 0x73 PS_S1C_N_cal = 0x74 PS_S1C_R_raw = 0x75 PS_S1C_G_raw = 0x76 PS_S1C_B_raw = 0x77 PS_S1C_N_raw = 0x78 # Sensor 2 PS_S2_Mode = 0xA3 # EV3 PS_S2EV_Ready = 0xA4 PS_S2EV_SensorID = 0xA5 PS_S2EV_Mode = 0xB5 PS_S2EV_Length = 0xB6 PS_S2EV_Data = 0xB7 # LEGO Analog PS_S2AN_Read = 0xA4 # LEGO Color PS_S2C_Color = 0xA4 PS_S2C_R_cal = 0xA5 PS_S2C_G_cal = 0xA6 PS_S2C_B_cal = 0xA7 PS_S2C_N_cal = 0xA8 PS_S2C_R_raw = 0xA9 PS_S2C_G_raw = 0xAA PS_S2C_B_raw = 0xAB PS_S2C_N_raw = 0xAC # LED PS_R = 0xD7 PS_G = 0xD8 PS_B = 0xD9 # Buttons PS_KeyPress = 0xDA PS_Key1Count = 0xDB PS_Key2Count = 0xDC PS_CONTROL_SPEED = 0x01 PS_CONTROL_RAMP = 0x02 PS_CONTROL_RELATIVE = 0x04 PS_CONTROL_TACHO = 0x08 PS_CONTROL_BRK = 0x10 PS_CONTROL_ON = 0x20 PS_CONTROL_TIME = 0x40 PS_CONTROL_GO = 0x80 #Supported I2C commands R = 0x52 S = 0x53 a = 0x61 b = 0x62 c = 0x63 A = 0x41 B = 0x42 C = 0x43 bankA = mindsensors_i2c(PS_A_ADDRESS >> 1) bankB = mindsensors_i2c(PS_B_ADDRESS >> 1) BAM1 = PSMotor(bankA, 1) BAM2 = PSMotor(bankA, 2) BBM1 = PSMotor(bankB, 1) BBM2 = PSMotor(bankB, 2) BAS1 = PSSensor(bankA, 1) BAS2 = PSSensor(bankA, 2) BBS1 = PSSensor(bankB, 1) BBS2 = PSSensor(bankB, 2) def __init__(self): try: self.bankA.readByte(self.PS_BattV) except: print "could not connect to pistorms" else: self.bankA.writeByte(self.PS_Command, self.R) self.bankB.writeByte(self.PS_Command, self.R) def command(self, cmd, bank): if (bank == 1): self.bankA.writeByte(self.PS_COMMAND, cmd) elif (bank == 2): self.bankB.writeByte(self.PS_COMMAND, cmd) def battVoltage(self): return self.bankA.readByte(self.PS_BattV) * .040 ## Read the firmware version of the i2c device def GetFirmwareVersion(self): ver = self.bankA.readString(0x00, 8) return ver ## Read the vendor name of the i2c device def GetVendorName(self): vendor = self.bankA.readString(0x08, 8) return vendor ## Read the i2c device id def GetDeviceId(self): device = self.bankA.readString(0x10, 8) return device def led(self, lednum, red, green, blue): try: if (lednum == 1): array = [red, green, blue] self.bankA.writeArray(self.PS_R, array) if (lednum == 2): array = [red, green, blue] self.bankB.writeArray(self.PS_R, array) except AttributeError: self.led(lednum, red, green, blue) time.sleep(.001) def isKeyPressed(self): return int(0x01 & self.bankA.readByte(self.PS_KeyPress)) def getKeyPressCount(self): return self.bankA.readByte(self.PS_Key1Count) def resetKeyPressCount(self): self.bankA.writeByte(self.PS_Key1Count, 0) def ping(self): self.bankA.readByte(0x00)
#!/usr/bin/env python # # Copyright (c) 2015 mindsensors.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program 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. # # 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 # Oct 2015 Nitin Initial Authoring from mindsensors_i2c import mindsensors_i2c import sys,os,time driver = mindsensors_i2c( 0x34 >> 1) count = 0 while (True): time.sleep(0.4) try : keypress = driver.readByte(0xdB)
#Learn more product option visit us @ http://www.mindsensors.com/ # # History: # Date Author Comments # 04/21/17 Seth Tenembaum Initial development. # import os, time from mindsensorsUI import mindsensorsUI from mindsensors_i2c import mindsensors_i2c from PiStormsCom import PiStormsCom from PiStormsCom import PSSensor s = mindsensorsUI() # screen psc = PiStormsCom() i2c = mindsensors_i2c(0x22 >> 1) PSSensor(psc.bankA, 1).activateCustomSensorI2C() s.drawDisplay("ABSIMU Calibration") s.termGotoLine(0) s.termPrintln("Beginning AbsoluteIMU compass") s.termPrintln("calibration program.") s.termPrintln("") s.termPrintln("Connect AbsoluteIMU-ACG") s.termPrintln("to BAS1.") s.termPrintln("") s.termReplaceLastLine("Press GO to begin.") startKeyPressCount = psc.getKeyPressCount()
# Oct 2015 Michael Initial Authoring # Jun 2017 Seth Simplification import sys from mindsensors_i2c import mindsensors_i2c from PiStorms import PiStorms psm = PiStorms("Explorer") psm.BAS1.activateCustomSensorI2C() psm.BAS2.activateCustomSensorI2C() i2c_all = [] for addr in range(0x00, 0x34, 2) + range(0x38, 0xEF, 2): i2c_all.append(mindsensors_i2c(addr >> 1)) def ping(i2c): return i2c.readByte(0x00) != None while not psm.isKeyPressed(): found = filter(ping, i2c_all) psm.screen.terminalBuffer = [""] * 20 psm.screen.terminalBuffer[0] = "Found {} I2C device{}." \ .format(len(found), "s" if len(found) != 1 else "") psm.screen.terminalBuffer[8] = "Press GO to quit" if len(found) > 1:
# Oct 2015 Michael Initial Authoring # Jun 2017 Seth Simplification import sys from mindsensors_i2c import mindsensors_i2c from PiStorms import PiStorms psm = PiStorms("Explorer") psm.BAS1.activateCustomSensorI2C() psm.BAS2.activateCustomSensorI2C() i2c_all = [] for addr in range(0x00,0x34,2) + range(0x38,0xEF,2): i2c_all.append(mindsensors_i2c(addr>>1)) def ping(i2c): return i2c.readByte(0x00) != None while not psm.isKeyPressed(): found = filter(ping, i2c_all) psm.screen.terminalBuffer = [""]*20 psm.screen.terminalBuffer[0] = "Found {} I2C device{}." \ .format(len(found), "s" if len(found) != 1 else "") psm.screen.terminalBuffer[8] = "Press GO to quit" if len(found) > 1: for i,dev in enumerate(found): psm.screen.terminalBuffer[i+2] = "0x{:02X}: {}" \
# Date Author Comments # July 2015 Henry Initial Authoring from PiStorms import PiStorms # 10/18/15 Deepak UI improvements and messenger integration from PiStorms import PiStorms from mindsensors_i2c import mindsensors_i2c import sys, os, time, json PROGRAM_DIRECTORY = "/home/pi/PiStormsprograms" json_file = '/var/tmp/ps_data.json' rotation = 3 if (os.getenv("PSREVERSE", "0") == "1"): rotation = 3 #print os.getcwd() try: bootmode = mindsensors_i2c(0xEA >> 1) bootmode.readbyte() psm = PiStorms("PiStorms", rotation) psm.screen.termPrintAt(4, "PiStorms in fw upgrade mode") except: psm = PiStorms("PiStorms", rotation) def listPrograms(directory): files = os.listdir(directory) #files = os.listdir("./" + directory) x = 0 while (x < len(files)): if (not files[x].endswith(".py")) or (not files[x][0].isdigit()):
class PiStormsCom(object): PS_SENSOR_TYPE_NONE = 0 PS_SENSOR_TYPE_SWITCH = 1 PS_SENSOR_TYPE_ANALOG = 2 PS_SENSOR_TYPE_LIGHT_REFLECTED = 3 PS_SENSOR_TYPE_LIGHT_AMBIENT = 4 PS_SENSOR_TYPE_SOUND_DB = 5 PS_SENSOR_TYPE_SOUND_DBA = 6 PS_SENSOR_TYPE_LOWSPEED_9V = 7 PS_SENSOR_TYPE_LOWSPEED = 8 PS_SENSOR_TYPE_CUSTOM = 9 PS_SENSOR_TYPE_COLORFULL = 13 PS_SENSOR_TYPE_COLORRED = 14 PS_SENSOR_TYPE_COLORGREEN = 15 PS_SENSOR_TYPE_COLORBLUE = 16 PS_SENSOR_TYPE_COLORNONE = 17 PS_SENSOR_TYPE_EV3_SWITCH = 18 PS_SENSOR_TYPE_EV3 = 19 PS_SENSOR_MODE_EV3_COLOR_REFLECTED = 0 PS_SENSOR_MODE_EV3_COLOR_AMBIENT = 1 PS_SENSOR_MODE_EV3_COLOR_COLOR = 2 PS_SENSOR_MODE_EV3_GYRO_ANGLE = 0 PS_SENSOR_MODE_EV3_GYRO_RATE = 1 PS_SENSOR_MODE_EV3_ULTRASONIC_DIST_CM = 0 PS_SENSOR_MODE_EV3_ULTRASONIC_DIST_IN = 1 PS_SENSOR_MODE_EV3_ULTRASONIC_DETECT = 2 PS_SENSOR_MODE_EV3_IR_PROXIMITY = 0 PS_SENSOR_MODE_EV3_IR_CHANNEL = 1 PS_SENSOR_MODE_EV3_IR_REMOTE = 2 PS_SENSOR_MODE_NXT_LIGHT_REFLECTED = 0 PS_SENSOR_MODE_NXT_LIGHT_AMBIENT = 0 PS_SENSOR_MODE_NXT_COLOR_COLOR = 0 PS_A_ADDRESS = 0x34 PS_B_ADDRESS = 0x36 # Registers PS_Command = 0x41 PS_SetPoint_M1 = 0x42 PS_Speed_M1 = 0x46 PS_Time_M1 = 0x47 PS_CMDB_M1 = 0x48 PS_CMDA_M1 = 0x49 PS_SetPoint_M2 = 0x4A PS_Speed_M2 = 0x4E PS_Time_M2 = 0x4F PS_CMDB_M2 = 0x50 PS_CMDA_M2 = 0x51 PS_Position_M1 = 0x52 PS_Position_M2 = 0x56 PS_Status_M1 = 0x5A PS_Status_M2 = 0x5B PS_Tasks_M1 = 0x5C PS_Tasks_M2 = 0x5D PS_P_Kp = 0x5E PS_P_Ki = 0x60 PS_P_Kd = 0x62 PS_S_Kp = 0x64 PS_S_Ki = 0x66 PS_S_Kd = 0x68 PS_PassCount = 0x6A PS_PassTolerance = 0x6B PS_ChkSum = 0x6C PS_BattV = 0x6E # Sensor 1 PS_S1_Mode = 0x6F # EV3 PS_S1EV_Ready = 0x70 PS_S1EV_SensorID = 0x71 PS_S1EV_Mode = 0x81 PS_S1EV_Length = 0x82 PS_S1EV_Data = 0x83 # LEGO Analog PS_S1AN_Read = 0x70 # LEGO Color PS_S1C_Color = 0x70 PS_S1C_R_cal = 0x71 PS_S1C_G_cal = 0x72 PS_S1C_B_cal = 0x73 PS_S1C_N_cal = 0x74 PS_S1C_R_raw = 0x75 PS_S1C_G_raw = 0x76 PS_S1C_B_raw = 0x77 PS_S1C_N_raw = 0x78 # Sensor 2 PS_S2_Mode = 0xA3 # EV3 PS_S2EV_Ready = 0xA4 PS_S2EV_SensorID = 0xA5 PS_S2EV_Mode = 0xB5 PS_S2EV_Length = 0xB6 PS_S2EV_Data = 0xB7 # LEGO Analog PS_S2AN_Read = 0xA4 # LEGO Color PS_S2C_Color = 0xA4 PS_S2C_R_cal = 0xA5 PS_S2C_G_cal = 0xA6 PS_S2C_B_cal = 0xA7 PS_S2C_N_cal = 0xA8 PS_S2C_R_raw = 0xA9 PS_S2C_G_raw = 0xAA PS_S2C_B_raw = 0xAB PS_S2C_N_raw = 0xAC ## Touchscreen x- and y-axis registers PS_TSX = 0xE3 PS_TSY = 0xE5 # Touchscreen Calibration PS_TS_CALIBRATION_DATA_READY = 0x70 PS_TS_CALIBRATION_DATA = 0x71 # LED PS_R = 0xD7 PS_G = 0xD8 PS_B = 0xD9 # Buttons PS_KeyPress = 0xDA PS_Key1Count = 0xDB PS_Key2Count = 0xDC PS_CONTROL_SPEED = 0x01 PS_CONTROL_RAMP = 0x02 PS_CONTROL_RELATIVE = 0x04 PS_CONTROL_TACHO = 0x08 PS_CONTROL_BRK = 0x10 PS_CONTROL_ON = 0x20 PS_CONTROL_TIME = 0x40 PS_CONTROL_GO = 0x80 # Supported I2C commands R = 0x52 S = 0x53 a = 0x61 b = 0x62 c = 0x63 A = 0x41 B = 0x42 C = 0x43 H = 0x48 E = 0x45 t = 0x74 T = 0x54 w = 0x77 l = 0x6C bankA = mindsensors_i2c(PS_A_ADDRESS >> 1) bankB = mindsensors_i2c(PS_B_ADDRESS >> 1) BAM1 = PSMotor(bankA, 1) BAM2 = PSMotor(bankA, 2) BBM1 = PSMotor(bankB, 1) BBM2 = PSMotor(bankB, 2) BAS1 = PSSensor(bankA, 1) BAS2 = PSSensor(bankA, 2) BBS1 = PSSensor(bankB, 1) BBS2 = PSSensor(bankB, 2) def __init__(self): try: self.bankA.readByte(self.PS_BattV) except: print("Could not connect to PiStorms.") else: self.bankA.writeByte(self.PS_Command, self.R) self.bankB.writeByte(self.PS_Command, self.R) config = configparser.RawConfigParser() config.read("/usr/local/mindsensors/conf/msdev.cfg") if "GRX" in config.get('msdev', 'device'): self.PS_BattV = 0xC1 self.PS_R = 0xB6 self.PS_G = 0xB7 self.PS_B = 0xB8 self.PS_KeyPress = 0xBF self.PS_Key1Count = 0xC0 def Shutdown(self): self.bankA.writeByte(self.PS_Command, self.H) def command(self, cmd, bank): if (bank == 1): self.bankA.writeByte(self.PS_Command, cmd) elif (bank == 2): self.bankB.writeByte(self.PS_Command, cmd) def battVoltage(self): try: return self.bankA.readByte(self.PS_BattV) * 0.04 except: return 0 def GetFirmwareVersion(self): try: return self.bankA.readString(0x00, 8) except: return "ReadErr" def GetVendorName(self): try: return self.bankA.readString(0x08, 8) except: return "ReadErr" def GetDeviceId(self): try: return self.bankA.readString(0x10, 8) except: return "ReadErr" def GetDeviceFeatures(self): try: return self.bankA.readString(0x18, 8) except: return "ReadErr" def led(self, lednum, red, green, blue): array = [red, green, blue] if (lednum == 1): self.bankA.writeArray(self.PS_R, array) if (lednum == 2): self.bankB.writeArray(self.PS_R, array) time.sleep(0.001) def isKeyPressed(self): try: x = self.bankA.readByte(self.PS_KeyPress) return int(0x01 & x) except: return 0 def getKeyPressValue(self): try: x, y = self.getTouchscreenCoordinates() if x > 300 and y > 0: return [8, 16, 24, 40][int((y - 1) / (240 / 4))] else: return 0 except: return 0 def getKeyPressCount(self): try: return (self.bankA.readByte(self.PS_Key1Count)) except: return 0 def resetKeyPressCount(self): try: self.bankA.writeByte(self.PS_Key1Count, 0) except: pass def ping(self): self.bankA.readByte(0x00) def getTouchscreenCoordinates(self): sampleSize = 3 tolerance = 3 x = [0] * sampleSize y = [0] * sampleSize try: for i in range(sampleSize): x[i] = self.bankA.readInteger(self.PS_TSX) y[i] = self.bankA.readInteger(self.PS_TSY) except: print("Failed to read touchscreen") return (0, 0) if (numpy.std(x) < tolerance and numpy.std(y) < tolerance): return (int(numpy.mean(x)), int(numpy.mean(y))) else: return (0, 0)