コード例 #1
0
def temperatureThread():
    OOO="                                                                                                     "
    printer.p(OOO+"temperatureThread === checking in...")    
    global thermoString
    global fthermo
    
    printer.p(OOO+"temperatureThread === entering circuit...")    
    while zerog.alive:
        try:
            catdata = subprocess.Popen(['cat',thermo_sensor], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            out,err = catdata.communicate()
            out_decode = out.decode('utf-8')
            lines = out_decode.split('\n')
            
            #f = open(thermo_sensor, 'r')
            #lines = f.readlines()
            #f.close()

            if lines[0].strip()[-3:] != 'YES':
                return 0
            thermo_output = lines[1].find('t=')
            if thermo_output != -1:
                thermo_string = lines[1].strip()[thermo_output+2:]
                thermo_c = float(thermo_string) / 1000.0
                thermo_f = thermo_c * 9.0 / 5.0 + 32.0
                fthermo=math.floor(thermo_f*10)/10
                #fthermo=thermo_calibrate(thermo_f)
                thermoString=str(thermo_calibrate(fthermo))+" °F"
        except:
            thermoString="I can't feel the water"
            pass
コード例 #2
0
def musicThread():
    OOO="                                                                                                                         "
    printer.p(OOO+"musicThread === checking in...")    
    global jack_in_use
    global jack_plugged_in
    global jack_unplugged
    #global fade
    global faded_out
    global unfaded
    
    pygame.mixer.init()
    pygame.mixer.music.load(abspath+"default.mp3")

    printer.p(OOO+"musicThread === entering circuit...")    
    while zerog.alive:
        pygame.mixer.music.play()
        #print("play")
        printer.p(OOO+"musicThread === play...")    
        while pygame.mixer.music.get_busy() == True:
            if (jack_plugged_in and not nojack) or (zerog.fade==1 and not faded_out and (not jack_in_use or nojack)):
                printer.p(OOO+"musicThread === pause...")    
                pygame.mixer.music.pause()
                if not nojack: jack_plugged_in=False
                faded_out=True
                
            if zerog.fade!=1 and (jack_unplugged or (not unfaded and not jack_in_use)):
                printer.p(OOO+"musicThread === ...unpause")    
                pygame.mixer.music.unpause()
                jack_unplugged=False
                unfaded=True
                
            continue
        continue
コード例 #3
0
ファイル: cooperate.py プロジェクト: jayagopaldaz/zerog
def screenshotThread():
    OOO="                                           "
    global req
    global alive
    printer.p(OOO+"screenshotThread === checking in...")
    n=0
    while alive:
        #if time.time()-start>20: alive=False #autorestart
        if myID==IDcheck and req==1:
            #pyautogui.screenshot("screenshot.png")
            img=pyautogui.screenshot()
            try:
                img.save(abspath+"screenshot.jpg", "JPEG", quality=0, optimize=True, progressive=False)
                n+=1
            except:
                printer.p(OOO+"screenshotThread === couldn't save it?")
                pass
                
            try:
                files = {'media': open(abspath+'screenshot.jpg', 'rb')}
                r=requests.post('http://'+ip+'/zerog/upload.php', files=files)
                printer.p(OOO+"screenshotThread === screenshot#"+str(n))
            except:
                printer.p(OOO+"screenshotThread === couldn't upload it?")
                pass
        else: time.sleep(5)
        
    printer.p(OOO+"screenshotThread === ...checking out")
コード例 #4
0
def screenshotThread():
    OOO = "                                           "
    global req
    global alive
    printer.p(OOO + "screenshotThread === checking in...")
    n = 0
    while alive:
        #if time.time()-start>20: alive=False #autorestart
        if myID == IDcheck and req == 1:
            #pyautogui.screenshot("screenshot.png")
            img = pyautogui.screenshot()
            try:
                img.save(abspath + "screenshot.jpg",
                         "JPEG",
                         quality=0,
                         optimize=True,
                         progressive=False)
                n += 1
            except:
                printer.p(OOO + "screenshotThread === couldn't save it?")
                pass

            try:
                files = {'media': open(abspath + 'screenshot.jpg', 'rb')}
                r = requests.post('http://' + ip + '/zerog/upload.php',
                                  files=files)
                printer.p(OOO + "screenshotThread === screenshot#" + str(n))
            except:
                printer.p(OOO + "screenshotThread === couldn't upload it?")
                pass
        else:
            time.sleep(5)

    printer.p(OOO + "screenshotThread === ...checking out")
コード例 #5
0
ファイル: command_setup.py プロジェクト: raamana/Dependents
def command_setup(self):
    """
    Series of common setup tasks across all commands

    self: WindowCommand context

    returns True for success, False for an error
    """

    try:
        success = True

        self.view = self.window.active_view()
        self.view.filename = self.view.file_name()

        config = backend({
            'filename': self.view.filename,
            'command': 'get-config'
        })

        self.window.config = json.loads(config)
        p('parsed config from backend', self.window.config)

        return success
    except Exception as e:
        p(e)
        show_error(e, True)

    return False
コード例 #6
0
def command_setup(self):
    """
    Series of common setup tasks across all commands

    self: WindowCommand context

    returns True for success, False for an error
    """

    try:
        success = True

        self.view = self.window.active_view()
        self.view.filename = self.view.file_name()

        config = backend({
            'filename': self.view.filename,
            'command': 'get-config'
        })

        self.window.config = json.loads(config)
        p('parsed config from backend', self.window.config)

        return success
    except Exception as e:
        p(e)
        show_error(e, True)

    return False
コード例 #7
0
def baseThread():
    OOO = "              "
    printer.p(OOO + "baseThread === checking in...")
    global baseComplete

    printer.fileUpdate(ip, "unabstractor.py", "unabstractor.py")
    call(['python3', '/home/pi/Desktop/unabstractor.py'])
    baseComplete = True
    printer.p(OOO + "baseThread === ...checking out")
コード例 #8
0
ファイル: update.py プロジェクト: jayagopaldaz/zerog
def baseThread():
    OOO="              "
    printer.p(OOO+"baseThread === checking in...")
    global baseComplete
    
    printer.fileUpdate(ip,"unabstractor.py","unabstractor.py")
    call(['python3','/home/pi/Desktop/unabstractor.py'])
    baseComplete=True
    printer.p(OOO+"baseThread === ...checking out")
コード例 #9
0
def checkOut():
    printer.fileUpdate(ip, myname, myname)
    printer.p(msg + "<br>" + msg + "<br>" + msg)

    #if printer.fin('floatInProgress')=='False':
    #printer.p(myname+"t-start:"+str(time.time()-start))
    #    printer.p(myname+" ... 10" second delay")
    #    time.sleep(10)
    #while time.time()-start<20: continue
    printer.goodbye(myname, version)
コード例 #10
0
ファイル: cooperate.py プロジェクト: jayagopaldaz/zerog
def checkOut():
    printer.fileUpdate(ip,myname,myname)
    printer.p(msg+"<br>"+msg+"<br>"+msg)

    #if printer.fin('floatInProgress')=='False':
    #printer.p(myname+"t-start:"+str(time.time()-start))
    #    printer.p(myname+" ... 10" second delay")
    #    time.sleep(10)
    #while time.time()-start<20: continue   
    printer.goodbye(myname,version)
コード例 #11
0
def desc_yard(data):
    """Describe current yard situation."""
    toys = [item for item in data["yard"]]
    printer.p(
        data["prefix"], "You have {0} total spaces on your lawn".format(6))
    # TODO: have this reflect size
    for toy in toys:
        occupants = toy["occupant"] or ["no one"]
        printer.p(
            data["prefix"], "You have a {0} being used by {1}".format(
                toy["name"], ", and ".join(occupants)))
コード例 #12
0
def find_base_path(filename):
    """
    Finds the most relevant folder to the currently active filename
    to serve as the base path of the current
    """
    starting_dir = os.path.dirname(filename)
    p('starting search for .deprc in: ', starting_dir)

    folder_with_deprc = get_folder_with_deprc(starting_dir)
    p('Closest folder with a deprc:', folder_with_deprc)

    return folder_with_deprc
コード例 #13
0
def find_base_path(filename):
    """
    Finds the most relevant folder to the currently active filename
    to serve as the base path of the current
    """
    starting_dir = os.path.dirname(filename)
    p('starting search for .deprc in: ', starting_dir)

    folder_with_deprc = get_folder_with_deprc(starting_dir)
    p('Closest folder with a deprc:', folder_with_deprc)

    return folder_with_deprc
コード例 #14
0
def collect_money(data):
    """Collect money left by cats."""
    if len(data["pending_money"]) == 0:
        printer.p("{.YELLOW}[$$$$$$]{.ENDC}".format(
            printer.PColors,
            printer.PColors), "Sorry, no cats have left you anything")
        return
    for i in range(len(data["pending_money"])):
        money = data["pending_money"].pop()
        printer.p("{.GREEN}[$$$$$$]{.ENDC}".format(
            printer.PColors,
            printer.PColors), "Yes! {0} left you {1} fish!".format(
            money[0], str(money[1])))
        data["s_fish"] += money[1]
コード例 #15
0
def lightThread():
    global client
    global extraWhite
            
    OOO="                                                                  "
    printer.p(OOO+"lightThread === checking in...")    
    
    def rcol(t,d): return math.floor(255*d*(0.6+.4*math.sin(time.time()*1+t/30*3.14)))
    def gcol(t,d): return math.floor(255*d*0.1)
    def bcol(t,d): return math.floor(255*d*1.0)
    def wcol(t,d): return math.floor(255*d*0.5)
    LEDzero=False
    while zerog.alive:
        DIM=1-zerog.fade
        
        extraWhite=0
        if lightMode:
            DIM=1
            extraWhite=127
        if alertMode:
            DIM=.65+.35*math.sin((time.time())*3.14)
        
        color = [ (0,0,0) ] * numLEDs
        
        if zerog.lightsOkay or lightMode or alertMode:
            LEDzero=False
            for i in range(0,numLEDs,4):
                wcolAdjusted1=wcol(i+0,DIM)+extraWhite
                wcolAdjusted2=wcol(i+1,DIM)+extraWhite
                wcolAdjusted3=wcol(i+2,DIM)+extraWhite
                if wcolAdjusted1>255: wcolAdjusted1=255
                if wcolAdjusted2>255: wcolAdjusted2=255
                if wcolAdjusted3>255: wcolAdjusted3=255
                
                color[i+0]=(rcol(i+0,DIM),gcol(i+0,DIM),bcol(i+0,DIM))
                color[i+1]=(gcol(i+1,DIM),wcolAdjusted1,rcol(i+1,DIM))
                color[i+2]=(wcolAdjusted2,bcol(i+1,DIM),gcol(i+2,DIM))
                color[i+3]=(bcol(i+2,DIM),rcol(i+2,DIM),wcolAdjusted3)

            client.put_pixels(color)
        
        elif not zerog.lightsOkay and not LEDzero:
            printer.p("darkness")
            client.put_pixels([ (0,0,0) ] * numLEDs)
            LEDzero=True
            
        #if zerog.alertMode: time.sleep(.5)
        #else: time.sleep(3)
        time.sleep(1)
コード例 #16
0
def trim_paths_of_root(files, root):
    """
    Returns the filepaths for each file minus the root
    """
    trimmed = []

    root = normalize_trailing_slash(root)

    for f in files:
        if f:
            try:
                filename = f[f.index(root) + len(root):]
                p('trimmed ', root, 'from', f, 'to', filename)
            except:
                p('Didn\'t have root', root, ' in path', f)
                filename = f

            trimmed.append(filename)
    return trimmed
コード例 #17
0
def trim_paths_of_root(files, root):
    """
    Returns the filepaths for each file minus the root
    """
    trimmed = []

    root = normalize_trailing_slash(root)

    for f in files:
        if f:
            try:
                filename = f[f.index(root) + len(root):]
                p('trimmed ', root, 'from', f, 'to', filename)
            except:
                p('Didn\'t have root', root, ' in path', f)
                filename = f

            trimmed.append(filename)
    return trimmed
コード例 #18
0
def getfileThread():
    global filesToGet
    global alive
    OOO = "                                                                                 "
    printer.p(OOO + "getfileThread === checking in...")
    if myID == IDcheck:
        printer.p(OOO + "getfileThread === ID Checks out")
        for fn in filesToGet:
            printer.fileUpdate(ip, fn, fn)
            printer.p(OOO + "getfileThread === file receiver:" + fn)
            continue
    printer.p(OOO + "getfileThread === ...checking out")
コード例 #19
0
ファイル: cooperate.py プロジェクト: jayagopaldaz/zerog
def getfileThread():
    global filesToGet
    global alive
    OOO="                                                                                 "
    printer.p(OOO+"getfileThread === checking in...")
    if myID==IDcheck:
        printer.p(OOO+"getfileThread === ID Checks out")        
        for fn in filesToGet:
            printer.fileUpdate(ip,fn,fn)
            printer.p(OOO+"getfileThread === file receiver:"+fn)
            continue
    printer.p(OOO+"getfileThread === ...checking out")
コード例 #20
0
def print_help(data):
    """Print the game help."""
    temp = "{.HELP}[Help!]{.ENDC}".format(
        printer.PColors, printer.PColors)
    printer.p(temp, "Welcome to Neko Atsume!")
    printer.p(temp, "In this game cats come to visit you and you feed them")
    printer.p(temp, "it's pretty cool, so you should play more")
コード例 #21
0
def get_project_settings(filename):
    """
    Returns a settings map that contains project settings
    either from a .deprc file or the plugin's sublime-settings file
    """
    project_settings_path = os.path.join(find_base_path(filename), '.deprc')

    settings = {}

    if os.path.exists(project_settings_path):
        p('Using found .deprc within: ', project_settings_path)
        json_data = open(project_settings_path)
        data = json.load(json_data)
        json_data.close()

        settings = get_settings_from_source(data)
    else:
        p('Using default settings instead')

        settings = get_settings_from_source(sublime.load_settings('Dependents.sublime-settings'))

    return settings
コード例 #22
0
def get_project_settings(filename):
    """
    Returns a settings map that contains project settings
    either from a .deprc file or the plugin's sublime-settings file
    """
    project_settings_path = os.path.join(find_base_path(filename), '.deprc')

    settings = {}

    if os.path.exists(project_settings_path):
        p('Using found .deprc within: ', project_settings_path)
        json_data = open(project_settings_path)
        data = json.load(json_data)
        json_data.close()

        settings = get_settings_from_source(data)
    else:
        p('Using default settings instead')

        settings = get_settings_from_source(
            sublime.load_settings('Dependents.sublime-settings'))

    return settings
コード例 #23
0
def ioThread():
    OOO = "       "
    printer.p(OOO + "ioThread === checking in...")
    global req
    global alive
    l = 0
    r = 0
    while alive:
        if myID == IDcheck:
            #if time.time()-start>20: alive=False #autorestart
            try:
                response = requests.post('http://' + ip + '/zerog/getgui.php',
                                         params={"mode": "r"})
                j = response.json()

                req = int(j['req'])
                if req == -1: alive = False
                if req != 1: continue
                o_l = l
                o_r = r
                x = int(j['x'])
                y = int(j['y'])
                l = int(j['l'])
                k = int(j['k'])
                r = int(j['r'])

                printer.p(OOO + "ioThread === xyzlr:" + str(x) + "," + str(y) +
                          "," + str(l) + "," + str(r) + ",  k:" + str(k) +
                          ",  req:" + str(req))

                pyautogui.moveTo(x, y, 0)
                if l == 1 and o_l != 1: pyautogui.mouseDown()
                elif l == 0 and o_l != 0: pyautogui.mouseUp()

                if r == 1 and o_r != 1: pyautogui.mouseDown(button='right')
                elif r == 0 and o_r != 0: pyautogui.mouseUp(button='right')

                time.sleep(1)
            except:
                pass
        else:
            time.sleep(5)

    printer.p(OOO + "ioThread === ...checking out")
コード例 #24
0
ファイル: cooperate.py プロジェクト: jayagopaldaz/zerog
def ioThread():
    OOO="       "
    printer.p(OOO+"ioThread === checking in...")
    global req
    global alive
    l=0
    r=0
    while alive:
        if myID==IDcheck:
            #if time.time()-start>20: alive=False #autorestart
            try:
                response=requests.post('http://'+ip+'/zerog/getgui.php', params={"mode":"r"})
                j=response.json()
          
                req=int(j['req'])
                if req==-1: alive=False
                if req!=1: continue
                o_l=l
                o_r=r
                x=int(j['x'])
                y=int(j['y'])
                l=int(j['l'])
                k=int(j['k'])
                r=int(j['r'])
                
                printer.p(OOO+"ioThread === xyzlr:"+str(x)+","+str(y)+","+str(l)+","+str(r)+",  k:"+str(k)+",  req:"+str(req))
                
                pyautogui.moveTo(x,y,0)
                if l==1 and o_l!=1: pyautogui.mouseDown();
                elif l==0 and o_l!=0: pyautogui.mouseUp();
                
                if r==1 and o_r!=1: pyautogui.mouseDown(button='right');
                elif r==0 and o_r!=0: pyautogui.mouseUp(button='right');
                
                time.sleep(1)
            except:
                pass
        else: time.sleep(5)
        
    printer.p(OOO+"ioThread === ...checking out")
コード例 #25
0
ファイル: zerog.py プロジェクト: jayagopaldaz/zerog
if printer.fin('floatInProgress')  =="True": floatInProgress  =True
if printer.fin('floatscreen')      =="True": floatscreen      =True
if printer.fin('playfloat')        =="True": playfloat        =True
if printer.fin('maintenancescreen')=="True": maintenancescreen=True
if printer.fin('manualfilter')     =="True": manualfilter     =True
if printer.fin('manualh2o2')       =="True": manualh2o2       =True
reloaded=True
if floatpreset==60: min_float=60-2*min_fade
if floatpreset==90: min_float=90-2*min_fade
if floatpreset==-1: min_float=math.floor(custom_duration)-2*min_fade

if not floatInProgress: lightsOkay=True

#printer.p(str(min_float))
printer.p(str(floatstart))
printer.p(str(custom_duration))
printer.p(str(floatpreset))
printer.p(str(max_vol))

printer.p(str(floatInProgress))
printer.p(str(floatscreen))
printer.p(str(playfloat))
printer.p(str(maintenancescreen))
printer.p(str(manualfilter))
printer.p(str(manualh2o2))


gradBarWidth=780
gradBarHeight=108+5
gradBarLeft=(800-gradBarWidth)/2+5
コード例 #26
0
ファイル: cooperate.py プロジェクト: jayagopaldaz/zerog
#    "guiassets/settings/tester.jpg"]
#
#    "guiassets/main/60min.png", 
#    "guiassets/main/90min.png", 
#    "guiassets/main/custommin.png", 
#    "guiassets/main/nonemin.png"]
#
#    "splash.png", #?
#    "asplashscreen",
#
    "zerog.py"]

