コード例 #1
0
import socket, fcntl, struct


def get_ip_address(ifname):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(
        fcntl.ioctl(
            s.fileno(),
            0x8915,  # SIOCGIFADDR
            struct.pack('256s', ifname[:15]))[20:24])


from PiStormsCom import PiStormsCom

print("running psm-info.py")
psm_comm = PiStormsCom()

print(" Version :  {0}".format(str(psm_comm.GetFirmwareVersion())[:5]))
print(" Vendor  :  {0}".format(str(psm_comm.GetVendorName())))
print(" Device :   {0}".format(str(psm_comm.GetDeviceId())))
print(" HostName : {0}".format(socket.gethostname()))

try:
    print(" eth0 :    {0} ".format(get_ip_address('eth0')))
except:
    print(" eth0 : not present")
try:
    print(" wlan0 :   {0} ".format(get_ip_address('wlan0')))
except:
    print(" wlan0 : not present")
コード例 #2
0
import socket,fcntl,struct


def get_ip_address(ifname):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(fcntl.ioctl(
        s.fileno(),
        0x8915,  # SIOCGIFADDR
        struct.pack('256s', ifname[:15])
    )[20:24])



from PiStormsCom import PiStormsCom
print "running psm-info.py"
psm_comm = PiStormsCom()

print " Version : "+ str(psm_comm.GetFirmwareVersion() )[:5]
print " Vendor  : "+ str(psm_comm.GetVendorName() )
print " Device : "+ str(psm_comm.GetDeviceId() )
print " HostName :     "   + socket.gethostname()

try:
    print " eth0 :     "   + get_ip_address('eth0')
except:
    print " eth0 : not present"
try:
    print " wlan0 :    "+ get_ip_address('wlan0')
except:
    print " wlan0 : not present"
コード例 #3
0
ファイル: PiStorms.py プロジェクト: modulusx/PiStorms
class PiStorms:

    ## Initialize the PiStorms motor and sensor ports
    #  @param self The object pointer.
    #  @param name The display title that will appear at the top of the LCD touchscreen.
    #  @param rotation The rotation of the LCD touchscreen.
    #  @remark
    #  There is no need to use this function directly. To initialize the PiStorms class in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  @endcode
    def __init__(self, name="PiStorms", rotation=3):

        self.screen = mindsensorsUI(name, rotation)
        self.psc = PiStormsCom()
        self.BAS1 = PiStormsSensor(self.psc.BAS1)
        self.BAS2 = PiStormsSensor(self.psc.BAS2)
        self.BBS1 = PiStormsSensor(self.psc.BBS1)
        self.BBS2 = PiStormsSensor(self.psc.BBS2)

        self.BAM1 = PiStormsMotor(self.psc.BAM1)
        self.BAM2 = PiStormsMotor(self.psc.BAM2)
        self.BBM1 = PiStormsMotor(self.psc.BBM1)
        self.BBM2 = PiStormsMotor(self.psc.BBM2)

    ## Returns the input battery voltage
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  volts = psm.battVoltage()
    #  @endcode
    def battVoltage(self):
        return self.psc.battVoltage()

    ## Returns the PiStorms firmware version
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  fwVersion = psm.GetFirmwareVersion()
    #  @endcode
    def GetFirmwareVersion(self):
        return self.psc.GetFirmwareVersion()

    ## Returns the PiStorms vendor name
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  venName = psm.GetVendorName()
    #  @endcode
    def GetVendorName(self):
        return self.psc.GetVendorName()

    ## Returns the PiStorms device ID
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  devID = psm.GetDeviceId()
    #  @endcode
    def GetDeviceId(self):
        return self.psc.GetDeviceId()

    ## Writes to the specified RGB LED
    #  @param self The object pointer.
    #  @param lednum The number to specify the LED (1 for BankA, 2 for BankB).
    #  @param red The red value to write to the specified LED (0-255).
    #  @param green The green value to write to the specified LED (0-255).
    #  @param blue The blue value to write to the specified LED (0-255).
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  psm.led(1,255,0,0)
    #  @endcode
    def led(self, lednum, red, green, blue):
        return self.psc.led(lednum, red, green, blue)

    ## Check if the GO button is pressed
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  key = psm.isKeyPressed()
    #  @endcode
    def isKeyPressed(self):
        return self.psc.isKeyPressed()

    ## Returns the GO button press count
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  keyCount = psm.getKeyPressCount()
    #  if(keyCount == 5):
    #      # do some task
    #  @endcode
    def getKeyPressCount(self):
        return self.psc.getKeyPressCount()

    ## Resets the GO button press count
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  resetKeyPressCount()
    #  @endcode
    def resetKeyPressCount(self):
        self.psc.resetKeyPressCount()

    ### @cond
    ## Pings the PiStorms for reliable I2C communication
    #  @param self The object pointer.
    def ping(self):
        self.psc.ping()
