Пример #1
0
def inloop(textchange=False, activity=False, offset=0):

    if textchange:
        text.regen()
        text2.regen()

    if httpbutton.status == 'unknown':
        get_button_status()
    if httpbutton.status == 'error':
        httpbutton.colouring.set_colour([0, 0, 1])
    if peripherals.touch_pressed:
        peripherals.touch_pressed = False

        if peripherals.clicked(httpbutton.x, httpbutton.y):

            if httpbutton.status == 'OFF':
                try:
                    a = urllib.request.urlopen('http://blabla/relais1=1')
                except:
                    print('error httpbutton')
                else:
                    #if a.getcode() == 200:  #checks http status code 200 = OK
                    httpbutton.colouring.set_colour(
                        [0, 1, 0])  #we change color of button to green
                    httpbutton.status = 'ON'

                    # we could also check response content
                    #if a.read() == 'OK':       check content

            elif httpbutton.status == 'ON':
                try:
                    a = urllib.request.urlopen('http://blabla/relais1=0')
                except:
                    print('error httpbutton')
                else:
                    #if a.getcode() == 200:  #checks http status code 200 = OK
                    httpbutton.colouring.set_colour(
                        [1, 0, 0])  #we change color of button to red
                    httpbutton.status = 'OFF'

    if offset != 0:
        graphics.slider_change(text2.text, offset)
        offset = graphics.slider_change(text.text, offset)
        if offset == 0:
            httpbutton.status = 'unknown'
            text.regen()
            text2.regen()
    text.draw()
    text2.draw()

    return activity, offset
Пример #2
0
def inloop(textchange = False,activity = False, offset = 0):

     global actualy,scrolloffset, updown,displayheight, lasticalrefresh


     if lasticalrefresh < time.time(): 
         init()
         lasticalrefresh = time.time() +  config.ICAL_TM

     if offset != 0:
           offset = graphics.slider_change(text6.text, offset)
     if offset == 0:
             
        background2.draw()
        lowerboarder.draw()
        upperboarder.draw()
     
        if actualy < -displayheight:
            if scrolloffset <  actualy + displayheight:
               updown = 1
            if scrolloffset > 0:
               updown = 0
            if updown:    
               scrolloffset += 15
            else:
              scrolloffset -= 1
            text6.text.positionY(-scrolloffset)



     text6.draw()
     return activity, offset
Пример #3
0
def inloop(textchange=False, activity=False, offset=0):
    global seplines, degwind, threehours, weathericon, text, line, baroneedle, windneedle, linemin, linemax, error

    if (time.time() > threehours) and offset == 0:
        start_new_thread(init, ())
        threehours = time.time() + (60 * 60 * 3)

    grapharea2.draw()
    grapharea.draw()

    if offset != 0:
        #graphics.slider_change(city.sprite, offset)
        offset = graphics.slider_change(text.text, offset)

    else:
        if (error == False):
            weathericon.draw()
            baroneedle.draw()
            line.draw()
            # linemin.draw()
            # linemax.draw()
            if degwind:
                windneedle.draw()
            for subline in seplines:
                subline.draw()
            #for icon in icons: icon.draw()

    text.draw()

    return activity, offset
Пример #4
0
def inloop(textchange=False, activity=False, offset=0):
    global nextsensorcheck, graph
    now = time.time()
    if (now > nextsensorcheck
        ) and offset == 0 and peripherals.touched() == False:
        peripherals.get_sensors()
        peripherals.get_infrared()
        nextsensorcheck = now + 0.1
        text.regen()
        i = 0
        for varname in showvars:
            y_vals[i][:-1] = y_vals[i][1:]
            y_vals[i][-1] = getattr(peripherals.eg_object, varname)
            i += 1
        graph.update(y_vals)

    grapharea.draw()

    if offset != 0:
        offset = graphics.slider_change(text.text, offset)
    else:
        graph.draw()
    text.draw()
    activity = False
    return activity, offset