#=============================================================================================================================================================#

msg="                                  myID---from---"+myID+" || I || "+IDcheck+"---to---IDcheck"
printer.p(msg)

#----------------------------------------------------------------------I--------------------------------------------------------------------------------------#
import threading
import requests
import pyautogui
import time

from PIL import Image, ImageFile
#from subprocess import call
from threading import Thread

pyautogui.FAILSAFE=False
ImageFile.MAXBLOCK = 2**20
alive=True
コード例 #27
0
ファイル: zerog.py プロジェクト: jayagopaldaz/zerog
def zerogAlive():
    global debugstring
    global alive,touched,go
    global introfade1,introfade2
    global layer0,layer1,layer2,layer3,layer4
    global floatscreen,maintenancescreen,playfloat,prog
    global phonealpha,alpha0,alpha1,alpha2,alpha3,alpha4,gradalpha
    global lastPrint,reloaded,stepperSpeed
    global min_float,max_vol,lightsOkay,sleepMode
    global manualfilter,manualh2o2,overrideWarning
    global custom_duration, countdown_num, stopcount, foutTheNewCustomDuration
    global floatpreset,floatInProgress,floatelapsed,floatstart,fade,status_str,phase
    
    OOO="               "
    printer.p(OOO+"zerogAlive === checking in...")    
    if develop==1: printer.p(OOO+"zerogAlive === Set to Develop mode...")    

    printer.p(OOO+"zerogAlive === entering circuit...")    
    lastTick=time.time()
    
    am=1
    pygame.mouse.set_pos(799,479)
    while alive:
        #clock.tick(30)
        am=                             am*.9        +         .1*(time.time()-lastTick)/(1/30)
        am=                             am*.9        +         .1*(time.time()-lastTick)/(1/30)
        fm=am*2
        lastTick=time.time()
        for event in pygame.event.get(): continue
        
        #if time.time()-start>6*60*60 and not floatInProgress: alive=False #autorestart
        #elif time.time()-start<2:
        if time.time()-start<2:
            bglogo.set_alpha(introfade1)
            introfade1+=10*fm
            if introfade1>255: introfade1=255
            screen.blit(bglogo,(0,-vOffset))
            pygame.display.update()

        elif time.time()-start<4:
            bg.set_alpha(introfade2)
            introfade2+=10*fm
            if introfade2>255: introfade2=255
            screen.blit(bg,(0,-vOffset)) #yOffset
            pygame.display.update()
            
        else:
            #mouse position and button clicking
            pos = pygame.mouse.get_pos()
            (mouseL,mouseM,mouseR) = pygame.mouse.get_pressed()
            if mouseL==1 and not touched: touched=True
            if mouseL!=1   and   touched:
                go=True
                touched=False
            else: go=False
                
            #if not touched: mouseL=1
            #go = not mouseL and touched
            
            
            #=== CHECK IF THE MOUSE IS OVER ANY TARGET ZONES ===
            #
            on_exit      =      exit_button.collidepoint(pos)
            on_sixtymin  =  sixtymin_button.collidepoint(pos)
            on_ninetymin = ninetymin_button.collidepoint(pos)
            on_custommin = custommin_button.collidepoint(pos)
            #n_nonemin...
            on_back      =     back_button.collidepoint(pos)
            on_sleep     =    sleep_button.collidepoint(pos)
            on_play      =     play_button.collidepoint(pos)
            on_stop      =     stop_button.collidepoint(pos)
            on_question  = question_button.collidepoint(pos)
            on_gear      =     gear_button.collidepoint(pos)
            on_filter    =   filter_button.collidepoint(pos)
            on_h2o2      =     h2o2_button.collidepoint(pos)
            on_volume    =   volume_button.collidepoint(pos)
            on_length    =   length_button.collidepoint(pos)
            
            
            #printer.p(OOO+"zerogAlive === about to go into the buttons...")
            oldTarg0 = layer0
            oldTarg1 = layer1
            oldTarg2 = layer2
            oldTarg3 = layer3
            oldTarg4 = layer4

            #================== BUTTON AND SCREEN BRANCHING FLOW CHART ==================
            #
            screens_BEGIN=mainscreen+2*floatscreen+4*maintenancescreen
            if mainscreen:
                layer0=nonemin
                if floatpreset==60: layer0 = sixtymin
                if floatpreset==90: layer0 = ninetymin
                if floatpreset==-1: layer0 = custommin
                if on_sixtymin    : layer0 = sixtymin
                if on_ninetymin   : layer0 = ninetymin
                if on_custommin   : layer0 = custommin
                
                if      on_exit and go: alive = False
                if      on_exit and go: printer.p(OOO+"zerogAlive === ending...")
                
                if not floatscreen and not maintenancescreen:
                    if  on_sixtymin and go: floatpreset=60
                    if on_ninetymin and go: floatpreset=90
                    if on_custommin and go: floatpreset=-1
                    #if on_custommin and go: printer.fout('custom_duration',str(custom_duration))
                    
                    if (on_sixtymin or on_ninetymin or on_custommin) and go: 
                        floatscreen = True
                        if floatpreset==-1: min_float = math.floor(custom_duration)-2*min_fade
                        else: min_float = floatpreset-2*min_fade
                        #printer.fout('min_float',str(min_float))
                        printer.fout('floatpreset',str(floatpreset))
                        printer.fout('floatscreen',str(floatscreen))
                
                if on_gear and go: 
                    maintenancescreen=True
                    printer.fout('maintenancescreen',str(maintenancescreen))
                    if manualfilter: layer1=filter
                    if manualh2o2: layer2=h2o2
                
                if floatscreen and not maintenancescreen:
                    if on_back and go: 
                        floatscreen=False
                        printer.fout('floatscreen',str(floatscreen))
                    layer0=play
                 
                    if not manualfilter and not manualh2o2:
                        if on_play and go: prog=0
                        if on_play and go: floatstart=time.time()
                        if on_play and go: floatInProgress=True
                        if on_play and go: printer.fout('floatstart',str(floatstart))
                        if on_play and go: printer.fout('floatInProgress',str(floatInProgress))
                        
                        if on_play and go: playfloat=True 
                        if on_play and go: printer.fout('playfloat',str(playfloat))
                        if on_stop and mouseL:
                            stopcount=True
                            countdown_num=3-(time.time()-countdownstart)
                            if countdown_num<0:
                                playfloat=False
                                printer.fout('playfloat',str(playfloat))
                                printer.fout('floatInProgress',str(floatInProgress))
                                countdown_num=0
                                stopcount=False
                                
                        else: 
                            stopcount=False
                            countdown_num=3
                            countdownstart=time.time()
                    
                    else:    
                        if on_play and go: overrideWarning=time.time()
                        #else: overrideWarning=False
               
                    if playfloat:
                        layer0=stop
                        prog=math.floor(floatelapsed/60/totalDuration*gradBarWidth)
                        
                if maintenancescreen:
                    layer0=settings
                    if on_back and go: printer.fout('custom_duration',str(custom_duration))
                    if on_back and go: printer.fout('max_vol',str(max_vol))
                    if on_back and go: layer0=layer1=layer2=layer3=layer4=0
                    if on_back and go: 
                        maintenancescreen=False
                        printer.fout('maintenancescreen',str(maintenancescreen))
                    
                    #if floatInProgress and phase==4
                    if on_sleep and go: sleepMode=not sleepMode
                        
                    if not floatInProgress:
                        if on_filter and go: manualfilter = not manualfilter
                        if on_filter and go: printer.fout('manualfilter',str(manualfilter))
                        if on_filter and go   and   manualfilter: layer1 = filter
                        if on_filter and go and not manualfilter: layer1 = 0
                        
                        if on_h2o2 and go: manualh2o2 = not manualh2o2
                        if on_h2o2 and go: printer.fout('manualh2o2',str(manualh2o2))
                        if on_h2o2 and go   and   manualh2o2: layer2 = h2o2
                        if on_h2o2 and go and not manualh2o2: layer2 = 0
                    
                    if on_volume and mouseL: 
                        max_vol=(pos[0]-10-volume_button.left) / volume_button.width
                        if max_vol<0: max_vol=0
                        if max_vol>1: max_vol=1
                    
                    if on_length and mouseL:
                        stepper=(pos[0]-length_button.left) / length_button.width - .5
                        
                        if stepper<0 and stepperSpeed==0: custom_duration-=1
                        if stepper>0 and stepperSpeed==0: custom_duration+=1
                        
                        if stepper<0: custom_duration-=stepperSpeed*fm
                        if stepper>0: custom_duration+=stepperSpeed*fm
                        
                        if  stepperSpeed<.5: stepperSpeed+=.001*fm
                        elif stepperSpeed<2: stepperSpeed*=1.1
                        
                        if custom_duration<2*min_fade: custom_duration=2*min_fade
                        if custom_duration>999.9: custom_duration=999
                        
                        #if floatpreset!=60 and floatpreset!=90: 
                        floatpreset=math.floor(custom_duration)
                        foutTheNewCustomDuration=True
                        
                    elif foutTheNewCustomDuration:
                        printer.fout('custom_duration',str(custom_duration))
                        foutTheNewCustomDuration=False
                    else: 
                        stepperSpeed=0
                    
            screens_END=mainscreen+2*floatscreen+4*maintenancescreen
            if screens_BEGIN!=screens_END and floatscreen or reloaded: drawgradbar()
            if reloaded: reloaded=False
            
            if oldTarg0!=layer0: alpha0=minAlpha
            if oldTarg1!=layer1: alpha1=minAlpha
            if oldTarg2!=layer2: alpha2=minAlpha
            if oldTarg3!=layer3: alpha3=minAlpha
            
            if on_question and mouseL and not maintenancescreen and not floatscreen: phonealpha+=alphaStep*fm
            elif phonealpha>0: phonealpha-=alphaStep*fm
            if phonealpha<0: phonealpha=0
            
            
            alpha0+=alphaStep*fm
            alpha1+=alphaStep*fm
            alpha2+=alphaStep*fm
            gradalpha+=alphaStep*fm
            
            if alpha0>255: alpha0=255
            if alpha1>255: alpha1=255
            if alpha2>255: alpha2=255
            if gradalpha>255: gradalpha=255
            
            if layer0: layer0.set_alpha(alpha0)
            if layer1: layer1.set_alpha(alpha1)
            if layer2: layer2.set_alpha(alpha2)
            
            if layer0: stage.blit(layer0,(0,0))
            if layer1: stage.blit(layer1,(153,42))
            if layer2: stage.blit(layer2,(422,42))
            
            if maintenancescreen:
                for x in range(0,6):
                    a=0
                    if max_vol>x/6: a=255
                    elif max_vol>(x-.75)/6: a=64
                    elif max_vol>(x-.50)/6: a=128
                    elif max_vol>(x-.25)/6: a=192
                    volume.set_alpha(math.floor(a))
                    stage.blit(volume,(174+x*26,316))
                
                floatlengthbar(str(math.floor(custom_duration)))
                        
            if not maintenancescreen: 
                tankname()
                if floatscreen:
                    gradbar()
                    statusbar(status_str)
                    if playfloat:
                        #screen.blit(progbar,(gradBarLeft-gradBarWidth+prog,gradBarTop-vOffset))
                        progbar.set_alpha(alpha0*.7)
                        stage.blit(progbar,(gradBarLeft-gradBarWidth+prog,gradBarTop-vOffset))
                        #playfloat: 
                        #if 
                        #else: 
                        #playBAK.blit(progbar,(gradBarLeft-gradBarWidth+prog,gradBarTop-vOffset))
        
                        x=gradBarLeft+prog
                        pygame.draw.line(screen, (0,255,0), (x,gradBarTop-vOffset),(x,gradBarTop+gradBarHeight-vOffset-1), 1)

            screen.blit(stage,(0,0))
            tfade=1
            tlights=False
            if floatInProgress:
                tfade=0
                tlights=True
                phase=PHASE_SHOWER
                status_str="SHOWER"
                
                if floatelapsed/60>min_shower:
                    phase=PHASE_FADE1
                    status_str="FADE"
                    tfade=(floatelapsed/60-min_shower)/min_fade
                    if tfade>1: tfade=1
                
                if floatelapsed/60>min_shower+min_fade: 
                    tlights=False
                    phase=PHASE_FLOAT
                    status_str="FLOAT"
                
                if floatelapsed/60>min_shower+min_fade+min_float:
                    tlights=True
                    phase=PHASE_FADE2
                    status_str="FADE"
                    tfade=1-(floatelapsed/60-(min_shower+min_fade+min_float))/min_fade
                    if tfade<0: tfade=0
                
                if floatelapsed/60>min_shower+2*min_fade+min_float: 
                    phase=PHASE_WAIT
                    status_str="SHOWER"
                    
                if floatelapsed/60>min_shower+2*min_fade+min_float+min_wait: 
                    phase=PHASE_PLO
                    status_str="FILTER"
                
                if floatelapsed/60>min_shower+2*min_fade+min_float+min_wait+min_plo: 
                    phase=PHASE_PHI
                    if floatelapsed/60<min_shower+2*min_fade+min_float+min_wait+min_plo+min_uv: phase+=PHASE_UV
                    if floatelapsed/60<min_shower+2*min_fade+min_float+min_wait+min_plo+min_h2o2: phase+=PHASE_H2O2
                
                if tfade>0:
                    blackout.set_alpha(tfade*192)
                    screen.blit(blackout,(0,0))
                    #if floatscreen and not maintenancescreen: screen.blit(blackout,(0,0))
                
                if floatelapsed/60>totalDuration:
                    playfloat=False
                    floatInProgress=False
                    phase=PHASE_SHUTOFF
                    printer.fout('playfloat',str(playfloat))
                    printer.fout('floatInProgress',str(floatInProgress))
                                                    
            else:
                tlights=True
                phase=PHASE_NONE
                status_str="READY"
                tfade=fade
                if tfade>0: tfade-=.01
                if tfade<0: tfade=0
            #set the actual fade just once! otherwise every so often the other thread will call on it before it is prepared ;)
            
            if not playfloat: floatInProgress=False
            if not floatInProgress: floatstart=time.time()
            if phonealpha>0: myPhoneNumber()
            if stopcount:
                blackout.set_alpha(192)# -(255-alpha0)/255*fade)
                countdown=tankname_font.render(str(math.floor(countdown_num+1)), 1, (164,154,144))
                screen.blit(blackout,(0,0))
                screen.blit(countdown, (400-countdown.get_rect().width/2,240-countdown.get_rect().height/2))

            if overrideWarning!=False:
                th=(time.time()-overrideWarning)/2*3.14
                if th>2*3.14: overrideWarning=False
                a=(.5-math.cos(th)/2)*192
                print(str(th))
                reasonSurface.set_alpha(a)
                screen.blit(reasonSurface, (0,0))
        
            #if lightMode:
            #    #tfade=0
            #    
            #if alertMode:
            #    #tfade=.5+.5*math.sin((time.time()/3)*3.14)
            #    #amber.set_alpha(DIM*255)
            #    #screen.blit(amber,(0,0))
            
            if sleepMode:
                #tlights=False
                if tfade<1: tfade+=.1
                if tfade>1: tfade=1
                blackout.set_alpha(128)
                screen.blit(blackout,(0,0))
            
            lightsOkay=tlights
            fade=tfade
                        
            #floatelapsed=(time.time()-floatstart)*10+60*min_shower
            #floatelapsed=(time.time()-floatstart)*1+60*(min_shower-20/60)
            #floatelapsed=(time.time()-floatstart)*20+60*(min_shower+1*min_fade)
            #floatelapsed=(time.time()-floatstart)*20+60*(min_shower+1*min_fade+min_float)
            #floatelapsed=(time.time()-floatstart)*20+60*(min_shower+2*min_fade+min_float)
            #floatelapsed=(time.time()-floatstart)*20+60*(min_shower+2*min_fade+min_float+min_wait-1)
            #floatelapsed=(time.time()-floatstart)*20+60*(min_shower+2*min_fade+min_float+min_wait+min_plo)
            #floatelapsed=(time.time()-floatstart)*40
        
            #================ ================ ================ ================ ================ 
            floatelapsed=(time.time()-floatstart)   #this is the not-testing-for one
            #================ ================ ================ ================ ================ 
            
            #debug = default_font.render(debugstring,1,(190,190,178))
            #screen.blit(debug, (565, 400))
            
            #================ ACTUALLY DRAW TARGET ZONES FOR TESTING ======================
            #
            #sixtymin_buttonTARG  = pygame.draw.rect(screen, (100,0,0),sixtymin_button, 2)
            #ninetymin_buttonTARG = pygame.draw.rect(screen, (0,100,0),ninetymin_button, 2)
            #custommin_buttonTARG = pygame.draw.rect(screen, (0,0,100),custommin_button, 2)
            #back_buttonTARG      = pygame.draw.rect(screen, (0,0,100),back_button, 2)
            #sleep_buttonTARG     = pygame.draw.rect(screen, (0,0,100),sleep_button, 2)
            #play_buttonTARG      = pygame.draw.rect(screen, (0,100,0),play_button, 2)
            #stop_buttonTARG      = pygame.draw.rect(screen, (100,0,0),stop_button, 2)
            #question_buttonTARG  = pygame.draw.rect(screen, (0,100,0),question_button, 2)
            #gear_buttonTARG      = pygame.draw.rect(screen, (100,0,0),gear_button, 2)
            #filter_buttonTARG    = pygame.draw.rect(screen, (0,100,0),filter_button, 2)
            #h2o2_buttonTARG      = pygame.draw.rect(screen, (0,0,100),h2o2_button, 2)
            #volume_buttonTARG    = pygame.draw.rect(screen, (0,0,100),volume_button, 2)
            #length_buttonTARG    = pygame.draw.rect(screen, (0,100,0),length_button, 2)
            #exit_buttonTARG      = pygame.draw.rect(screen, (0, 0, 0),exit_button, 2)    
            #

            pygame.display.update()
            
    #=============================================================================================================================================================#

    printer.goodbye(myname,version)
