Exemple #1
0
def WriteReg(reg, data):
    print "Write Reg [", reg, "] =", data,
    if Click.WriteI2C(WR_PTR, reg >> 7, reg & 0x7F):
        if Click.WriteI2C(WR_IND, data, 0):
            print "OK"
            return
    #else
    print "Fail"
def ReadReg(reg):
    print "Read Reg [", reg, "] =",
    if Click.WriteI2C(WR_PTR, reg >> 7, reg & 0x7f):
        r = Click.ReadI2C(RD_IND)
        if r[0] == 0x21:
            print r[1]
            return
    #else
    print "Fail"
Exemple #3
0
def time(w, time):
    if not time:
        time = 500

    pygame.display.set_caption('Time Menu')

    lastMove = False

    while True:
        if type(time) == list:
            time = time[0]
        moveCheck = False

        x, y = pygame.mouse.get_pos()

        if pygame.mouse.get_pressed()[0]:
            if lastMove:
                if x >= 350 and x <= 850:
                    time = x
                elif x < 350:
                    time = 350
                elif x > 850:
                    time = 850

                moveCheck = True
            else:

                if x > time - 8 and x < time + 8:
                    if y > 492 and y < 508:
                        time = x
                        moveCheck = True
                if c.checkWithin(x, y, 0, 10, 160, 20):
                    #return time conversion here
                    return time
                elif c.checkWithin(x, y, 560, 580, 80, 40):
                    #return time conversion here
                    return time

        d.drawTime(w, x, y, time)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print("Goodbye!")
                pygame.quit()
                sys.exit()

        lastMove = moveCheck
Exemple #4
0
def roadMenu(w, inp):

    lastClick = False
    temp = None

    clock = pygame.time.Clock()

    while True:
        clickCheck = False

        x, y = pygame.mouse.get_pos()

        drawRoadMenu(w, inp, x, y)

        if pygame.mouse.get_pressed()[0]:
            if lastClick:
                if x < 350:
                    x = 350
                elif x > 850:
                    x = 850

                windowValue = inp.getSpecial()
                windowValue[temp - 1] = x
                inp.setSpecial(windowValue)
                clickCheck = True
            else:
                temp = inp.mouseOverSpecial(x, y)
                if temp:
                    print("Getting Special Values", inp.getSpecial())
                    values = inp.getSpecial()
                    values[temp - 1] = x
                    inp.setSpecial(values)
                    clickCheck = True

                elif click.checkWithin(x, y, 0, 10, 160,
                                       20) or click.checkWithin(
                                           x, y, 550, 625, 100, 50):
                    return inp

        clock.tick(60)
        lastClick = clickCheck

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print("Goodbye")
                sys.exit()
def field_click(num_on):
    if gtp.get_pixel_colour(xcoords2[5],ycoords2[5]) == colours[5] or gtp.get_pixel_colour(xcoords2[5],ycoords2[5]-20) == colours[5]:
        return 4
    py.scroll(-1000)
    if num_on == 2:
        py.click(394,423)
        t.sleep(.2)
        py.click(402,461,clicks=2)
        t.sleep(1)
    if num_on == 1:
        t.sleep(1)
        if gtp.get_pixel_colour(815,468) == (0,0,0):
            print("no fields to click...")
            return 2
    py.press(num_press,pause=.2)
    c.click(45,num_press)
    sleep_code = s.sleep(num_press)
    if sleep_code == 1:
        return 5
    elif sleep_code == 2:
        return 6
    py.press("d",pause=.2)
    py.scroll(-400)
    t.sleep(.5)
    if num_press == "1":
        if gtp.get_pixel_colour(xcoords2[1],ycoords2[1]) == colours[1] or gtp.get_pixel_colour(xcoords2[1],ycoords2[1]-20) == colours[1]:
            return 4
    elif num_press == "2":
        if gtp.get_pixel_colour(xcoords2[2],ycoords2[2]) == colours[2] or gtp.get_pixel_colour(xcoords2[2],ycoords2[2]-20) == colours[2]:
            return 4
    elif num_press == "3":
        if gtp.get_pixel_colour(xcoords2[3],ycoords2[3]) == colours[3] or gtp.get_pixel_colour(xcoords2[3],ycoords2[3]-20) == colours[3]:
            return 4
    elif num_press == "4":
        if gtp.get_pixel_colour(xcoords2[4],ycoords2[4]) == colours[4] or gtp.get_pixel_colour(xcoords2[4],ycoords2[4]-20) == colours[4]:
            return 4
    else:
        if gtp.get_pixel_colour(xcoords2[0],ycoords2[0]) == colours[0] or gtp.get_pixel_colour(xcoords2[0],ycoords2[0]-20) == colours[0]:
            return 4
    py.scroll(-400)
    return 0