Пример #5
0
def inloop(textchange=False, activity=False, offset=0):

    if textchange:
        text2.regen()

    if peripherals.touch_pressed:
        peripherals.touch_pressed = False
        if peripherals.clicked(Up.x, Up.y):
            peripherals.eg_object.max_backlight += 1
            if peripherals.eg_object.max_backlight > 31:
                peripherals.eg_object.max_backlight = 31
            peripherals.controlbacklight(peripherals.eg_object.max_backlight)
            text2.regen()

        elif peripherals.clicked(Down.x, Down.y):
            peripherals.eg_object.max_backlight -= 1
            if peripherals.eg_object.max_backlight < 1:
                peripherals.eg_object.max_backlight = 1
            peripherals.controlbacklight(peripherals.eg_object.max_backlight)
            text2.regen()

        elif peripherals.clicked(wifi.x, wifi.y):
            config.subslide = 'wifisetup'

    if offset != 0:
        offset = graphics.slider_change(text2.text, offset)
        if offset == 0:
            text2.regen()
    text2.draw()

    return activity, offset
Пример #6
0
def inloop(textchange = False,activity = False, offset = 0):
      
     if textchange:
       text2.regen()
     if shutterUp.y != -100 and shutterUp.colouring.colour[2] == 1:
        shutterUp.set_position(y=-100)
     if (shutterUp.colouring.colour[2] == 0):
        if shutterUp.y > 0:
          shutterUp.set_position(y=-100)
        shutterUp.set_position(y=(shutterUp.y+2))
        activity = True



     if shutterDown.y != -100 and shutterDown.colouring.colour[2] == 1:
        shutterDown.set_position(y=-100)
     if (shutterDown.colouring.colour[2] == 0):
        if shutterDown.y < -99:
          shutterDown.set_position(y=0)
        shutterDown.set_position(y=(shutterDown.y-2))
        activity = True
       
 

     if peripherals.touch_pressed:
      peripherals.touch_pressed = False     
      if peripherals.clicked(shutterUp.x,shutterUp.y):
        peripherals.controlrelays(config.shutterdown, 0)
        mqttclient.publish("scheinwerfer", '0')
        peripherals.controlrelays(config.shutterup, 1)
        shutterUp.colouring.set_colour([0,1,0])
        shutterUp.set_text(text_format= chr(0xe00f))
        shutterDown.colouring.set_colour([1,1,1])


      elif peripherals.clicked(shutterDown.x,shutterDown.y):
        peripherals.controlrelays(config.shutterup, 0)
        peripherals.controlrelays(config.shutterdown, 1)
        mqttclient.publish("scheinwerfer", '1')
        shutterUp.colouring.set_colour([1,1,1])
        shutterDown.colouring.set_colour([0,1,0])


      else:
        peripherals.controlrelays(config.shutterdown, 0)
        peripherals.controlrelays(config.shutterup, 0)
        shutterUp.colouring.set_colour([1,1,1])
        shutterDown.colouring.set_colour([1,1,1])
        
        
     if offset != 0:
         offset = graphics.slider_change(text2.text, offset)
         if offset == 0:
             text2.regen()
     text2.draw()   
         
     return activity,offset
Пример #7
0
def inloop(textchange=False, activity=False, offset=0):

    if textchange:
        text3.regen()
    if offset != 0:
        offset = graphics.slider_change(text3.text, offset)
        if offset == 0:
            text3.regen()
    background.draw()
    text3.draw()

    return activity, offset
Пример #8
0
def inloop(textchange=False, activity=False, offset=0):

    global graphupdated, graph

    if graphupdated < time.time():
        graphupdated = time.time() + 60
        start_new_thread(update_graph, ())

    if offset != 0:
        offset = graphics.slider_change(graph, offset)
    graph.draw()

    return activity, offset
Пример #9
0
def inloop(textchange=False, activity=False, offset=0):

    if offset != 0:
        offset = graphics.slider_change(amperemeter, offset)
    else:
        ampereneedle.rotateToZ(
            50 - (peripherals.eg_object.relais1current * 20))
        ampereneedle.draw()

    amperemeter.draw()
    text5.draw()

    try:
        peripherals.eg_object.relais1current = (
            ((5000/1024) * (peripherals.read_two_bytes(0x14) - 2)) / 185)
        text5.regen()

    except:
        pass

    return activity, offset
