device.hide() def display_icon(code,i):
 global device
 font = make_font("fontawesome-webfont.ttf", device.height - 10)
 with canvas(device) as draw:
     w, h = draw.textsize(text=code, font=font)
     left = (device.width - w) / 2
     top = (device.height - h) / 2
     draw.text((left, top), text=code, font=font, fill="white")
     s = str(i) + ":"
     print(s)
     updateDisplay() def dispay_message( speed=1,msg='Hello World'):
 global device
 device.show()
 font_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'fonts', 'Volter__28Goldfish_29.ttf'))
 font = ImageFont.truetype(font_path,35)
 with canvas(device) as draw:
     draw.text((0, 20), msg, font=font, fill="white")
     updateDisplay() def main(num_iterations=sys.maxsize):
 global device
 port = 1
 bus = smbus.SMBus(port)
 apds = APDS9960(bus)
 GPIO.setmode(GPIO.BOARD)
 GPIO.setup(7, GPIO.IN)
 #GPIO.add_event_detect(7, GPIO.FALLING, callback = intH)
 apds.setProximityIntLowThreshold(50)
 print("Gesture Test")
 print("============")
 apds.enableGestureSensor()
 device = get_device()
 regulator = framerate_regulator(fps=1)
 button = Button(21)
 button.when_pressed = Showtime
 #draw.text((0, 0), "Hello World", font=font, fill=255)
 dispay_message(6,'Start')
 t = threading.Thread(target=displaytimeout)
 t.start()
 i = 0
 #for code in infinite_shuffle(codes):
 while True:
     with regulator:
         num_iterations -= 1
         if num_iterations == 0:
             break
         if apds.isGestureAvailable():
             motion = apds.readGesture()
             if motion == APDS9960_DIR_LEFT:
                 i = i+1
             if motion == APDS9960_DIR_RIGHT:
                 i = i-1
             if i < 0:
                 i = 6
             if i > 5:
                 i = 0
             code = menuicons[i]
             display_icon(code, i) if __name__ == "__main__":
 try:
     main()
 except KeyboardInterrupt:
     pass
Пример #2
0
def main(num_iterations=sys.maxsize):
    global device
    port = 1
    bus = smbus.SMBus(port)
    apds = APDS9960(bus)
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(7, GPIO.IN)
    #GPIO.add_event_detect(7, GPIO.FALLING, callback = intH)
    apds.setProximityIntLowThreshold(50)
    print("Gesture Test")
    print("============")
    apds.enableGestureSensor()
    device = get_device()
    regulator = framerate_regulator(fps=1)
    font_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'fonts', 'Volter__28Goldfish_29.ttf'))
    font = ImageFont.truetype(font_path,35)
    #draw.text((0, 0), "Hello World", font=font, fill=255)
    dispay_message(font,6,'Start')
    t = threading.Thread(target=displaytimeout)
    t.start()
    i = 100
    #for code in infinite_shuffle(codes):
    while True:
        with regulator:
            num_iterations -= 1
            if num_iterations == 0:
                break
            if apds.isGestureAvailable():
                motion = apds.readGesture()
                if motion == APDS9960_DIR_LEFT:
                    i = i+1
                if motion == APDS9960_DIR_RIGHT:
                    i = i-1
                code = codes[i]
                display_icon(code, i)
Пример #3
0
def main():
	global device
	device = get_device()
	GPIO.setmode(GPIO.BOARD)
	GPIO.setup(7, GPIO.IN)
	
	port = 1
	bus = smbus.SMBus(port)

	apds = APDS9960(bus)	
	GPIO.add_event_detect(7, GPIO.FALLING, callback = intH)
	apds.setProximityIntLowThreshold(50)
	apds.enableGestureSensor()
	#with canvas(device) as draw:
	font_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'fonts', 'Volter__28Goldfish_29.ttf'))
	font = ImageFont.truetype(font_path,35)
	#draw.text((0, 0), "Hello World", font=font, fill=255)
	dispay_message(font,6,'Start')
	while True:
		time.sleep(0.5)
		if apds.isGestureAvailable():
			motion = apds.readGesture()
			diris = dirs.get(motion, "unknown")
			dispay_message(font,6,diris)
            
	time.sleep(1)
