Example #1
0
def write():
    user_input = raw_input("DigiUSB#")
        user_input = user_input+"\n"
        theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df)
        for c in user_input:
            theDevice.write(ord(c))
            time.sleep(0.1)
Example #2
0
    def _main_loop(self):
        while True:
            try:
                self.led_usb = ArduinoUsbDevice(idVendor=0x16c0,
                                                idProduct=0x05df)
                led_usb = self.led_usb

                print("Found: 0x%04x 0x%04x %s %s" %
                      (led_usb.idVendor, led_usb.idProduct,
                       led_usb.productName, led_usb.manufacturer))

                while True:
                    if not self.blink:
                        self._set_color(self.color)
                        time.sleep(1)
                    else:
                        self._set_color(self.color)
                        time.sleep(self.on_time)
                        self._set_color((0, 0, 0))
                        time.sleep(self.off_time)
            except USBFailed:
                print("USB communication problem, retrying later")
                time.sleep(2)
            except USBDeviceNotFound:
                print("No USB device found, retrying later")
                time.sleep(2)
Example #3
0
def init_function():
    if len(sys.argv) == 1:
        print("Usage [<Mode>] [<param>..]")
        return

    mode = int(sys.argv[1])

    theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df)
    if theDevice is None:
        print("Cannot found the devie")
        return

    print("Found: 0x%04x 0x%04x %s %s" %
          (theDevice.idVendor, theDevice.idProduct, theDevice.productName,
           theDevice.manufacturer))

    # mode
    send_param(theDevice, mode)

    # params
    for x in range(2, len(sys.argv)):
        send_param(theDevice, int(sys.argv[x]))
        pass

    return
Example #4
0
def write():
    try:
        theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df)

        print "Found: 0x%04x 0x%04x %s %s" % (
            theDevice.idVendor, theDevice.idProduct, theDevice.productName,
            theDevice.manufacturer)
    except:
        pass

    while True:
        user_input = raw_input("DigiUSB#")
        user_input = user_input + "\n"
        theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df)
        for c in user_input:
            theDevice.write(ord(c))
            time.sleep(0.1)
Example #5
0
def send_to_digi(m_str):
    m_str += '\n'
    try:
       theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df)
    except:
       #sys.exit("No DigiUSB Device Found")
       return "ERROR: No DigiUSB Device Found"
    for c in m_str:
        theDevice.write(ord(c))
Example #6
0
    def __init__(self):
        try:
            self.device = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df)
        except:
            raise rospy.ROSException("No DigiUSB Device Found")

        rospy.init_node('temperature_sensor_publisher')

        self.pub = rospy.Publisher('temp', Temperature, queue_size=50)
        self.rate = 1.0
Example #7
0
    def connect(self):
        if self.DEBUG:
            print "Connecting Device"

        deviceBound = False
        while (not deviceBound):
            try:
                self.device = ArduinoUsbDevice(idVendor=0x16c0,
                                               idProduct=0x05df)
                deviceBound = True
            except Exception as e:
                print "Problem connecting:", e
                time.sleep(1)
                print 'retrying...'
Example #8
0
def read():
    try:
        theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df)

        print "Found: 0x%04x 0x%04x %s %s" % (theDevice.idVendor,
                                              theDevice.idProduct,
                                              theDevice.productName,
                                              theDevice.manufacturer)
    except:
        pass

    while True:
        try:
            theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df)
            try:
                sys.stdout.write(chr(theDevice.read()))
                sys.stdout.flush()
            except:
                # TODO: Check for exception properly
                time.sleep(0.5)

        except:
            # TODO: Check for exception properly
            time.sleep(1)
Example #9
0
def blink():
    theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df)

    red = request.query.get('red')
    green = request.query.get('green')
    blue = request.query.get('blue')

    print("red:{}, green:{}, blue:{}".format(red, green, blue))

    red = int(mapping(red))
    green = int(mapping(green))
    blue = int(mapping(blue))

    theDevice.write(ord("s"))
    theDevice.write(red)
    theDevice.write(green)
    theDevice.write(blue)

    print("mred:{}, mgreen:{}, mblue:{}".format(red, green, blue))