Пример #10
0
def inloop(textchange=False, activity=False, offset=0):

    global graphupdated, graph

    if graphupdated < time.time():
        graphupdated = time.time() + 60
        activity = True
        rrdtool.graph(
            "/media/ramdisk/graph1.png", "--full-size-mode", "--font",
            "DEFAULT:13:", "--color", "BACK#ffffffC0", "--color",
            "CANVAS#ffffff00", "--color", "SHADEA#ffffff00", "--color",
            "SHADEB#ffffff00", "--width", "800", "--height", "480", "--start",
            "-1h", "--title", "temperature overview", "--vertical-label", "°C",
            "DEF:act_temp=temperatures.rrd:act_temp:AVERAGE",
            "DEF:cpu=temperatures.rrd:cpu:AVERAGE",
            "DEF:gpu=temperatures.rrd:gpu:AVERAGE",
            "DEF:atmega=temperatures.rrd:atmega:AVERAGE",
            "DEF:sht=temperatures.rrd:sht:AVERAGE",
            "DEF:bmp280=temperatures.rrd:bmp280:AVERAGE",
            "DEF:mlxamb=temperatures.rrd:mlxamb:AVERAGE",
            "DEF:mlxobj=temperatures.rrd:mlxobj:AVERAGE",
            "LINE4:act_temp#ff0000:ROOM", "LINE2:cpu#ff0000:CPU",
            "LINE2:gpu#ff0000:GPU", "LINE2:atmega#00ff00:AVR",
            "LINE2:sht#0000ff:SHT30", "LINE2:mlxamb#ff00ff:MLX_A",
            "LINE2:mlxobj#00ffff:MLX_O", "LINE2:bmp280#888800:BMP280")

        graph = pi3d.ImageSprite('/media/ramdisk/graph1.png',
                                 shader=graphics.SHADER,
                                 camera=graphics.CAMERA,
                                 w=800,
                                 h=480,
                                 z=1)
    if offset != 0:
        offset = graphics.slider_change(graph, offset)
    graph.draw()

    return activity, offset
def inloop(textchange=False, activity=False, offset=0):
    global rotate

    if textchange:
        text.regen()

    rotate = rotate + 1
    if rotate > 90:
        rotate = 0
    doorneedle.rotateToZ(rotate)  # open  rotate 0 closed
    doorneedle.set_material([rotate * 1.1 * 0.01, 0, 0])
    windowneedle.set_material(
        [rotate * 1.1 * 0.01, 100 - rotate * 1.1 * 0.01, 0])
    windowneedle.rotateToZ(-rotate)

    if offset == 0:
        officearea.draw()
        kitchenarea.draw()
        storagearea.draw()
        doorneedle.draw()
        windowneedle.draw()

    floorplan.draw()

    officearea.set_alpha(0.01 * rotate)
    kitchenarea.set_alpha(1 - 0.01 * rotate)
    storagearea.set_alpha(0.01 * rotate)

    if offset != 0:
        offset = graphics.slider_change(floorplan, offset)
        if offset == 0:
            text.regen()

    text.draw()
    activity = True
    return activity, offset