Пример #4
0
    def run(self):

        port = 1
        bus = smbus.SMBus(port)
        apds = APDS9960(bus)

        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(self.pin, GPIO.IN)

        try:
            # Interrupt-Event hinzufuegen, steigende Flanke
            GPIO.add_event_detect(self.pin, GPIO.FALLING, callback=intH)

            apds.setProximityIntLowThreshold(150)

            print("Gesture Test")
            print("============")
            apds.enableGestureSensor()
            while True:
                time.sleep(0.5)
                if apds.isGestureAvailable():
                    motion = apds.readGesture()
                    self.motion = motion
                    self.publish("motion", self.dirs.get(motion, "unknown"))
                    print("Gesture={}".format(self.dirs.get(motion,
                                                            "unknown")))
        finally:
            GPIO.cleanup()
Пример #5
0
class gestClass:
    def __init__(self, **kwargs):
        print("Gesture Sensor is GO!!")

    port = 1
    bus = smbus.SMBus(port)
    apds = APDS9960(bus)

    def intH(channel):
        #print("INTERRUPT")          # removed
        pass  # do nothing

    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(7, GPIO.IN)

    def get_gesture(self):
        exitCnt = 0
        exitKey = 'n'

        try:
            dirs = {
                APDS9960_DIR_NONE: "none",
                APDS9960_DIR_LEFT: "left",
                APDS9960_DIR_RIGHT: "right",
                APDS9960_DIR_UP: "up",
                APDS9960_DIR_DOWN: "down",
                APDS9960_DIR_NEAR: "near",
                APDS9960_DIR_FAR: "far",
            }
            try:
                # Interrupt-Event [add rising edge??]
                GPIO.add_event_detect(7, GPIO.FALLING, callback=self.intH)
                self.apds.setProximityIntLowThreshold(50)

                print("CAPTURE GESTURES:")
                print("=================")
                self.apds.enableGestureSensor()
                while True:
                    sleep(0.5)
                    if self.apds.isGestureAvailable():
                        motion = self.apds.readGesture()
                        print("Gesture = {}".format(dirs.get(
                            motion, "unknown")))
                        if exitCnt == 5:
                            print("Exit gesture Counting: y/n")
                            exitKey = raw_input()  # get exit code
                            exitCnt = 0  # clear counter
                        exitCnt += 1
                    if exitKey == 'y':
                        break
            finally:
                GPIO.cleanup()
                print("Exit gesture class!")

        # Any Main Errors saved to log.txt file:
        except Exception:
            log = open("log.txt", 'w')
            traceback.print_exc(file=log)
            print("main gesture error")
Пример #6
0
 def __init__(self):
     self.onGesture = None
     try:
         port = 1
         bus = smbus.SMBus(port)
         self.apds = APDS9960(bus)
     except Exception as e:
         print(e)
Пример #7
0
 def init_apds9960(self):
     port = 1
     bus = smbus.SMBus(port)
     apds = APDS9960(bus)
     GPIO.setup(4, GPIO.IN)
     GPIO.add_event_detect(4, GPIO.FALLING, callback=self._gesture_handler)
     apds.enableGestureSensor()
     return apds
Пример #8
0
    def plugin_init(self, enableplugin=None):
        initok = False
        self.readinprogress = False
        if self.enabled:
            if self.taskdevicepin[0] >= 0:
                try:
                    gpios.HWPorts.add_event_detect(self.taskdevicepin[0],
                                                   gpios.FALLING,
                                                   self.p064_handler, 200)
                    self.timer100ms = False
                except Exception as e:
                    if str(self.taskdevicepluginconfig[0]) == "0":
                        self.timer100ms = True
                    misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,
                                "Interrupt error " + str(e))
            else:
                if str(self.taskdevicepluginconfig[0]) == "0":
                    self.timer100ms = True

            try:
                try:
                    i2cl = self.i2c
                except:
                    i2cl = -1
                i2cbus = gpios.HWPorts.i2c_init(i2cl)
                if i2cl == -1:
                    i2cbus = gpios.HWPorts.i2cbus
                if i2cbus is not None:
                    if self.interval > 2:
                        nextr = self.interval - 2
                    else:
                        nextr = self.interval
                    self.apds = APDS9960(i2cbus)
                    self._lastdataservetime = rpieTime.millis() - (nextr *
                                                                   1000)
                    self.lastread = 0
                    initok = True
                else:
                    self.initialized = False
                    misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,
                                "I2C can not be initialized!")
            except Exception as e:
                self.initialized = False
                misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,
                            "APDS init error " + str(e))
        if initok:
            try:
                self.apds.setProximityIntLowThreshold(50)
                if str(self.taskdevicepluginconfig[0]) == "1":
                    self.apds.enableProximitySensor()
                    self.apds.enableLightSensor()
                else:
                    self.apds.enableGestureSensor()
            except Exception as e:
                misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,
                            "APDS setup error " + str(e))
            plugin.PluginProto.plugin_init(self, enableplugin)
        self.initialized = initok
 def __init__(self):
     self._bus = smbus.SMBus(self.port)
     GPIO.setmode(GPIO.BOARD)
     GPIO.setup(7, GPIO.IN)
     self._apds = APDS9960(self._bus)
     self._apds.enableLightSensor()
     self._apds.enableProximitySensor()
     self._apds.setAmbientLightGain(APDS9960_AGAIN_64X)
     self._apds.setLEDBoost(APDS9960_LED_BOOST_300)
