Exemplo n.º 1
0
class Accel:
    def __init__(self):
        self.accel = [0, 0, 0]
        self.calib = [0, 0, 0]
        self.valSub = []
        self.raw = ""
        try:
            with open("/sys/class/misc/FreescaleAccelerometer/enable", "w") as enabler:
                enabler.write("1")
                enabler.flush()
                enabler.close()
        except (OSError, IOError, ValueError, TypeError):
            print "Error: No Accel detected"

        self.mm_accel = MemoryMap("/sys/class/misc/FreescaleAccelerometer/data", "r")

    def calibrate(self, period=0.5):
        self.valSub = self.get()
        sum1 = [0, 0, 0]
        sum2 = [0, 0, 0]
        for num in range(0, len(self.accel)):
            sum1[num] = self.valSub[num]
        sleep(period)
        for num in range(0, len(self.accel)):
            sum2[num] = self.valSub[num]

        for num in range(0, len(self.accel)):
            self.calib[num] = (sum1[num] + sum2[num]) / 2

    def get(self):  # Return accel data in array
        try:
            self.raw = str(self.mm_accel.read_line().replace('\n', ''))
            for a in range(0, 3):
                try:
                    self.accel[a] = (int(self.raw[0:self.raw.index(',')]) if ',' in self.raw else int(self.raw))
                    self.raw = self.raw[self.raw.index(',') + 1:]
                except (IndexError, ValueError, TypeError):
                    break
        except (OSError, IOError, TypeError, ValueError):
            print "Error using accelerometer!"
        finally:
            for num in range(0, len(self.accel)):
                self.accel[num] -= self.calib[num]
            return self.accel  # return like this [x, y, z] in integer formats

    def release(self, pin):
        try:
            self.mm_accel.close()
            with open("/sys/class/misc/FreescaleAccelerometer/enable", "w") as enabler:
                enabler.write("0")
                enabler.flush()
                enabler.close()
        except (ValueError, IndexError, TypeError):
            raise ValueError("Couldn't release Accelerometer" % str(pin))
Exemplo n.º 2
0
class Temp:
    def __init__(self):  # Start temp module on object call
        self.temp = 0000
        self.coms = Command()
        try:
            self.coms.run("rmmod lm75")
        finally:
            pass
        try:
            self.coms.run("modprobe lm75")
        finally:
            pass
        try:
            self.coms.run("sh -c 'echo lm75 0x48 >/sys/class/i2c-dev/i2c-1/device/new_device' 2&>1")
            # easier to run command to black hole using system
        finally:
            pass
        self.mm_temp = MemoryMap("/sys/class/i2c-dev/i2c-1/device/1-0048/temp1_input", "r")

    def get_temp(self, mode="f"):  # Return with mode
        try:
            self.temp = (float(self.mm_temp.read_line().replace(' ', '').replace('\n', ''))) * (
                0.001)  # Turn into celcius
        except (OSError, IndexError, IOError, ValueError):
            print "Snap in sensor is not plugged in!"
        finally:
            return (self.temp * 1.8 + 32) if "f" in mode else self.temp  # Either return into Far or Celc
Exemplo n.º 3
0
    def __init__(self):
        self.temp = 0000
        self.Tempscale = 0000
        self.pressure = 0000
        self.Tempress = 000
        self.coms = Command()

        try:
            self.coms.run("rmmod mpl3115")
        finally:
            pass
        try:
            self.coms.run("modprobe mpl3115")
        finally:
            pass
        base = "/sys/class/i2c-dev/i2c-1/device/1-0060/iio:device0/"
        self.mm_temp = MemoryMap(base + "in_temp_raw", "r")
        self.mm_scale = MemoryMap(base + "in_temp_scale", "r")
        self.mm_pressure = MemoryMap(base + "in_pressure_raw", "r")
        self.mm_pressure_scale = MemoryMap(base + "in_pressure_scale", "r")
Exemplo n.º 4
0
    def __init__(self):
        self.gyro = [0, 0, 0]
        self.calib = [0, 0, 0]
        self.valSub = []
        self.raw = ""
        try:
            with open("/sys/class/misc/FreescaleGyroscope/enable", "w") as enabler:
                enabler.write("1")
                enabler.flush()
                enabler.close()
        except (OSError, IOError, ValueError, TypeError):
            print "Error: No Gyro detected"

        self.mm_gyro = MemoryMap("/sys/class/misc/FreescaleGyroscope/data", "r")
Exemplo n.º 5
0
 def __init__(self):  # Start temp module on object call
     self.temp = 0000
     self.coms = Command()
     try:
         self.coms.run("rmmod lm75")
     finally:
         pass
     try:
         self.coms.run("modprobe lm75")
     finally:
         pass
     try:
         self.coms.run("sh -c 'echo lm75 0x48 >/sys/class/i2c-dev/i2c-1/device/new_device' 2&>1")
         # easier to run command to black hole using system
     finally:
         pass
     self.mm_temp = MemoryMap("/sys/class/i2c-dev/i2c-1/device/1-0048/temp1_input", "r")
Exemplo n.º 6
0
class Led:
    def __init__(self):
        self.led = 0
        self.mm_led = MemoryMap("/sys/class/leds/led0/brightness")

    def set(self, state=0):
        self.mm_led.write_digit(state)

    def on(self):
        self.mm_led.write_digit(1)

    def off(self):
        self.mm_led.write_digit(0)

    def get_state(self):
        return self.mm_led.read_digit()
Exemplo n.º 7
0
class Barometer:
    def __init__(self):
        self.temp = 0000
        self.Tempscale = 0000
        self.pressure = 0000
        self.Tempress = 000
        self.coms = Command()

        try:
            self.coms.run("rmmod mpl3115")
        finally:
            pass
        try:
            self.coms.run("modprobe mpl3115")
        finally:
            pass
        base = "/sys/class/i2c-dev/i2c-1/device/1-0060/iio:device0/"
        self.mm_temp = MemoryMap(base + "in_temp_raw", "r")
        self.mm_scale = MemoryMap(base + "in_temp_scale", "r")
        self.mm_pressure = MemoryMap(base + "in_pressure_raw", "r")
        self.mm_pressure_scale = MemoryMap(base + "in_pressure_scale", "r")

    def get_temp(self, mode="f"):  # Return from Barometer
        try:
            self.temp = (float(self.mm_temp.read_line().replace('\n', '')))
            self.Tempscale = (float(self.mm_scale.read_line().replace('\n', '')))
            self.temp = (self.temp * self.Tempscale)
        except (IndexError, ValueError, IOError, TypeError, OSError):
            print "Barometer is not plugged in!"
        finally:
            return (self.temp * 1.8 + 32) if "f" in mode else self.temp

    def get_pressure(self):  # Return raw data which is (kPA) a form of pressure measurments sea level is about 100
        try:
            self.pressure = (float(self.mm_pressure.read_line().replace('\n', '')))
            self.Tempress = (float(self.mm_pressure_scale.read_line().replace('\n', '')))
        except (IndexError, ValueError, IOError, TypeError, OSError):
            print "Barometer is not plugged in!"
        finally:
            return float(self.pressure * self.Tempress)

    def release(self, pin):
        try:
            self.mm_temp.close()
            self.mm_scale.close()
            self.mm_pressure.close()
            self.mm_pressure_scale.close()
        except (ValueError, IndexError, TypeError):
            raise ValueError("Couldn't release barometer" % str(pin))
Exemplo n.º 8
0
 def __init__(self):
     self.led = 0
     self.mm_led = MemoryMap("/sys/class/leds/led0/brightness")