Пример #12
0
def inloop(textchange=False, activity=False, offset=0):
    global shuttertimer
    if textchange:
        text2.regen()
    if shutterUp.y != -100 and shutterUp.colouring.colour[2] == 1:
        shutterUp.set_position(y=-100)
    if (shutterUp.colouring.colour[2] == 0):
        if shutterUp.y > 0:
            shutterUp.set_position(y=-100)
        shutterUp.set_position(y=(shutterUp.y + 2))
        activity = True

    if shutterDown.y != -100 and shutterDown.colouring.colour[2] == 1:
        shutterDown.set_position(y=-100)
    if (shutterDown.colouring.colour[2] == 0):
        if shutterDown.y < -99:
            shutterDown.set_position(y=0)
        shutterDown.set_position(y=(shutterDown.y - 2))
        activity = True

    if (shuttertimer > 0):
        if (shuttertimer > time.time()):
            peripherals.eg_object.uhrzeit = str(int(shuttertimer -
                                                    time.time()))
            text2.regen()

        elif (shuttertimer < time.time()):
            shuttertimer = 0
            peripherals.eg_object.uhrzeit = time.strftime("%H:%M")
            text2.regen()
            peripherals.controlrelays(config.shutterdown, 0)
            peripherals.controlrelays(config.shutterup, 0)
            shutterDown.colouring.set_colour([1, 1, 1])
            shutterUp.colouring.set_colour([1, 1, 1])

    if peripherals.touch_pressed:
        peripherals.touch_pressed = False
        if peripherals.clicked(shutterUp.x, shutterUp.y):
            peripherals.controlrelays(config.shutterdown, 0)
            peripherals.controlrelays(config.shutterup, 1)
            shuttertimer = time.time() + config.shuttertimer
            shutterUp.colouring.set_colour([0, 1, 0])
            shutterDown.colouring.set_colour([1, 1, 1])

        elif peripherals.clicked(shutterDown.x, shutterDown.y):
            peripherals.controlrelays(config.shutterup, 0)
            peripherals.controlrelays(config.shutterdown, 1)
            shuttertimer = time.time() + config.shuttertimer
            shutterUp.colouring.set_colour([1, 1, 1])
            shutterDown.colouring.set_colour([0, 1, 0])

        else:
            shuttertimer = 0
            peripherals.eg_object.uhrzeit = time.strftime("%H:%M")
            text2.regen()

            peripherals.controlrelays(config.shutterdown, 0)
            peripherals.controlrelays(config.shutterup, 0)
            shutterUp.colouring.set_colour([1, 1, 1])
            shutterDown.colouring.set_colour([1, 1, 1])

    if offset != 0:
        offset = graphics.slider_change(text2.text, offset)
        if offset == 0:
            text2.regen()
    text2.draw()

    return activity, offset