Пример #10
0
 def __init__(self,
              screenWidth=None,
              screenHeight=None,
              backgroundColour="black"):
     self.ScreenWidth = screenWidth  #int
     self.ScreenHeight = screenHeight  #int
     self.BackgroundColour = backgroundColour  #string
     self.root = Tk()
     root = self.root
     if self.ScreenWidth == None:
         self.ScreenWidth = root.winfo_screenwidth()
     if self.ScreenHeight == None:
         self.ScreenHeight = root.winfo_screenheight()
     root.geometry(str(self.ScreenWidth) + "x" + str(self.ScreenHeight))
     root.resizable(width=FALSE, height=FALSE)
     root.config(bg=self.BackgroundColour)  #Set background
     root.config(cursor="none")  #Remove cursor
     root.bind("<Escape>",
               self.Shutdown)  #binds ESC key to shut down mirror
     root.wm_attributes("-fullscreen", "true")  #remove title bar
     self.__Populate()
     if DEBUGFROMWINDOWS == False:
         port = 1
         bus = smbus.SMBus(port)
         self.apds = APDS9960(bus)
         GPIO.setmode(GPIO.BOARD)
         GPIO.setup(7, GPIO.IN)
         self.dirs = {
             APDS9960_DIR_NONE: "none",
             APDS9960_DIR_LEFT: "left",
             APDS9960_DIR_RIGHT: "right",
             APDS9960_DIR_UP: "up",
             APDS9960_DIR_DOWN: "down",
             APDS9960_DIR_NEAR: "near",
             APDS9960_DIR_FAR: "far"
         }
         try:
             # Interrupt-Event hinzufuegen, steigende Flanke
             GPIO.add_event_detect(7, GPIO.FALLING, callback=self.__intH)
             self.apds.setProximityIntLowThreshold(50)
             print("Gesture Test")
             print("============")
             self.apds.enableGestureSensor()
         finally:
             pass
     self.__ThreadList.append(
         threading.Thread(target=self.__Sense, daemon=True))
     self.__ThreadList.append(
         threading.Thread(target=self.__Update, daemon=True))
     self.__ThreadList.append(
         threading.Thread(target=self.__UpdateSpecial, daemon=True))
     for i in self.__ThreadList:
         i.start()
     if DEBUGFROMWINDOWS == True: root.bind("<Return>", self.__DebugTestGUI)
     root.mainloop()
Пример #11
0
    def __init__(self):
        self.port = 1
        self.bus = smbus.SMBus(self.port)
        self.apds = APDS9960(self.bus)
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(7, GPIO.IN)

        self.config = ConfigParser.ConfigParser()
        self.config.read(
            os.path.dirname(os.path.abspath(__file__)) + '/../conf/app.cfg')
        self.config.sections()
Пример #12
0
def get_dist(sensor):
    set_i2c_channel(sensor)

    if last_mode[sensor] != 'proximity':
        local_apds = APDS9960(i2c_bus)
        local_apds.enableProximitySensor()
        local_apds.setProximityGain(0)
        local_apds.setLEDDrive(0 if sensor.startswith('front') else 3)
        last_mode[sensor] = 'proximity'
        time.sleep(0.01)

    return apds.readProximity()
