Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 49 lines (36 sloc) 1.539 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
#!/usr/bin/python
import usb.core
import time
import argparse

def initUSB ():
    dev = usb.core.find(idVendor=0x0403, idProduct=0xc630)
    
    if dev is None:
        raise ValueError('Device not found')
    
    return dev

def main ():
    parser = argparse.ArgumentParser(description="ping+ cli interface")
    parser.add_argument('-s', '--sendstring', help="Sends a string to the ping+")
    parser.add_argument('-c', '--clear', action="store_true", help="Clears the display by scrolling it out")
    parser.add_argument('-p', '--scrollspeed', type=int, help="Sets the scrolling speed")
    parser.add_argument('-w', '--waitdelay', type=int, help="Sets the wait delay")

    args = parser.parse_args()

    dev = initUSB()

    # Sends the clear command to the usb device and waits 0.5 seconds
    if (args.clear):
        dev.ctrl_transfer(0x40, 20, 0, 0)
        time.sleep(0.5)
    
    # Clears the off-screen buffer, sends the string to the usb device and copies the off-screen buffer to the main
    # buffer.
    if (args.sendstring):
        dev.ctrl_transfer(0x40, 10, 0, 0)
        
        for c in args.sendstring:
            dev.ctrl_transfer(0x40, 4, 0, ord(c))
        
        dev.ctrl_transfer(0x40, 5, 0, 0)
    
    # Sets the wait delay at the end of a line
    if (args.waitdelay):
        dev.ctrl_transfer(0x40, 25, args.waitdelay, 0)
    
    # Sets the scrolling speed
    if (args.scrollspeed):
        dev.ctrl_transfer(0x40, 26, args.scrollspeed, 0)

main()
print("All done. Type -h for help")
Something went wrong with that request. Please try again.