Exemple #6
0
def Close():
    Click.Close()
Exemple #7
0
def Init():
    global I2C
    I2C = (Click.InitI2C() != None)
    return I2C
Exemple #8
0
def readError():
    if I2C:
        return Click.ReadI2C(RD_ERR)
    else:
        return 0
Exemple #9
0
def junctionMenu(w, inp):
    tolerance = 8
    lastClick = False
    while True:
        clickCheck = False

        x, y = pygame.mouse.get_pos()

        drawJunctionMenu(w, inp, x, y)

        if pygame.mouse.get_pressed()[0]:
            if click.checkWithin(x, y, 0, 10, 160, 20) or click.checkWithin(
                    x, y, 550, 625, 100, 50):
                print("Goodbye!")
                sys.exit()

            elif not lastClick:
                coord = 300
                special = inp.getSpecial()
                length = len(special)

                for prop in range(length):
                    if y > coord - tolerance and y < coord + tolerance:
                        if x > 450 - tolerance and x < 450 + tolerance:
                            print("P")
                            if "Pink" in special[prop]:
                                special[prop].remove("Pink")
                            else:
                                special[prop].append("Pink")

                        elif x > 550 - tolerance and x < 550 + tolerance:
                            print("B")
                            if "Blue" in special[prop]:
                                special[prop].remove("Blue")
                            else:
                                special[prop].append("Blue")

                        elif x > 650 - tolerance and x < 650 + tolerance:
                            print("G")
                            if "Green" in special[prop]:
                                special[prop].remove("Green")
                            else:
                                special[prop].append("Green")

                        elif x > 750 - tolerance and x < 750 + tolerance:
                            if inp.getTyp() == "4J":
                                print("O")
                                if "Orange" in special[prop]:
                                    special[prop].remove("Orange")
                                else:
                                    special[prop].append("Orange")

                    coord += 50
                if length > 1:
                    if y > coord - 57 - 8 and y < coord - 57 + 8:
                        if x > 778 - 8 and x < 778 + 8:
                            special.pop(length - 1)

                if length <= 7:
                    if y > coord - 16 and y < coord + 16:
                        if x > (600 - 16) and x < (600 + 16):
                            special.append([])

                inp.setSpecial(special)
            clickCheck = True

        clock.tick(60)
        lastClick = clickCheck

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print("Goodbye!")
                sys.exit()
Exemple #10
0
def unpack(num):
    print("================")
    print("Unpacking")
    print("================")

    if num==0:
        with open('./Saves/spareSave.pickle', 'rb') as handle:
            temp = pickle.load(handle)
    elif num==1:
        with open('./Saves/saveOne.pickle', 'rb') as handle:
            temp = pickle.load(handle)
    elif num==2:
        with open('./Saves/saveTwo.pickle', 'rb') as handle:
            temp = pickle.load(handle)

    listy=[]
    time=temp[0][0]
    for i in temp[1]:
        if i[4]=="RD":
            newObject=classy.Road(i[0], i[1])
        elif i[4]=="TL":
            newObject=classy.TrafficLight(i[0], i[1])
        elif i[4]=="4J":
            newObject=classy.FourJunction(i[0], i[1]) 
        elif i[4]=="TJ":
            newObject=classy.TJunction(i[0], i[1])
        elif i[4]=="TN":
            newObject=classy.Turn(i[0], i[1])
        
        newObject.setSpecial(i[5])
        newObject.setId(i[6])

        while i[3]!=newObject.rotation:
            c.rotate(newObject, [])
            newObject.defineGeometry()

        newObject.conns=i[2]
        
        updateInstance=newObject
        listy.append(newObject)
    
    
    newGroupList=unpackGroup(temp[2], listy)
    if not newGroupList:
        newGroupList=[]
    else:
        for group in newGroupList:
            group.infectGroup()

    try:
        updateInstance.updateGlobal(listy)
    except:
        pass
    
    print()
    print("Printing Unpacked Values")
    print("Printing Group List:", newGroupList)
    print("Printing Item List:", listy)
    print("Printing Time:", time)
    print()
    
    return listy, time, newGroupList