Пример #13
0
 def __init__(self):
     bus = smbus.SMBus(1)
     self.apds = APDS9960(bus)
     self.apds.setProximityIntLowThreshold(50)
     self.apds.enableLightSensor()
     self.apds.enableGestureSensor()
     self.event = Events(
         ('on_change', 'on_light_up', 'on_light_down', 'on_near', 'on_far'))
     maxInt = sys.maxsize
     minInt = -maxInt - 1
     self.light_up = maxInt
     self.light_down = minInt
     self.far = maxInt
     self.near = minInt
Пример #14
0
 def __init__(self, collection: DataCollection):
     self.collection = collection
     self.logger = logging.getLogger(__name__)
     self.bus = smbus2.SMBus(self.PORT)
     calibrated = False
     while not calibrated:
         try:
             bme280.load_calibration_params(self.bus, self.ADDRESS)
             calibrated = True
         except Exception as e:
             self.logger.error('Failed to calibrate bme280: %s', str(e))
             time.sleep(5)
     self.apds = APDS9960(self.bus)
     self.apds.enableLightSensor()
Пример #15
0
def get_color(sensor):
    set_i2c_channel(sensor)

    if last_mode[sensor] != 'color':
        local_apds = APDS9960(i2c_bus)
        local_apds.enableLightSensor()
        time.sleep(0.110)  # default ATIME is 103ms
        last_mode[sensor] = 'color'

    red = apds.readRedLight()
    green = apds.readGreenLight()
    blue = apds.readBlueLight()
    ambient = apds.readAmbientLight()

    return (red, green, blue, ambient)
Пример #16
0
    def __init__(self, *args, **kwargs):
        super(PiClock, self).__init__(*args, **kwargs)

        # Instantiate an API caller object, then use it to seed initial data
        self.caller = ApiCaller()
        self.clockVars = {}
        self.tempHistory = [None] * 24
        self.getData()
        self.updateClockVars = True

        # Setup proximity sensor, if flag enabled
        if self.proxSensorEnabled == True:
            port = 1
            bus = smbus.SMBus(port)
            self.apds = APDS9960(bus)
            GPIO.setmode(GPIO.BOARD)
            GPIO.setup(7, GPIO.IN)
            GPIO.add_event_detect(7, GPIO.FALLING)
def main(num_iterations=sys.maxsize):
    global device

    port = 1
    bus = smbus.SMBus(port)
    apds = APDS9960(bus)
    #GPIO.setmode(GPIO.BOARD)
    #GPIO.setup(7, GPIO.IN)
    #GPIO.add_event_detect(7, GPIO.FALLING, callback = intH)
    apds.setProximityIntLowThreshold(50)
    print("Gesture Test")
    print("============")
    apds.enableGestureSensor()
    device = get_device()
    regulator = framerate_regulator(fps=1)
    button = Button(21)
    button.when_pressed = Showtime
    #draw.text((0, 0), "Hello World", font=font, fill=255)
    dispay_message(6,'Start')
    t = threading.Thread(target=displaytimeout)
    t.start()
    t1 = threading.Thread(target=BluetoothNoti)
    t1.start()
    i = 0
    #for code in infinite_shuffle(codes):
    while True:
        with regulator:
            num_iterations -= 1
            if num_iterations == 0:
                break
            if apds.isGestureAvailable():
                motion = apds.readGesture()
                if motion == APDS9960_DIR_LEFT:
                    i = i+1
                if motion == APDS9960_DIR_RIGHT:
                    i = i-1
                if i < 0:
                    i = 5
                if i > 5:
                    i = 0
                code = menuicons[i]
                display_icon(code, i)
Пример #18
0
def main(num_iterations=sys.maxsize):
	port = 1
	bus = smbus.SMBus(port)

	apds = APDS9960(bus)
	GPIO.setmode(GPIO.BOARD)
	GPIO.setup(7, GPIO.IN)


	#GPIO.add_event_detect(7, GPIO.FALLING, callback = intH)

	apds.setProximityIntLowThreshold(50)
	print("Gesture Test")
	print("============")
	apds.enableGestureSensor()
	device = get_device()
	regulator = framerate_regulator(fps=1)
	font = make_font("fontawesome-webfont.ttf", device.height - 10)
	i = 100
	#for code in infinite_shuffle(codes):
	while True:
		with regulator:
			num_iterations -= 1
			if num_iterations == 0:
				break
			if apds.isGestureAvailable():
				motion = apds.readGesture()
				if motion == APDS9960_DIR_LEFT:
					i = i+1
				if motion == APDS9960_DIR_RIGHT:
					i = i-1
				code = codes[i]
				with canvas(device) as draw:
					w, h = draw.textsize(text=code, font=font)
					left = (device.width - w) / 2
					top = (device.height - h) / 2
					draw.text((left, top), text=code, font=font, fill="white")
					s = str(i) + ":"
					print(s)