コード例 #28
0
def actionThread():
    OOO="         "
    printer.p(OOO+"actionThread === checking in...")    
    global session
    global fthermo
    global jack_unplugged,jack_plugged_in,jack_in_use
    global unfaded,faded_out
    global lastPrint,pdelay
    global lightMode,alertMode
    global extraWhite
    
    try:
        amp = MAX9744() #amp = MAX9744(busnum=2, address=0x4C)
        amp.set_volume(0)
        noAmp=False
    except Exception:
        noAmp=True
        pass
    
    thermo="I can't feel the water"
    alert="No alert, probably"
    status = "Just getting warmed up..."

    DIM=0
    VOL=0
    h12hot=time.time()
    h12cool=time.time()
        
    printer.p(OOO+"actionThread === entering circuit...")    
    while zerog.alive:
        try:
            filtermode=zerog.manualfilter
            h2o2mode=zerog.manualh2o2
            session=zerog.floatInProgress
            custom_session_duration=math.floor(zerog.custom_duration)
            zerog.cur_temp=thermoString
            
            if session:
                if zerog.phase==zerog.PHASE_SHUTOFF:
                    statusstring="Ready to float :)"
                    GPIO.output(p_plo, OFF)
                    GPIO.output(p_phi, OFF)
                    GPIO.output(p_h2o2, OFF)
                    GPIO.output(p_uv, OFF)
                    zerog.phase=zerog.PHASE_NONE
                
                bit1=zerog.phase%10
                bit2=(zerog.phase-bit1)%100
                bit3=zerog.phase-bit1-bit2
                if bit1==zerog.PHASE_PHI:
                    GPIO.output(p_plo, OFF)
                    GPIO.output(p_phi, ON)
                    if bit2==zerog.PHASE_UV: GPIO.output(p_uv, ON)
                    else: GPIO.output(p_uv, OFF)
                    if bit3==zerog.PHASE_H2O2: GPIO.output(p_h2o2, ON)
                    else: GPIO.output(p_h2o2, OFF)
                
                if zerog.phase==zerog.PHASE_PLO: GPIO.output(p_plo, ON)
                
            elif filtermode or h2o2mode:
                if filtermode:
                    GPIO.output(p_plo, OFF)
                    GPIO.output(p_phi, ON)
                    GPIO.output(p_uv, ON)
                else:
                    GPIO.output(p_phi, OFF)
                    GPIO.output(p_uv, OFF)
                if h2o2mode:
                    GPIO.output(p_h2o2, ON)
                else:
                    GPIO.output(p_h2o2, OFF)

            else:
                GPIO.output(p_plo, OFF)
                GPIO.output(p_phi, OFF)
                GPIO.output(p_h2o2, OFF)
                GPIO.output(p_uv, OFF)
                statusstring="Ready to float :)"

            oldVOL=VOL
            VOL=(1-zerog.fade)*zerog.max_vol
            if oldVOL != VOL:
                if not noAmp:
                    ampvol=math.floor(VOL*63)
                    if ampvol<0: ampvol=0
                    if ampvol>63: ampvol=63
                    amp.set_volume(ampvol)

            thermotarg=93.5
            calThermo=thermo_calibrate(fthermo)
  
            topHeatOn=3*60
            topHeatOff=5*60
            if printer.myID=='Harmony-DEVI': 
                topHeatOn=60
                topHeatOff=5*60
            if printer.myID=='Portland-DEVI1': 
                topHeatOn=15
                topHeatOff=4*60
            
            if calThermo<thermotarg and GPIO.input(p_heater1) and time.time()-h12cool>topHeatOn:
                GPIO.output(p_heater1,ON)
                GPIO.output(p_heater2,ON)
                h12hot=time.time()
            if (calThermo>thermotarg or time.time()-h12hot>topHeatOff) and not GPIO.input(p_heater1):
                GPIO.output(p_heater1,OFF)
                GPIO.output(p_heater2,OFF)
                h12cool=time.time()
            
            if calThermo<thermotarg and GPIO.input(p_heater3):
                GPIO.output(p_heater3,ON)
                GPIO.output(p_heater4,ON)
            if calThermo>thermotarg+.5 and not GPIO.input(p_heater3):
                GPIO.output(p_heater3,OFF)
                GPIO.output(p_heater4,OFF)
            
            if GPIO.input(p_user): #and time.time()-userElapse>.5:
                #print("USER LIGHT TRUE");
                zerog.lightMode=True
                lightMode=True
            if not GPIO.input(p_user):
                #userElapse=time.time()
                #print("USER LIGHT FALSE");
                zerog.lightMode=False
                lightMode=False

            if zerog.fade==1 and unfaded: unfaded=False
            if zerog.fade!=1 and faded_out: faded_out=False
            
            if printer.myID!='Portland-DEVI1':
                if GPIO.input(p_alert):
                    #alert.set("Emergency Light On")
                    zerog.alertMode=True
                    alertMode=True
                if not GPIO.input(p_alert):
                    alertElapse=time.time()
                    #alert.set("Emergency Light Off")
                    zerog.alertMode=False
                    alertMode=False
            else: 
                zerog.alertMode=False
                alertMode=False
            
            if not GPIO.input(p_audio) and not jack_in_use:
                jack_plugged_in=True
                jack_in_use=True
            elif GPIO.input(p_audio) and jack_in_use:
                jack_unplugged=True
                jack_in_use=False
            if nojack:
                jack_in_use=False
                jack_plugged_in=False
                
            #zerog.debugstring=statusstring
            
            if time.time()-lastPrint>pdelay: #and zerog.phase>0:
                #pdelay+=.1
                lastPrint=time.time()
                #printer.p("phase: "+str(zerog.phase))
                
                pre=OOO+"actionThread === "
                br="<br>"+pre
                statusstring=pre+"=========================="
                statusstring+=br+"session      : "+str(session)
                statusstring+=br+"min_float    : "+str(zerog.min_float+2*zerog.min_fade)
                statusstring+=br+"temperature  : "+thermoString
                statusstring+=br+"raw temp     : "+str(fthermo)
                statusstring+=br+"times        : "+zerog.timeleft_str
                statusstring+=br+"phase        : "+zerog.dephaser()
                statusstring+="<br>"
                statusstring+=br+"fade         : "+str(math.floor(zerog.fade*100))+"%"
                statusstring+=br+"lightsOkay   : "+str(zerog.lightsOkay)
                statusstring+=br+"extraWhite   : "+str(extraWhite)
                statusstring+="<br>"
                statusstring+=br+"jack_in_use  : "+str(jack_in_use)
                statusstring+=br+"p_user|alert : "+bool_to_on_off(GPIO.input(p_user))+"|"+bool_to_on_off(GPIO.input(p_alert))
                statusstring+=br+"p_heater1234 : "+heaterString()
                statusstring+="<br>"
                statusstring+=br+"man_filter   : "+str(filtermode)
                statusstring+=br+"man_h2o2     : "+str(h2o2mode)
                statusstring+=br+"max_vol      : "+str(math.floor(zerog.max_vol*100))+"%"
                statusstring+=br+"cust_dur     : "+str(custom_session_duration)
                statusstring+="<br>"
                statusstring+=br+"pdelay       : "+str(math.floor(pdelay*10))+"ds"
                printer.p(statusstring)
        except:
            zerog.alive=False

    #cleanup on exit
    GPIO.output(p_plo, False)
    GPIO.output(p_phi, False)
    GPIO.output(p_h2o2, False)
    GPIO.output(p_uv, False)
    GPIO.output(p_heater1, False)
    GPIO.output(p_heater2, False)
    GPIO.output(p_heater3, False)
    GPIO.output(p_heater4, False)
    GPIO.cleanup()
    pygame.mixer.music.stop()
    try:
        global client
        amp.set_volume(0)
        color = [ (0,0,0) ] * numLEDs
        client.put_pixels(color)
    except Exception:
        pass