コード例 #4
0
ファイル: PiStorms.py プロジェクト: tizcodex/PiStorms
class PiStorms:

    ## Initialize the PiStorms motor and sensor ports
    #  @param self The object pointer.
    #  @param name The display title that will appear at the top of the LCD touchscreen.
    #  @param rotation The rotation of the LCD touchscreen.
    #  @remark
    #  There is no need to use this function directly. To initialize the PiStorms class in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  @endcode
    def __init__(self, name="PiStorms", rotation=3):

        ## An instance of mindsensorsUI.mindsensorsUI representing the PiStorms's touchscreen.
        self.screen = mindsensorsUI(name, rotation)
        ## An instance of PiStormsCom.PiStormsCom.
        self.psc = PiStormsCom()
        ## An instance of PiStormsSensor representing Bank A sensor 1.
        self.BAS1 = PiStormsSensor(self.psc.BAS1)
        ## An instance of PiStormsSensor representing Bank A sensor 2.
        self.BAS2 = PiStormsSensor(self.psc.BAS2)
        ## An instance of PiStormsSensor representing Bank B sensor 1.
        self.BBS1 = PiStormsSensor(self.psc.BBS1)
        ## An instance of PiStormsSensor representing Bank B sensor 2.
        self.BBS2 = PiStormsSensor(self.psc.BBS2)

        ## An instance of PiStormsMotor representing Bank A motor 1.
        self.BAM1 = PiStormsMotor(self.psc.BAM1)
        ## An instance of PiStormsMotor representing Bank A motor 2.
        self.BAM2 = PiStormsMotor(self.psc.BAM2)
        ## An instance of PiStormsMotor representing Bank B motor 1.
        self.BBM1 = PiStormsMotor(self.psc.BBM1)
        ## An instance of PiStormsMotor representing Bank B motor 2.
        self.BBM2 = PiStormsMotor(self.psc.BBM2)

        self.psc.resetKeyPressCount()

    def command(self, cmd, bank):
        self.psc.command(cmd, bank)

    ## Shutdown the Raspberry Pi
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  psm.Shutdown()
    #  @endcode
    def Shutdown(self):
        self.psc.Shutdown()

    ## Returns the input battery voltage
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  volts = psm.battVoltage()
    #  if(volts > 6):
    #      # do some task
    #  @endcode
    def battVoltage(self):
        return self.psc.battVoltage()

    ## Returns the PiStorms firmware version
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  fwVersion = psm.GetFirmwareVersion()
    #  print str(fwVersion)
    #  @endcode
    def GetFirmwareVersion(self):
        return self.psc.GetFirmwareVersion()

    ## Returns the PiStorms vendor name
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  venName = psm.GetVendorName()
    #  print str(venName)
    #  @endcode
    def GetVendorName(self):
        return self.psc.GetVendorName()

    ## Returns the PiStorms device ID
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  devID = psm.GetDeviceId()
    #  print str(devID)
    #  @endcode
    def GetDeviceId(self):
        return self.psc.GetDeviceId()

    ## Writes to the specified RGB LED
    #  @param self The object pointer.
    #  @param lednum The number to specify the LED (1 for BankA, 2 for BankB).
    #  @param red The red value to write to the specified LED (0-255).
    #  @param green The green value to write to the specified LED (0-255).
    #  @param blue The blue value to write to the specified LED (0-255).
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  psm.led(1,255,0,0)
    #  @endcode
    def led(self, lednum, red, green, blue):
        return self.psc.led(lednum, red, green, blue)

    ## Check if the GO button is pressed
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  key = psm.isKeyPressed()
    #  if(key == True):
    #      # do some task
    #  @endcode
    def isKeyPressed(self):
        return self.psc.isKeyPressed()

    ## Wait until the GO button is pressed
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  psm.screen.termPrintln("Press GO to continue...")
    #  psm.waitForKeyPress()
    #  @endcode
    def waitForKeyPress(self):
        self.untilKeyPress(functools.partial(time.sleep, 0.01))

    ## Repeat an action until the GO button is pressed
    #  @param self The object pointer.
    #  @param func The function to be called repeatedly
    #  @param args Positional arguments to be passed to func
    #  @param kwargs Keyword arguments to be passed to func
    #  @warning Beware of scope issues! In Python, functions introduce a new scope.
    #  You might have to use the keyword "global" to achieve your intended behavior.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #
    #  def mainLoop():
    #      psm.screen.termPrintln(psm.battVoltage())
    #
    #  psm.untilKeyPress(mainLoop)
    #  @endcode
    def untilKeyPress(self, func, *args, **kwargs):
        initialKeyPressCount = self.getKeyPressCount()
        while self.getKeyPressCount() == initialKeyPressCount:
            func(*args, **kwargs)

    ## Repeat an action until the GO button is pressed
    #  or the screen is touched
    #  @param self The object pointer.
    #  @param func The function to be called repeatedly
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #
    #  def mainLoop():
    #      psm.screen.termPrintln(psm.battVoltage())
    #
    #  psm.untilKeyPressOrTouch(mainLoop)
    #  @endcode
    def untilKeyPressOrTouch(self, func, *args, **kwargs):
        initialKeyPressCount = self.getKeyPressCount()
        while self.getKeyPressCount(
        ) == initialKeyPressCount and not self.screen.isTouched():
            func(*args, **kwargs)

    ## Repeat an action until the touchscreen is touched
    #  @param self The object pointer.
    #  @param func The function to be called repeatedly
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #
    #  def mainLoop():
    #      psm.screen.termPrintln(psm.battVoltage())
    #
    #  psm.untilTouch(mainLoop)
    #  @endcode
    def untilTouch(self, func, *args, **kwargs):
        while not self.screen.isTouched():
            func(*args, **kwargs)

    ## Check if any Function button is pressed
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  key = psm.getKeyValue()
    #  if(key == 40):
    #      # (40 is F4), do some task
    #  @endcode
    def getKeyPressValue(self):
        return self.psc.getKeyPressValue()

    ## Check if F1 Function button is pressed
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  key = psm.isF1Pressed()
    #  if(key == True):
    #      # F1 is pressed, do some task
    #  @endcode
    def isF1Pressed(self):
        return (self.psc.getKeyPressValue() == 8)

    ## Check if F2 Function button is pressed
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  key = psm.isF2Pressed()
    #  if(key == True):
    #      # F2 is pressed, do some task
    #  @endcode
    def isF2Pressed(self):
        return (self.psc.getKeyPressValue() == 16)

    ## Check if F3 Function button is pressed
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  key = psm.isF3Pressed()
    #  if(key == True):
    #      # F3 is pressed, do some task
    #  @endcode
    def isF3Pressed(self):
        return (self.psc.getKeyPressValue() == 24)

    ## Check if F4 Function button is pressed
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  key = psm.isF4Pressed()
    #  if(key == True):
    #      # F4 is pressed, do some task
    #  @endcode
    def isF4Pressed(self):
        return (self.psc.getKeyPressValue() == 40)

    ## Returns the GO button press count
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  keyCount = psm.getKeyPressCount()
    #  if(keyCount == 5):
    #      # do some task
    #  @endcode
    def getKeyPressCount(self):
        return self.psc.getKeyPressCount()

    ## Resets the GO button press count
    #  @param self The object pointer.
    #  @remark
    #  To use this function in your program:
    #  @code
    #  from PiStorms import PiStorms
    #  ...
    #  psm = PiStorms()
    #  resetKeyPressCount()
    #  @endcode
    def resetKeyPressCount(self):
        self.psc.resetKeyPressCount()

    ### @cond
    ## Pings the PiStorms for reliable I2C communication
    #  @param self The object pointer.
    def ping(self):
        self.psc.ping()