Example #10
0
def decrypty_(byte1, byte2):
    """
    """
    theDevice.write(byte1)
    theDevice.write(byte2)
    return chr(theDevice.read())


if __name__ == "__main__":

    if len(sys.argv) > 1:
        source = sys.argv[1]
    else:
        source = "13e971c3bd7ef968ac92174cbd63ca1ddb849f1e3161beb0a926b8e4af1c1338cecb02f34622a89e137c468f9e7060c33402ac3f8e044216bd96aca4062702f89cc7216ccfc9afb6"

    theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df)

    print "Found: 0x%04x 0x%04x %s %s" % (
        theDevice.idVendor, theDevice.idProduct, theDevice.productName,
        theDevice.manufacturer)

    bytes = [int(i + j, 16) for i, j in zip(source[::2], source[1::2])]
    un = "".join([
        decrypty_(byte1, byte2)
        for byte1, byte2 in zip(bytes[::2], bytes[1::2])
    ])

    print eval(un)

    raise SystemExit
def updateColor(setColor):
    global color
    if (color != setColor):
        color = setColor
        global taskbar_icon
        try:
            theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df)
            icon = color
            if (icon == "black"):
                icon = "white"
            taskbar_icon.set_icon("icons/"+icon+".png")
            #
            print "Color:"+color

            global red,green,blue,cyan,white,warmwhite,purple,magenta,yellow,orange,black
            if color == 'red':
                color_list = red
            elif color == 'green':
                color_list = green
            elif color == 'blue':
                color_list = blue
            elif color == 'cyan':
                color_list = cyan
            elif color == 'white':
                color_list = white
            elif color == 'warmwhite':
                color_list = warmwhite
            elif color == 'purple':
                color_list = purple
            elif color == 'magenta':
                color_list = magenta
            elif color == 'yellow':
                color_list = yellow
            elif color == 'orange':
                color_list = orange
            elif color == 'black':
                color_list = black





           # while 1:
                #pin = int(pin)



                #if output == "\r":
                #    print line
                #    line =""
                #else:
                #    line += output
                #else:
            
                #    print "Pin response didn't match."

            #byte val = sys.argv[1]
            print color_list
            theDevice.write(ord("s"))

            if color_list[0] == 0:
                theDevice.write(0)
            else:
                theDevice.write(int(color_list[0]))

            if color_list[1] == 0:
                theDevice.write(0)
            else:
                theDevice.write(int(color_list[1]))

            if color_list[2] == 0:
                theDevice.write(0)
            else:
                theDevice.write(int(color_list[2]))
        except:
            print "No device found"