コード例 #29
0
    
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')

#tester:
try:
    fns = [fn for fn in os.listdir("/sys/bus/w1/devices/")]
    if str(fns[0][:2])=="28": thermoID=str(fns[0])
    else: thermoID=str(fns[1])
    thermo_sensor = '/sys/bus/w1/devices/'+thermoID+'/w1_slave'
except:
    thermo_sensor = ''
    pass

    
printer.p("!!!!!!!!!"+thermo_sensor)

#if printer.myID=='Harmony-DEVI': thermo_sensor = '/sys/bus/w1/devices/28-00152c2849ee/w1_slave'
#if printer.myID=='Portland-DEVI1': thermo_sensor = '/sys/bus/w1/devices/?-?/w1_slave'

#portland??

thermoString="I can't feel the water"
fthermo=0

session_60=True
session_90=False
session_custom=False
filtermode=False
h2o2mode=False
コード例 #30
0
def quit(data):
    """Quit the game."""
    data["want_to_play"] = False
    printer.p("{.BLUE}[Goodbye!]{.ENDC}".format(
        printer.PColors, printer.PColors), "Saving game! See you later!")
    prep_data_on_close(data)
コード例 #31
0
#=============================================================================================================================================================#

myname = "loader.py"
version = "v3.11"

#=============================================================================================================================================================#
from subprocess import call