Exemple #11
0
def edit(w, obj):
    pygame.display.set_caption('Edit Menu')

    if obj.typ == "RD" or obj.typ == "TN":
        titleOne = "Length"
        titleTwo = ["Lane Distrobution One", "Lane Distrobution Two"]

    elif obj.typ == "TL":
        titleOne = "Time On"
        titleTwo = "Time Off"

    elif obj.typ == "4J" or "TJ":
        while True:
            x, y = pygame.mouse.get_pos()

            d.editJunction(w, x, y, obj.x, obj.y, obj, obj.rot, obj.states,
                           obj.exits)

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    print("Goodbye!")
                    pygame.quit()
                    sys.exit()

    valueOne, valueTwo = obj.getSpecial()

    if not valueOne:
        valueOne = 500
    if not valueTwo:
        valueTwo = 500

    savedX = obj.x + (obj.width / 2)
    savedY = obj.y + (obj.height / 2)

    image = pygame.transform.scale(obj.img, (150, 150))

    rotation = obj.rotation

    lastMove = False

    lines = [savedX, savedY, rotation]

    if type(valueOne) == int:
        lines.append(valueOne)
    else:
        for i in valueOne:
            lines.append(i)
    if type(valueTwo) == int:
        lines.append(valueTwo)
    else:
        for i in valueTwo:
            lines.append(i)

    print(lines)

    while True:

        moveCheck = False

        x, y = pygame.mouse.get_pos()

        tempList = d.drawEdit(w, x, y, lines[0], lines[1], image, lines[2],
                              valueOne, valueTwo, titleOne, titleTwo)

        if pygame.mouse.get_pressed()[0]:
            if lastMove:
                if x >= 350 and x <= 850:
                    lines[lineID] = x
                elif x < 350:
                    lines[lineID] = 350
                elif x > 850:
                    lines[lineID] = 850
                moveCheck = True

            else:
                print(lines, tempList, x, y)

                lineID = 0
                dontRepeat = False
                userAssist = 8

                for item in tempList:

                    if c.checkWithin(x, y, item[0] - userAssist,
                                     item[1] - userAssist, userAssist * 2,
                                     userAssist * 2) and dontRepeat == False:
                        print("Click")

                        lines[lineID] = x

                        moveCheck = True
                        dontRepeat = True

                    if not dontRepeat:
                        lineID += 1

                if c.checkWithin(x, y, 0, 10, 160, 20) and dontRepeat == False:
                    break

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print("Goodbye!")
                pygame.quit()
                sys.exit()

        lastMove = moveCheck
Exemple #12
0
# -*- coding: utf-8 -*-

from platform import python_version
import os
import socket
import datetime
import calendar
import Click

Click, OnRun = Click.CommandParser()


#support of flags with default values (python3 --version, python3 -V, python -v);
@Click('--version')
@Click('-v')
def OnGetVersion():
    return ("yk&yjb_1.0.0")


#support of position arguments (python3 module.py, cat file1 file2);
@Click('--path')
@Click('-p')
def OnDocumentRead(sPath):
    cwdpath = os.getcwd()
    path1 = os.path.join(cwdpath, sPath)
    sPathResult = path1.replace('\\', '/')

    with open('{}'.format(sPathResult), 'r') as f:
        return (f.read())

Exemple #13
0
def displayArray(a):
    for i, b in enumerate(a):
        Click.WriteWordSPI(i * 256 + (b & 0xff) + 256)
Exemple #14
0
#
# testing REDclick (SPI)
#

import Click
import time

Click.InitSPI()

# test all LEDs
# print Click.WriteWordSPI( 0x0F01)
# print Click.WriteWordSPI( 0x0F00)

# exit shutdown mode
Click.WriteWordSPI(0x0C01)
# set scan limit to 0-7
Click.WriteWordSPI(0x0B07)

a = [1, 2, 4, 8, 16, 32, 64, 128]


def displayArray(a):
    for i, b in enumerate(a):
        Click.WriteWordSPI(i * 256 + (b & 0xff) + 256)
        #print "0x%X" % (i*256 + b + 256),


while True:
    displayArray(a)
    a = map((lambda x: x << 1), a)
    time.sleep(0.1)
