def _get_raw_value(self):
     x = pyupm_mma7660.new_floatp()
     y = pyupm_mma7660.new_floatp()
     z = pyupm_mma7660.new_floatp()
     self.actuator.getAcceleration(x, y, z)
     return (pyupm_mma7660.floatp_value(x),
             pyupm_mma7660.floatp_value(y),
             pyupm_mma7660.floatp_value(z))
 def _get_raw_value(self):
     x = pyupm_mma7660.new_floatp()
     y = pyupm_mma7660.new_floatp()
     z = pyupm_mma7660.new_floatp()
     self.actuator.getAcceleration(x, y, z)
     return (
         pyupm_mma7660.floatp_value(x),
         pyupm_mma7660.floatp_value(y),
         pyupm_mma7660.floatp_value(z)
     )
示例#3
0
文件: mma7660.py 项目: oronum/upm
def main():
    # Instantiate an MMA7660 on I2C bus 0
    myDigitalAccelerometer = upmMMA7660.MMA7660(
        upmMMA7660.MMA7660_I2C_BUS, upmMMA7660.MMA7660_DEFAULT_I2C_ADDR)

    ## Exit handlers ##
    # This function stops python from printing a stacktrace when you hit control-C
    def SIGINTHandler(signum, frame):
        raise SystemExit

    # This function lets you run code on exit, including functions from myDigitalAccelerometer
    def exitHandler():
        print "Exiting"
        sys.exit(0)

    # Register exit handlers
    atexit.register(exitHandler)
    signal.signal(signal.SIGINT, SIGINTHandler)

    # place device in standby mode so we can write registers
    myDigitalAccelerometer.setModeStandby()

    # enable 64 samples per second
    myDigitalAccelerometer.setSampleRate(upmMMA7660.MMA7660.AUTOSLEEP_64)

    # place device into active mode
    myDigitalAccelerometer.setModeActive()

    x = upmMMA7660.new_intp()
    y = upmMMA7660.new_intp()
    z = upmMMA7660.new_intp()

    ax = upmMMA7660.new_floatp()
    ay = upmMMA7660.new_floatp()
    az = upmMMA7660.new_floatp()

    while (1):
        myDigitalAccelerometer.getRawValues(x, y, z)
        outputStr = ("Raw values: x = {0}"
                     " y = {1}"
                     " z = {2}").format(upmMMA7660.intp_value(x),
                                        upmMMA7660.intp_value(y),
                                        upmMMA7660.intp_value(z))
        print outputStr

        myDigitalAccelerometer.getAcceleration(ax, ay, az)
        outputStr = ("Acceleration: x = {0}"
                     "g y = {1}"
                     "g z = {2}g").format(upmMMA7660.floatp_value(ax),
                                          upmMMA7660.floatp_value(ay),
                                          upmMMA7660.floatp_value(az))
        print outputStr
        time.sleep(.5)
def main():

    signal.signal(signal.SIGINT, SIGINTHandler)


# place device in standby mode so we can write registers

    myDigitalAccelerometer.setModeStandby()

 

# enable 64 samples per second

    myDigitalAccelerometer.setSampleRate(upmMMA7660.MMA7660.AUTOSLEEP_64)

 

# place device into active mode

    myDigitalAccelerometer.setModeActive()

 

    x = upmMMA7660.new_intp()

    y = upmMMA7660.new_intp()

    z = upmMMA7660.new_intp()

 

    ax = upmMMA7660.new_floatp()

    ay = upmMMA7660.new_floatp()

    az = upmMMA7660.new_floatp()
    while (1):
        myDigitalAccelerometer.getRawValues(x, y, z)
        #print(x,y,z)
        outputStr = ("Raw values: x = {0}"
                     " y = {1}"
                     " z = {2}").format(upmMMA7660.intp_value(x),
                                        upmMMA7660.intp_value(y),

                                        upmMMA7660.intp_value(z))

        var1 = int(upmMMA7660.intp_value(x))
        var2 = int(upmMMA7660.intp_value(y))
        var3 = int(upmMMA7660.intp_value(z))

        print(output_command(var1, var2, var3))
def turn(request):
	
#    signal.signal(signal.SIGINT, SIGINTHandler)
    myDigitalAccelerometer = upmMMA7660.MMA7660(

                    upmMMA7660.MMA7660_I2C_BUS,

                    upmMMA7660.MMA7660_DEFAULT_I2C_ADDR);

# place device in standby mode so we can write registers
    myDigitalAccelerometer.setModeStandby()

# enable 64 samples per second
    myDigitalAccelerometer.setSampleRate(upmMMA7660.MMA7660.AUTOSLEEP_1)