try:
    import sys
    sys.path.insert(0, '/home/pi/Desktop/')
    import printer
    printer.hello(myname, version)

    while True:
        printer.p(
            "                                                                 Loader === Hi. I'm beginning a new cycle"
        )
        call(['python3', '/home/pi/Desktop/update.py'])
except:
    while True:
        call(['python3', '/home/pi/Desktop/update.py'])
    pass
コード例 #32
0
def callThread():
    OOO = "                            "
    printer.fileUpdate(ip, "cooperate.py", "cooperate.py")
    printer.p(OOO + "callThread === about to call cooperate...")
    call(['python3', '/home/pi/Desktop/cooperate.py'])
    printer.p(OOO + "callThread === ...checking out")
コード例 #33
0
    #
    #    "guiassets/main/60min.png",
    #    "guiassets/main/90min.png",
    #    "guiassets/main/custommin.png",
    #    "guiassets/main/nonemin.png"]
    #
    #    "splash.png", #?
    #    "asplashscreen",
    #
    "zerog.py"
]

#=============================================================================================================================================================#

msg = "                                  myID---from---" + myID + " || I || " + IDcheck + "---to---IDcheck"
printer.p(msg)

#----------------------------------------------------------------------I--------------------------------------------------------------------------------------#
import threading
import requests
import pyautogui
import time

from PIL import Image, ImageFile
#from subprocess import call
from threading import Thread

pyautogui.FAILSAFE = False
ImageFile.MAXBLOCK = 2**20
alive = True
コード例 #34
0
ファイル: loader.py プロジェクト: jayagopaldaz/zerog
#=============================================================================================================================================================#

myname="loader.py"
version="v3.11"

#=============================================================================================================================================================#
from subprocess import call

try:
    import sys
    sys.path.insert(0, '/home/pi/Desktop/')
    import printer
    printer.hello(myname,version)

    while True:
        printer.p("                                                                 Loader === Hi. I'm beginning a new cycle")
        call(['python3','/home/pi/Desktop/update.py'])
except:
    while True:
        call(['python3','/home/pi/Desktop/update.py'])
    pass
    
コード例 #35
0
ファイル: update.py プロジェクト: jayagopaldaz/zerog
def callThread():
    OOO="                            "
    printer.fileUpdate(ip,"cooperate.py","cooperate.py")
    printer.p(OOO+"callThread === about to call cooperate...")
    call(['python3','/home/pi/Desktop/cooperate.py'])
    printer.p(OOO+"callThread === ...checking out")