diff --git a/boards/pyruler/6.x/README.txt b/boards/pyruler/6.x/README.txt new file mode 100644 index 0000000..55947f6 --- /dev/null +++ b/boards/pyruler/6.x/README.txt @@ -0,0 +1,66 @@ +Welcome to CircuitPython! +############################# + +Time to set the record STRAIGHT: CircuitPython RULEs and don't try to argue, +we won't budge an INCH! With this 6" long dev board, you can see how +CircuitPython deveopment MEASURES up against the standard compile/upload +cycle with a handy reference guide to common packages. + +Best of all, this ruler is smart! You can plug it into your computer, and +turn it into a 4-button keypad that will type those pesky Ohm, Mu and Pi +symbols (see below on how to do that). + +We worked with Digi-Key, our favorite electronics component supplier, to +design this super cool ruler and have it released in celebration of +CircuitPython day, which we observe on August 8 every year. (8/8 is the +snakiest of dates, don't you agree?) + +Visit the PyRuler product page here for more info: + https://adafruit.com/product/4319 + +For the latest version of CircuitPython for this board, visit + https://circuitpython.org/board/pyruler/ + +############################# + +The PyRuler has a very tiny disk drive so we have disabled Mac OS X indexing +which could take up that valuable space. + +So *please* do not remove the empty .fseventsd/no_log, .metadata_never_index +or .Trashes files! + +############################# + +The pre-loaded demo shows off what your PyRuler can do with CircuitPython. +All the code is stored in a code.py file. Edit it with the Mu code editor and +save to restart the program. +The demo program watches for capacitive finger touches on the 4 pads and will +light up the matching LED to let you know it was detected. + +You can turn the PyRuler into a keyboard! Edit code.py and find the line that asays + +# Set this to True to turn the touchpads into a keyboard +ENABLE_KEYBOARD = False + +Change the 'False' value to 'True' and save. Now when you touch the Ohm, Mu, +or Pi symbol, that key will be typed out. +Open up your browser, click on the address bar and touch the Digi-Key logo for + +For more details on how to use CircuitPython, visit + https://adafruit.com/product/4319 +and check out all the tutorials we have! +The PyRuler contains the circuitry for a Trinket M0 so you may also want to +visit + https://adafruit.com/product/3500 +To learn more about the amazing projects you can build with a Trinket M0 + +############################# +CircuitPython Quick Start: + +Changing the code is as easy as editing main.py in your favorite text editor. +We recommend Mu, Atom, Notepad++, or Visual Studio Code. After the file is +saved, CircuitPython will automatically reload the latest code. + +Connecting to the serial port will give you access to better error messages and +interactive CircuitPython (known as the REPL). On Windows we recommend +Tera Term or PuTTY. On Mac OSX and Linux, 'screen' can be used from a terminal. diff --git a/boards/pyruler/6.x/code.py b/boards/pyruler/6.x/code.py new file mode 100644 index 0000000..dca25f1 --- /dev/null +++ b/boards/pyruler/6.x/code.py @@ -0,0 +1,132 @@ +import os +import board +from digitalio import DigitalInOut, Direction +import time +import touchio + +# Set this to True to turn the touchpads into a keyboard +ENABLE_KEYBOARD = False + +WINDOWS = "W" +MAC = "M" +LINUX = "L" # and Chrome OS + +# Set your computer type to one of the above +OS = WINDOWS + +# Used if we do HID output, see below +if ENABLE_KEYBOARD: + import usb_hid + from adafruit_hid.keyboard import Keyboard + from adafruit_hid.keycode import Keycode + from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS + kbd = Keyboard(usb_hid.devices) + layout = KeyboardLayoutUS(kbd) + +#print(dir(board), os.uname()) # Print a little about ourselves + +led = DigitalInOut(board.D13) +led.direction = Direction.OUTPUT + +touches = [DigitalInOut(board.CAP0)] +for p in (board.CAP1, board.CAP2, board.CAP3): + touches.append(touchio.TouchIn(p)) + +leds = [] +for p in (board.LED4, board.LED5, board.LED6, board.LED7): + led = DigitalInOut(p) + led.direction = Direction.OUTPUT + led.value = True + time.sleep(0.25) + leds.append(led) +for led in leds: + led.value = False + + +cap_touches = [False, False, False, False] + +def read_caps(): + t0_count = 0 + t0 = touches[0] + t0.direction = Direction.OUTPUT + t0.value = True + t0.direction = Direction.INPUT + # funky idea but we can 'diy' the one non-hardware captouch device by hand + # by reading the drooping voltage on a tri-state pin. + t0_count = t0.value + t0.value + t0.value + t0.value + t0.value + \ + t0.value + t0.value + t0.value + t0.value + t0.value + \ + t0.value + t0.value + t0.value + t0.value + t0.value + cap_touches[0] = t0_count > 2 + cap_touches[1] = touches[1].raw_value > 3000 + cap_touches[2] = touches[2].raw_value > 3000 + cap_touches[3] = touches[3].raw_value > 3000 + return cap_touches + +def type_alt_code(code): + kbd.press(Keycode.ALT) + for c in str(code): + if c == '0': + keycode = Keycode.KEYPAD_ZERO + elif '1' <= c <= '9': + keycode = Keycode.KEYPAD_ONE + ord(c) - ord('1') + else: + raise RuntimeError("Only number codes permitted!") + kbd.press(keycode) + kbd.release(keycode) + kbd.release_all() + +while True: + caps = read_caps() + print(caps) + # light up the matching LED + for i,c in enumerate(caps): + leds[i].value = c + if caps[0]: + if ENABLE_KEYBOARD: + if OS == WINDOWS: + type_alt_code(234) + elif OS == MAC: + kbd.send(Keycode.ALT, Keycode.Z) + elif OS == LINUX: + kbd.press(Keycode.CONTROL, Keycode.SHIFT) + kbd.press(Keycode.U) + kbd.release_all() + kbd.send(Keycode.TWO) + kbd.send(Keycode.ONE) + kbd.send(Keycode.TWO) + kbd.send(Keycode.SIX) + kbd.send(Keycode.ENTER) + if caps[1]: + if ENABLE_KEYBOARD: + if OS == WINDOWS: + type_alt_code(230) + elif OS == MAC: + kbd.send(Keycode.ALT, Keycode.M) + elif OS == LINUX: + kbd.press(Keycode.CONTROL, Keycode.SHIFT) + kbd.press(Keycode.U) + kbd.release_all() + kbd.send(Keycode.ZERO) + kbd.send(Keycode.THREE) + kbd.send(Keycode.B) + kbd.send(Keycode.C) + kbd.send(Keycode.ENTER) + if caps[2]: + if ENABLE_KEYBOARD: + if OS == WINDOWS: + type_alt_code(227) + elif OS == MAC: + kbd.send(Keycode.ALT, Keycode.P) + elif OS == LINUX: + kbd.press(Keycode.CONTROL, Keycode.SHIFT) + kbd.press(Keycode.U) + kbd.release_all() + kbd.send(Keycode.ZERO) + kbd.send(Keycode.THREE) + kbd.send(Keycode.C) + kbd.send(Keycode.ZERO) + kbd.send(Keycode.ENTER) + if caps[3]: + if ENABLE_KEYBOARD: + layout.write('https://www.digikey.com/python\n') + time.sleep(0.1) diff --git a/boards/pyruler/6.x/lib/adafruit_hid/__init__.mpy b/boards/pyruler/6.x/lib/adafruit_hid/__init__.mpy new file mode 100644 index 0000000..29daa94 Binary files /dev/null and b/boards/pyruler/6.x/lib/adafruit_hid/__init__.mpy differ diff --git a/boards/pyruler/6.x/lib/adafruit_hid/consumer_control.mpy b/boards/pyruler/6.x/lib/adafruit_hid/consumer_control.mpy new file mode 100644 index 0000000..ff510dc Binary files /dev/null and b/boards/pyruler/6.x/lib/adafruit_hid/consumer_control.mpy differ diff --git a/boards/pyruler/6.x/lib/adafruit_hid/consumer_control_code.mpy b/boards/pyruler/6.x/lib/adafruit_hid/consumer_control_code.mpy new file mode 100644 index 0000000..b6fc457 Binary files /dev/null and b/boards/pyruler/6.x/lib/adafruit_hid/consumer_control_code.mpy differ diff --git a/boards/pyruler/6.x/lib/adafruit_hid/gamepad.mpy b/boards/pyruler/6.x/lib/adafruit_hid/gamepad.mpy new file mode 100644 index 0000000..54f4a25 Binary files /dev/null and b/boards/pyruler/6.x/lib/adafruit_hid/gamepad.mpy differ diff --git a/boards/pyruler/6.x/lib/adafruit_hid/keyboard.mpy b/boards/pyruler/6.x/lib/adafruit_hid/keyboard.mpy new file mode 100644 index 0000000..6fe3ace Binary files /dev/null and b/boards/pyruler/6.x/lib/adafruit_hid/keyboard.mpy differ diff --git a/boards/pyruler/6.x/lib/adafruit_hid/keyboard_layout_us.mpy b/boards/pyruler/6.x/lib/adafruit_hid/keyboard_layout_us.mpy new file mode 100644 index 0000000..89f0856 Binary files /dev/null and b/boards/pyruler/6.x/lib/adafruit_hid/keyboard_layout_us.mpy differ diff --git a/boards/pyruler/6.x/lib/adafruit_hid/keycode.mpy b/boards/pyruler/6.x/lib/adafruit_hid/keycode.mpy new file mode 100644 index 0000000..106bba1 Binary files /dev/null and b/boards/pyruler/6.x/lib/adafruit_hid/keycode.mpy differ diff --git a/boards/pyruler/6.x/lib/adafruit_hid/mouse.mpy b/boards/pyruler/6.x/lib/adafruit_hid/mouse.mpy new file mode 100644 index 0000000..6289bd4 Binary files /dev/null and b/boards/pyruler/6.x/lib/adafruit_hid/mouse.mpy differ