Exemplo n.º 1
0
def Main():

    # SETUP KILL SIGNALS
    signal.signal(signal.SIGTERM, program_shutdown)
    signal.signal(signal.SIGINT, program_shutdown)

    # HACK FOR CLEANING UP GPIO IN A DOCKER CONTAINER
    UT.unexport_all()

    # CREATE OUR GIF CAMERA
    claptto = Claptto(GPIO, DEVICE, RESO, LOOP_COUNT, DELAY)
    claptto.setup_alsa()
    claptto.setup_gpio(SHUTTER)
    claptto.setup_notifier(SIGNAL, NOTIFY_ON_TIME, NOTIFY_LOOP_COUNT)
    claptto.start()

    dead = False
    try:
        while not dead:
            time.sleep(0.5)

    except ProgramExit, KeyboardInterrupt:
        dead = True
        print("CLEANUP")
        # KILL CLAPTTO OBJECT
        claptto.kill()
Exemplo n.º 2
0
def sig_handler(signal, frame):
    OM.unload("PWM0")
    GPIO.cleanup()
    PWM.cleanup()
    SPWM.cleanup()
    UT.disable_1v8_pin()
    sys.exit(0)
Exemplo n.º 3
0
	def run(self):
		# GPIO.toggle_debug()

		try:
			# reset all
			ioutil.unexport_all()
			# GPIO.cleanup()  -- broken?

			# led
			GPIO.setup(LED, GPIO.OUT)
			GPIO.output(LED, GPIO.LOW)

			# handset
			GPIO.setup(HANDSET, GPIO.IN, pull_up_down=GPIO.PUD_UP, initial=1)
			GPIO.add_event_detect(HANDSET, GPIO.BOTH, self.off_hook)

			# rotary dial
			GPIO.setup(ROT_ENGAGED, GPIO.IN, pull_up_down=GPIO.PUD_UP)
			GPIO.add_event_detect(ROT_ENGAGED, GPIO.BOTH, self.rotary_engaged)
			GPIO.setup(ROT_PULSE, GPIO.IN, pull_up_down=GPIO.PUD_UP)
			GPIO.add_event_detect(ROT_PULSE, GPIO.FALLING, self.count_pulse)
		except Exception as e:
			logging.exception("exception encountered")

		GPIO.output(LED, GPIO.LOW) # signal process has started successfully

		# busy loop
		while True:
			time.sleep(0.02)
Exemplo n.º 4
0
def RestApp(host="0.0.0.0", port=1883, debug=False):
    try:
        app.run(host=host, port=port, debug=debug)
    except KeyboardInterrupt:
        GPIO.cleanup()
        PWM.cleanup()
        SPWM.cleanup()
        UT.disable_1v8_pin()
        sys.exit(0)
Exemplo n.º 5
0
def pwm():

    rospy.init_node('pwm')
    rospy.Subscriber('speeds', Speeds, callback)

    while not rospy.is_shutdown():
        rospy.spin()

    SPWM.cleanup()
    UT.unexport_all()