# place device into active mode
    myDigitalAccelerometer.setModeActive()

    x = upmMMA7660.new_intp()
    y = upmMMA7660.new_intp()
    z = upmMMA7660.new_intp()
 
    ax = upmMMA7660.new_floatp()
    ay = upmMMA7660.new_floatp()
    az = upmMMA7660.new_floatp()
    if (1):
        myDigitalAccelerometer.getRawValues(x, y, z)
        #print(x,y,z)
        outputStr = ("Raw values: x = {0}"
                     " y = {1}"
                     " z = {2}").format(upmMMA7660.intp_value(x),
                                        upmMMA7660.intp_value(y),

                                        upmMMA7660.intp_value(z))

        var1 = int(upmMMA7660.intp_value(x))
        var2 = int(upmMMA7660.intp_value(y))
        var3 = int(upmMMA7660.intp_value(z))

        print(output_command(var1, var2, var3))
 

        #time.sleep(.5)
    	return HttpResponse("New Value Here")
#GPIO_ADDRESS = "/sys/class/gpio/gpio%s" % BUTTON
#DIRECTION_ADDRESS = "%s/direction" % GPIO_ADDRESS
#VALUE_ADDRESS = 	"%s/value" % GPIO_ADDRESS
#EXPORT_ADDRESS = 	"/sys/class/gpio/export"

statusLock = threading.Lock()

temp = grove.GroveTemp(TEMP_PIN)
light = grove.GroveLight(LIGHT_PIN)
# Instantiate an MMA7660 on I2C bus 0
myDigitalAccelerometer = upmMMA7660.MMA7660(
           	upmMMA7660.MMA7660_I2C_BUS,
            upmMMA7660.MMA7660_DEFAULT_I2C_ADDR);

ax = upmMMA7660.new_floatp()
ay = upmMMA7660.new_floatp()
az = upmMMA7660.new_floatp()


#Stationary node Ip pool 10.1.0.1 - 10.1.10.255 (assigned by the base Station)
#stationary node momentary IP pool 10.1.100.1 - 10.1.100.100 (Randomly selected)

#Mobile node Ip pool 10.2.0.1 - 10.2.10.255 (assigned by the base Station)
#Mobile node momentary IP pool 10.2.100.1 - 10.2.100.100 (Randomly selected)

def signal_handler(signal, frame):
        print "\n", "-" * 15, "CTRL + C RECEIVED", "-" * 15
        get_cycle.stop()
        sys.exit(0)
示例#7
0
文件: mma7660.py 项目: whpenner/upm
signal.signal(signal.SIGINT, SIGINTHandler)

# place device in standby mode so we can write registers
myDigitalAccelerometer.setModeStandby()

# enable 64 samples per second
myDigitalAccelerometer.setSampleRate(upmMMA7660.MMA7660.AUTOSLEEP_64)

# place device into active mode
myDigitalAccelerometer.setModeActive()

x = upmMMA7660.new_intp()
y = upmMMA7660.new_intp()
z = upmMMA7660.new_intp()

ax = upmMMA7660.new_floatp()
ay = upmMMA7660.new_floatp()
az = upmMMA7660.new_floatp()

while (1):
    myDigitalAccelerometer.getRawValues(x, y, z)
    outputStr = ("Raw values: x = {0}"
                 " y = {1}"
                 " z = {2}").format(upmMMA7660.intp_value(x),
                                    upmMMA7660.intp_value(y),
                                    upmMMA7660.intp_value(z))
    print outputStr

    myDigitalAccelerometer.getAcceleration(ax, ay, az)
    outputStr = ("Acceleration: x = {0}"
                 "g y = {1}"
示例#8
0
#Create the vibration sensor object using AIO pin 3
vibrationValue = vibrationSensor.LDT0028(3)
try:
    #Create the accelerometer sensor object using I2C 0
    accelerometerValue = accelerometerSensor.MMA7660(
        accelerometerSensor.MMA7660_DEFAULT_I2C_BUS,
        accelerometerSensor.MMA7660_DEFAULT_I2C_ADDR)
    print(accelerometerSensor.MMA7660_DEFAULT_I2C_BUS)
    #Place device in standby
    accelerometerValue.setModeStandby()

    #Place device into active mode
    accelerometerValue.setModeActive()

    ax = accelerometerSensor.new_floatp()
    ay = accelerometerSensor.new_floatp()
    az = accelerometerSensor.new_floatp()
except:
    print("")

#list created to know which sensors the edison have
sensor_type = [
    'light', 'loudness', 'vibration', 'temperature', 'accelerometer', 'weight'
]

#directory used for each sensor
lightDirectory = {'id0': 0, 'sensor0': '', "value0": 0, "unit0": ''}
loudnessDirectory = {'id0': 0, 'sensor0': '', "value0": 0, "unit0": ''}
vibrationDirectory = {'id0': 0, 'sensor0': '', "value0": 0, "unit0": ''}
accelerometerDirectory = {