Example #12
0
def logicloop(loopy):
    try:
        theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df)

    except:
        gui.alert(
            u'?? ???? ?? ???? ?????? ????? ??? ????? ????? \n ??? ?? ????? ????? ?? ????? ????'
        )

    try:

        f = open('data.txt', 'r')
        a = pickle.load(f)
        #print a, "Bombs So Far At:", time.ctime()

    except:
        a = 0

    b = 0
    f = open('pase.txt', 'w')
    pickle.dump(b, f)
    f.close()

    startime = time.time()
    f = open('startime.txt', 'w')
    pickle.dump(startime, f)
    f.close()

    c = 0
    f = open('shiftpase.txt', 'w')
    pickle.dump(c, f)
    f.close()

    shifttime = time.time()
    f = open('shifttime.txt', 'w')
    pickle.dump(shifttime, f)
    f.close()

    while True:
        lastChar = chr(theDevice.read())
        sys.stdout.flush()

        while (lastChar == "0"):

            lastChar = chr(theDevice.read())

            if (lastChar == "1"):
                winsound.PlaySound('bomb.wav', winsound.SND_FILENAME)

                f = open('data.txt', 'r')
                a = pickle.load(f)

                a = a + 1
                #print a, "Bombs So Far At:", time.ctime()

                ddelay = 0

                bombnum = a
                mywin['count'].left = '860'
                if (9 < a < 100):
                    mywin['count'].left = '790'
                if (99 < a < 1000):
                    mywin['count'].left = '720'
                if (999 < a):
                    mywin['count'].left = '660'
                mywin['count'].size = (0, 0)
                mywin['count'].text = u'%s' % (bombnum)
                mywin['count'].transparent = False
                mywin['count'].transparent = True
                mywin['count'].bgcolor = 'transparent'

                f = open('data.txt', 'w')
                pickle.dump(a, f)
                f.close()
                lastChar = chr(theDevice.read())

                mywin['statusbar'].text = u"???? ?????? ?????? ????: %s" % (
                    time.ctime())

                f = open('pase.txt', 'r')
                b = pickle.load(f)
                b = b + 1

                f = open('startime.txt', 'r')
                startime = pickle.load(f)

                pase = time.time()
                avg = (pase - startime)

                #print "time passed: ", avg
                avgpase = (b / avg) * 3600
                #print b
                #print "bomb pase: ", avgpase

                avgpase = int(avgpase)
                bombpase = avgpase
                print bombpase
                if (bombpase < 1):
                    mywin['bombpase'].fgcolor = u'#FFFFFF'
                    mywin['bombpase'].left = '800'
                    mywin['bombpase'].top = '500'
                    mywin['bombpase'].size = (0, 0)
                    mywin['bombpase'].text = u'--'
                    mywin['bombpase'].transparent = False
                    mywin['bombpase'].transparent = True
                    mywin['bombpase'].bgcolor = 'transparent'
                if (1 <= bombpase < 10):
                    mywin['bombpase'].fgcolor = u'#FFFFFF'
                    mywin['bombpase'].left = '800'
                    mywin['bombpase'].size = (0, 0)
                    mywin['bombpase'].text = u'%s' % (bombpase)
                    mywin['bombpase'].transparent = False
                    mywin['bombpase'].transparent = True
                    mywin['bombpase'].bgcolor = 'transparent'
                if (10 <= bombpase <= 33):
                    mywin['bombpase'].fgcolor = u'#FFFFFF'
                    mywin['bombpase'].left = '775'
                    mywin['bombpase'].top = '480'
                    mywin['bombpase'].size = (0, 0)
                    mywin['bombpase'].text = u'%s' % (bombpase)
                    mywin['bombpase'].transparent = False
                    mywin['bombpase'].transparent = True
                    mywin['bombpase'].bgcolor = 'transparent'
                if (34 <= bombpase <= 99):
                    mywin['bombpase'].fgcolor = u'#FFFFFF'
                    mywin['bombpase'].left = '775'
                    mywin['bombpase'].top = '480'
                    mywin['bombpase'].size = (0, 0)
                    mywin['bombpase'].text = u'%s' % (bombpase)
                    mywin['bombpase'].transparent = False
                    mywin['bombpase'].transparent = True
                    mywin['bombpase'].bgcolor = 'transparent'
                if (99 < bombpase):
                    mywin['bombpase'].fgcolor = u'#FFFFFF'
                    mywin['bombpase'].left = '780'
                    mywin['bombpase'].top = '500'
                    mywin['bombpase'].size = (0, 0)
                    mywin['bombpase'].text = u'--'
                    mywin['bombpase'].transparent = False
                    mywin['bombpase'].transparent = True
                    mywin['bombpase'].bgcolor = 'transparent'
                f = open('pase.txt', 'w')
                pickle.dump(b, f)
                f.close()

                f = open('shiftpase.txt', 'r')
                c = pickle.load(f)
                c = c + 1

                f = open('shifttime.txt', 'r')
                shifttime = pickle.load(f)

                shiftpase = time.time()
                shiftavg = (shiftpase - shifttime)

                #print "time passed: ", shiftavg
                shiftavgpase = (c / shiftavg) * 3600
                #print c
                #print "bomb pase: ", shiftavgpase

                shiftavgpase = int(shiftavgpase)
                shiftbombpase = shiftavgpase
                print shiftbombpase
                if (shiftbombpase < 1):
                    mywin['shiftbombpase'].fgcolor = u'#FFFFFF'
                    mywin['shiftbombpase'].left = '800'
                    mywin['shiftbombpase'].top = '700'
                    mywin['shiftbombpase'].size = (0, 0)
                    mywin['shiftbombpase'].text = u'--'
                    mywin['shiftbombpase'].transparent = False
                    mywin['shiftbombpase'].transparent = True
                    mywin['shiftbombpase'].bgcolor = 'transparent'
                if (1 <= shiftbombpase < 10):
                    mywin['shiftbombpase'].fgcolor = u'#FFFFFF'
                    mywin['shiftbombpase'].left = '800'
                    mywin['shiftbombpase'].size = (0, 0)
                    mywin['shiftbombpase'].text = u'%s' % (shiftbombpase)
                    mywin['shiftbombpase'].transparent = False
                    mywin['shiftbombpase'].transparent = True
                    mywin['shiftbombpase'].bgcolor = 'transparent'
                if (10 <= shiftbombpase <= 33):
                    mywin['shiftbombpase'].fgcolor = u'#FFFFFF'
                    mywin['shiftbombpase'].left = '775'
                    mywin['shiftbombpase'].top = '680'
                    mywin['shiftbombpase'].size = (0, 0)
                    mywin['shiftbombpase'].text = u'%s' % (shiftbombpase)
                    mywin['shiftbombpase'].transparent = False
                    mywin['shiftbombpase'].transparent = True
                    mywin['shiftbombpase'].bgcolor = 'transparent'
                if (34 <= shiftbombpase <= 99):
                    mywin['shiftbombpase'].fgcolor = u'#FFFFFF'
                    mywin['shiftbombpase'].left = '775'
                    mywin['shiftbombpase'].top = '680'
                    mywin['shiftbombpase'].size = (0, 0)
                    mywin['shiftbombpase'].text = u'%s' % (shiftbombpase)
                    mywin['shiftbombpase'].transparent = False
                    mywin['shiftbombpase'].transparent = True
                    mywin['shiftbombpase'].bgcolor = 'transparent'
                if (99 < shiftbombpase):
                    mywin['shiftbombpase'].fgcolor = u'#FFFFFF'
                    mywin['shiftbombpase'].left = '780'
                    mywin['shiftbombpase'].top = '700'
                    mywin['shiftbombpase'].size = (0, 0)
                    mywin['shiftbombpase'].text = u'--'
                    mywin['shiftbombpase'].transparent = False
                    mywin['shiftbombpase'].transparent = True
                    mywin['shiftbombpase'].bgcolor = 'transparent'
                f = open('shiftpase.txt', 'w')
                pickle.dump(c, f)
                f.close()

                while (ddelay < 50000000):
                    ddelay = ddelay + 1

                break
Example #13
0
    def __init__(self):

        self._digispark = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df)
        self.off()
Example #14
0
# The Blindinator v1.0 by Ivan Cooper & Meena Shah
# created for San Francisco Science Hack Day 2014

from SimpleCV import *
import usb, sys
from arduino.usbdevice import ArduinoUsbDevice
from collections import deque

try:
    USBlindinator = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df)
except:
    sys.exit("Blindinator Not Found")

# "calibration" given in servo values
pleft = 66
pright = 141
ptop = 59
pbottom = 111


class point(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y


def aim_and_fire():
    if lit:
        s = "*"
    else:
        s = "."