Exemplo n.º 6
0
def get_default_bus():
    """Return the default bus number based on the device platform.  For a
    Raspberry Pi either bus 0 or 1 (based on the Pi revision) will be returned.
    For a Beaglebone Black the first user accessible bus, 1, will be returned.
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        if Platform.pi_revision() == 1:
            # Revision 1 Pi uses I2C bus 0.
            return 0
        else:
            # Revision 2 Pi uses I2C bus 1.
            return 1
    elif plat == Platform.BEAGLEBONE_BLACK:
        # Beaglebone Black has multiple I2C buses, default to 1 (P9_19 and P9_20).
        return 1
    elif plat == Platform.CHIP:
        # CHIP has 2 user accessible I2C busses, default to 2 (U1425 and U14_26)
        # We want the CHIP to default to 2 as the PocketCHIP header breaks out
        # this interface
        # But, the CHIP Pro defaults to bus 1
        import CHIP_IO.Utilities as UT
        if UT.is_chip_pro():
            return 1
        else:
            return 2
    else:
        raise RuntimeError('Could not determine default I2C bus for platform.')
Exemplo n.º 7
0
    def api_handle_1v8pin(command, voltage=None):
        resp = copy.deepcopy(self.CHIP_INFO)
        resp["connected"] = True

        # If the command is "voltage" we are requesting the current voltage setting
        if command == "voltage":
            resp["message"] = "1.8V Pin Current Voltage: " + str(
                UT.get_1v8_pin_voltage())
        # Disable the 1v8 Pin
        elif command == "disable":
            resp["message"] = "Disabling the 1.8V Pin"
            UT.disable_1v8_pin()
        elif command == "enable":
            # Enable the 1v8 Pin
            voltage = float(voltage)
            if voltage not in [1.8, 2.0, 2.6, 3.3]:
                resp["message"] = "invalid voltage specified"
            else:
                resp["message"] = "Enabling the 1.8V Pin to " + str(voltage)
                UT.set_1v8_pin_voltage(voltage)
        else:
            resp["message"] = "invalid command"

        return jsonify(resp)
Exemplo n.º 8
0
try:
    while 1:
        encoder1_delta = encoder1.get_delta()
        if encoder1_delta != 0:
            pid.SetPoint = (encoder1_delta * .25) + pid.SetPoint

        temp = update_temp(celsius_unit)
        pid.update(temp)
        output = pid.output
        if output >= 0:
            gpio.output(relay_pin, GPIO.HIGH)
            lcd.set_color(1.0, 0.0, 0.0)  # Red
        else:
            gpio.output(relay_pin, GPIO.LOW)
            lcd.set_color(0.0, 0.0, 1.0)  # Blue

        lcd.clear()
        lcd.message('TEMP:{0:0.1f}\x01  \nGOAL:{1:0.1f}\x01'.format(temp, pid.SetPoint))

        # Provide some feedback at the terminal level
        # print("PID OUTOUT IS: " + str(output) +
        #       "and the temperature is: " + str(round(temp, 1)))
except KeyboardInterrupt:
    gpio.output(relay_pin, GPIO.HIGH)
    lcd.clear()
    if plat is 5:
        import CHIP_IO.Utilities as UT
        UT.unexport_all()
    pass
Exemplo n.º 9
0
	def stop(self):
		ioutil.unexport_all()
		logging.debug('IO SHUT DOWN')
Exemplo n.º 10
0
import rotary_encoder

A_PIN = "XIO-P0"
B_PIN = "XIO-P1"

encoder = rotary_encoder.RotaryEncoder.Worker(A_PIN, B_PIN)
encoder.start()


while 1:
    delta = encoder.get_cycles()
    if delta != 0:
        print "rotated %d cycles" % delta

except KeyboardInterrupt:
    import CHIP_IO.Utilities as UT
    UT.unexport_all()
Exemplo n.º 11
0
 def test_invalid_set_1v8_with_outofbounds_value(self):
     assert not UT.set_1v8_pin_voltage(0.5)
     assert not UT.set_1v8_pin_voltage(4.5)
Exemplo n.º 12
0
def setup_module(module):
    if not UT.is_chip_pro():
        OM.load("PWM0")
Exemplo n.º 13
0
def teardown_module(module):
    PWM.cleanup()
    if not UT.is_chip_pro():
        OM.unload("PWM0")
Exemplo n.º 14
0
 def api_unexport_all_pins():
     UT.unexport_all()
     resp = copy.deepcopy(self.CHIP_INFO)
     resp["connected"] = True
     resp["message"] = "Unexporting all the Pins"
     return jsonify(resp)
Exemplo n.º 15
0
def teardown_module(module):
    PWM.cleanup()
    if not UT.is_chip_pro():
        OM.unload("PWM0")
Exemplo n.º 16
0
def setup_module(module):
    if not UT.is_chip_pro():
        OM.load("PWM0")
Exemplo n.º 17
0
 def test_invalid_set_1v8_with_string(self):
     assert not UT.set_1v8_pin_voltage("yaystring")