Exemple #15
0
def main(w, clock):
    pygame.display.set_caption('Design Phase')

    itemList = []
    groupList = []
    menu = 0
    saveImport = 0
    lastMove = False
    lastClick = False
    l = None
    time = None

    while True:
        clickCheck = False
        moveCheck = False

        clock.tick(60)

        x, y = pygame.mouse.get_pos()

        if pygame.mouse.get_pressed()[0]:
            clickCheck = True
            if lastMove:
                l.move(x, y, w)
                moveCheck = True
            else:
                if x > 1050 and x < 1190:  #Run GUI or MRS
                    if y > 740 and y < 770:
                        s.MRS()
                        break
                    elif y > 680 and y < 710:
                        s.GUI()
                        break

                if not lastClick:
                    if c.checkWithin(x, y, 0, 10, 160, 20):
                        print("Returning To Main Menu")
                        itemList[0].resetCounter()
                        break

                    l = c.checkMove(w, x, y, itemList)
                if l:
                    if l.typ == ("TM"):
                        pass
                    else:
                        moveCheck = True

                if not moveCheck and not lastClick:
                    quart = 0
                    if c.checkWithin(x, y, 1000, 0, 100, 30):
                        if saveImport == 0:
                            saveImport = 1
                        elif saveImport == 1:
                            p.pack(itemList, 1, time, groupList)
                            saveImport = 0
                        elif saveImport == 2:
                            itemList, time, groupList = p.unpack(1)
                            saveImport = 0

                    if c.checkWithin(x, y, 1100, 0, 100, 30):
                        if saveImport == 0:
                            saveImport = 2
                        elif saveImport == 1:
                            p.pack(itemList, 2, time, groupList)
                            saveImport = 0
                        elif saveImport == 2:
                            itemList, time, groupList = p.unpack(2)
                            saveImport = 0

                    elif c.checkWithin(x, y, 0, 700, 100, 100):
                        quart = 1
                    elif c.checkWithin(x, y, 100, 700, 100, 100):
                        quart = 2
                    if menu == 0:
                        if quart == 1:
                            length = len(itemList)
                            for x in range(length, 0, -1):
                                o = itemList[x - 1]
                                if o.checkInside(0, 600, 200, 800):
                                    itemList.remove(o)
                                    classy.Object.counterStorage.append(o.id)
                            menu = 1
                        elif quart == 2:
                            length = len(itemList)
                            for x in range(length, 0, -1):
                                o = itemList[x - 1]
                                if o.checkInside(0, 600, 200, 800):
                                    itemList.remove(o)
                                    classy.Object.counterStorage.append(o.id)
                            menu = 2

                    elif menu == 1 or menu == 2:
                        if quart == 2:
                            length = len(itemList)
                            for x in range(length, 0, -1):
                                o = itemList[x - 1]
                                if o.checkInside(0, 600, 200, 800):
                                    itemList.remove(o)
                                    classy.Object.counterStorage.append(o.id)
                            menu = 0
                    if menu == 2:
                        if c.checkWithin(x, y, 100, 600, 100, 100):
                            time = e.time(w, time)

        if lastMove and not clickCheck:
            if l.checkInside(200, 740, 240, 800):
                itemList.remove(l)
                classy.Object.counterStorage.append(l.id)
            """ elif onTop(l, itemList):
                itemList.remove(l) """

            e.snap(w, itemList, l)

            tempX = l.x + (l.width / 2)
            tempY = l.y + (l.height / 2)
            if l.typ == "ET":
                for i in itemList:
                    if i.checkWithin(tempX, tempY):
                        itemList.remove(l)
                        classy.Object.counterStorage.append(l.id)
                        if i != l:
                            if i.typ == "TL":
                                groupList.append(e.edit(w, i, itemList))
                            else:
                                i = e.edit(w, i, itemList)

                            clickCheck = True
                        break

            elif l.typ == "RO":
                for i in itemList:
                    if i.checkWithin(tempX, tempY):
                        itemList.remove(l)
                        classy.Object.counterStorage.append(l.id)
                        c.rotate(i, itemList)
                        i.defineGeometry()
                        clickCheck = True
                        break

        d.drawAll(w, x, y, itemList, menu, saveImport)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print("Goodbye!")
                pygame.quit()
                sys.exit()

        lastClick = clickCheck
        lastMove = moveCheck
    #else
    print "Fail"


def WriteReg(reg, data):
    print "Write Reg [", reg, "] =", data,
    if Click.WriteI2C(WR_PTR, reg >> 7, reg & 0x7F):
        if Click.WriteI2C(WR_IND, data, 0):
            print "OK"
            return
    #else
    print "Fail"


# init the Click I2C interface
Click.InitI2C()

# test the error cmd
#Write( WR_ERR, 0, 0)
#Read( RD_ERR)

#write to CCPR2L reg
WriteReg(0x298, 0x5A)

#write to DACCON1 reg
WriteReg(0x119, 0xA5)

# read register CCPR2L back
ReadReg(0x298)

# read register DACCON1 back