Пример #13
0
def inloop(textchange=False, activity=False, offset=0):

    global controls_alpha

    if textchange:

        if peripherals.eg_object.tempoffset > 0:
            offset_temp_block.colouring.set_colour([1, 0, 0])
        elif peripherals.eg_object.tempoffset < 0:
            offset_temp_block.colouring.set_colour([0, 0, 1])
        else:
            offset_temp_block.colouring.set_colour([1, 1, 1])

        red = (0.01 * (peripherals.eg_object.a4 / 4))
        if (red > 1):
            red = 1

        green = (0.01 * (120 - peripherals.eg_object.a4 / 4))
        if green < 0:
            green = 0
        if green > 1:
            green = 1

        cloud.colouring.set_colour([red, green, 0, 1.0])

        if config.coolingrelay:
            if getattr(peripherals.eg_object,
                       'relais' + (str)(config.coolingrelay)):
                cooling.colouring.set_colour([0, 0, 1])
            else:
                cooling.colouring.set_colour([1, 1, 1])

        if config.heatingrelay:
            if getattr(peripherals.eg_object,
                       'relais' + (str)(config.heatingrelay)):
                heating.colouring.set_colour([1, 1, 0])
            else:
                heating.colouring.set_colour([1, 1, 1])

        if hasattr(peripherals.eg_object, 'pressure'):
            normalizedpressure = (peripherals.eg_object.pressure - 950)
            if normalizedpressure < 0:
                normalizedpressure = 0
            if normalizedpressure > 100:
                normalizedpressure = 100
            green = 0.02 * (normalizedpressure)
            if green > 1:
                green = 1
            red = 0.02 * (100 - normalizedpressure)
            if red > 1:
                red = 1
            barometer.colouring.set_colour([red, green, 0, 1.0])
            baroneedle.set_material([red, green, 0])
            baroneedle.rotateToZ(100 - (normalizedpressure * 2))
        text.regen()

    if hasattr(peripherals.eg_object, 'pressure') and offset == 0:
        baroneedle.draw()

    if (peripherals.eg_object.motion):
        motiondetection.colouring.set_colour([1, 0, 0])
    else:
        motiondetection.colouring.set_colour([1, 1, 1])

    if peripherals.touch_pressed:
        peripherals.touch_pressed = False

        if config.heatingrelay or config.coolingrelay:

            if peripherals.clicked(increaseTemp.x, increaseTemp.y):
                controls_alpha = 1
                peripherals.eg_object.set_temp += 0.5
                set_temp_block.colouring.set_colour([1, 0, 0])
                text.regen()
            if peripherals.clicked(decreaseTemp.x, decreaseTemp.y):
                controls_alpha = 1
                peripherals.eg_object.set_temp -= 0.5
                set_temp_block.colouring.set_colour([0, 0, 1])
                text.regen()

        if peripherals.clicked(-330, -180):
            config.subslide = 'videostream'

            try:
                os.popen('killall omxplayer.bin')
            except:
                pass

            os.popen(
                'omxplayer --threshold 0.5  --display 4 rtsp://username:[email protected]:554/mpeg4cif --win "0 0 800 450"'
            )
            # loading time depends on keyframes in stream, only h264 recommended!

        if 'intercom' in config.subslides and peripherals.clicked(-230, -180):
            config.subslide = 'intercom'

            try:
                os.popen('killall omxplayer.bin')
                os.popen('killall raspivid')
            except:
                pass

            os.popen('gpio -g write 27 1')  # deactivate amplifier
            os.popen('i2cset -y 2 0x2A 0x93 210')  # deactivate vent
            os.popen("amixer -c 1 set 'PCM' 0%")  # deactivate soundcard out
            os.popen("amixer -c 1 set 'Mic' 0%")  # enable mic
            config.iip = '192.168.1.22'
            config.iuser = '******'
            config.ipw = 'raspberry'
            os.popen(
                'sshpass -p \'raspberry\' ssh -o StrictHostKeyChecking=no  pi@'
                + config.iip +
                ' "raspivid  -t 0 -w 640 -h 480 -g 10 -ih -fps 25 -l -p \'640,0,160,120\' -o  tcp://0.0.0.0:5001"'
            )
            os.popen(
                'sshpass -p \'raspberry\' ssh -o StrictHostKeyChecking=no  pi@'
                + config.iip +
                ' "arecord -D plughw:1,0 -r 12000 -f S16_LE -c1 -B 300 -t wav | nc -l 5003"'
            )

            os.popen(
                'raspivid  -t 0 -w 640 -h 480 -g 10  -ih -fps 25 -hf  -vf -l -p \'640,0,160,120\' -o  tcp://0.0.0.0:5002'
            )
            os.popen('sleep 2 && nc ' + config.iip +
                     ' 5001 | ./videoplayer 0 0 640 480')
            os.popen(
                'sleep 2 && nc ' + config.iip +
                '  5003 | { dd bs=60K count=1 iflag=fullblock of=/dev/null; aplay -c 1 --device=plughw:1,0 -B 0 -f S16_LE -c1 -r 12000 -t wav; }'
            )
            os.popen(
                'arecord -D plughw:1,0 -r 12000 -f S16_LE -c1 -B 300 -t wav | nc -l 5004'
            )

            os.popen(
                'sshpass -p \'raspberry\' ssh -o StrictHostKeyChecking=no  pi@'
                + config.iip +
                ' "nc 192.168.1.33 5002 | ./videoplayer 0 0 640 480"')
            os.popen(
                'sshpass -p \'raspberry\' ssh -o StrictHostKeyChecking=no  pi@'
                + config.iip +
                ' "nc 192.168.1.33 5004 | { dd bs=60K count=1 iflag=fullblock of=/dev/null; aplay -c 1 --device=plughw:1,0 -B 0 -f S16_LE -c1 -r 12000 -t wav; }"'
            )

    # nc 192.168.1.33 5003 | { dd bs=60K count=1 iflag=fullblock of=/dev/null; aplay -c 1 --device=plughw:1,0 -B 0 -f S16_LE -c1 -r 12000 -t wav; }
    # arecord -D plughw:1,0 -r 12000 -f S16_LE -c1 -B 300 -t wav | nc -l 5003

    if controls_alpha > 0.3:
        activity = True
        controls_alpha -= 0.01
    if config.heatingrelay or config.coolingrelay:
        increaseTemp.colouring.set_colour(alpha=controls_alpha)
        decreaseTemp.colouring.set_colour(alpha=controls_alpha)
        set_temp_block.colouring.set_colour(alpha=controls_alpha)
        offset_temp_block.colouring.set_colour(alpha=controls_alpha)

    if controls_alpha < 0.3:

        if config.heatingrelay or config.coolingrealy:
            set_temp_block.colouring.set_colour([1, 1, 1])

    if offset != 0:
        offset = graphics.slider_change(text.text, offset)
        if offset == 0:
            text.regen()

    text.draw()

    return activity, offset