Пример #19
0
GPIO.setmode(GPIO.BCM)     # set up BCM GPIO numbering  
GPIO.setup(23, GPIO.OUT)    # set GPIO25 as FAN
GPIO.setup(24, GPIO.OUT)   # set GPIO24 as RELAY

GPIO.setup(14, GPIO.OUT)    # red led
GPIO.setup(15, GPIO.OUT)   # green led
GPIO.setup(18, GPIO.OUT)    # blue led


port = 1
address = 0x77 # Adafruit BME280 address. Other BME280s may be different
bus = smbus2.SMBus(port)

#light stuff
bus2 = smbus.SMBus(port)
apds = APDS9960(bus2)
port = 1
address = 0x77 # Adafruit BME280 address. Other BME280s may be different
bus = smbus2.SMBus(port)


#light stuff
bus2 = smbus.SMBus(port)
apds = APDS9960(bus2)

apds.enableLightSensor()

def flashRedLED():
    GPIO.output(14, 1)
    sleep(0.5)
    GPIO.output(14, 0)
Пример #20
0

def set_i2c_channel(channel):
    if channel not in i2c_channels.keys():
        raise ValueError('channel should be one of {}'.format(
            list(i2c_channels.keys())))

    # 0x04 is the register for switching channels
    # See http://www.ti.com/lit/ds/symlink/tca9548a.pdf
    i2c_bus.write_byte_data(mux_address, 0x04, i2c_channels[channel])


mux_address = 0x70
i2c_bus = smbus.SMBus(1)
set_i2c_channel(list(i2c_channels.keys())[0])
apds = APDS9960(i2c_bus)
last_mode = {channel: None for channel in i2c_channels.keys()}


def get_color(sensor):
    set_i2c_channel(sensor)

    if last_mode[sensor] != 'color':
        local_apds = APDS9960(i2c_bus)
        local_apds.enableLightSensor()
        time.sleep(0.110)  # default ATIME is 103ms
        last_mode[sensor] = 'color'

    red = apds.readRedLight()
    green = apds.readGreenLight()
    blue = apds.readBlueLight()
Пример #21
0
from apds9960.const import *
from apds9960 import APDS9960
import RPi.GPIO as GPIO
import smbus
from time import sleep

port = 1
bus = smbus.SMBus(port)

apds = APDS9960(bus)

def intH(channel):
    print("INTERRUPT")

GPIO.setmode(GPIO.BOARD)
GPIO.setup(3, GPIO.IN)
try:
    # Interrupt-Event hinzufuegen, steigende Flanke
    GPIO.add_event_detect(3, GPIO.FALLING, callback = intH)

    print("Light Sensor Test")
    print("=================")
    apds.enableLightSensor()
    oval = -1
    while True:
        sleep(0.25)
        val = apds.readAmbientLight()
        r = apds.readRedLight()
        g = apds.readGreenLight()
        b = apds.readBlueLight()
        if val != oval:
Пример #22
0
from machine import Pin, I2C, deepsleep
import utime
from bme280 import BME280
from apds9960.const import *
from apds9960 import uAPDS9960 as APDS9960
import myNet

i2c = I2C(scl=Pin(0), sda=Pin(4))
bme = BME280(i2c=i2c)
apds = APDS9960(i2c)

led = Pin(22, Pin.OUT)
configPin = Pin(2, Pin.IN, Pin.PULL_UP)

apds.enableLightSensor()
utime.sleep(2)  # allow sensor to init


def get_sensors():
    temperature, pressure, humidity = bme.read_compensated_data()
    light = apds.readAmbientLight()
    temperature = temperature / 100
    pressure = pressure / 256
    humidity = humidity / 1024
    return temperature, pressure, humidity, light


configMode = not configPin.value()

while not configMode:
    configMode = not configPin.value()