diff --git a/fw/README.md b/fw/README.md index 4cf4a04..e14b043 100644 --- a/fw/README.md +++ b/fw/README.md @@ -15,5 +15,5 @@ tested natively on a Mac. *For key press detection on Mac, you'll need to give a 1. Run `python3 bundle.py` from this directory. This will create a `bundle` directory, which will copy all required files into folders to be loaded onto each board. 2. Find the directory with your board's name in the `bundle` directory. Copy all files/subdirectories onto your CircuitPython device. -3. If your board's `bundle` directory contains a `lib` subdirectory, you may have to manually copy some third-party libraries into it. The `lib` subdirectory will contain a README listing all of the required dependencies. Official CircuitPython libraries available [here](https://circuitpython.org/libraries). As of May 2021, I have been using Bundle version 6.x. -4. If you're using the `macos` version, execute `python3 code.py` from the `bundle/macos` directory. \ No newline at end of file +3. If your board requires third-party libraries to run this code (most do), you may have to manually copy them. Each board's `bundle` directory will contain a README listing all of the required dependencies. Official CircuitPython libraries available [here](https://circuitpython.org/libraries). As of May 2021, I have been using Bundle version 6.x. +4. If you're using the `macos` version, execute `python3 code.py` from the `bundle/macos` directory. You'll have to `pip3 install pynput` as well. \ No newline at end of file diff --git a/fw/core/code.py b/fw/core/code.py index 335754c..0d4bd10 100644 --- a/fw/core/code.py +++ b/fw/core/code.py @@ -89,19 +89,6 @@ def __init__(self, keys, words, pres): def __str__(self): return f'keys: {self.keys}, words: {self.words}, pres: {self.pres}' -# Choose mode based on held keys at startup -if ('1' in keypad.pressed_keys): - leds.show_red() - run_numeric_mode() -elif ('2' in keypad.pressed_keys): - leds.show_green() - run_macro_mode() -else: - leds.show_blue() - -# Flag to indicate to our main loop that we want to start a new word -force_break_word = False - keypad_dict = { '1' : ['1'], '2' : ['a', 'b', 'c'], @@ -116,11 +103,45 @@ def __str__(self): '#' : ['.', ',', '?', '!'] } +def error_mode(): + print("ERROR!") + while True: + time.sleep(0.01) + pass + +reverse_key_dict = { } +for k, l in keypad_dict.items(): + for c in l: + reverse_key_dict[c] = k + # TODO - read in word list from txt file, build this dict dynamically. -priority_words = { - 4: "i", - 46: "in" -} +priority_words = { } +try: + with open("priority_words.txt", "r") as fp: + for line in fp.readlines(): + line = line.strip().lower() + key_seq = "" + for c in line: + key = reverse_key_dict.get(c) + if key is None: + error_mode() + key_seq = key_seq + key + priority_words[key_seq] = line +except IOError: + pass + +# Choose mode based on held keys at startup +if ('1' in keypad.pressed_keys): + leds.show_red() + run_numeric_mode() +elif ('2' in keypad.pressed_keys): + leds.show_green() + run_macro_mode() +else: + leds.show_blue() + +# Flag to indicate to our main loop that we want to start a new word +force_break_word = False # given a file and location in that file, read a 24bit unsigned int def read_int(file, offset): @@ -163,7 +184,7 @@ def get_words(file, input, last_result): output_prefixes.append(test_word) elif result == WORD: output_words.append(test_word) - return Results((last_result.keys * 10) + int(input), output_words, output_prefixes) + return Results(last_result.keys + input, output_words, output_prefixes) # if old_word has been typed, and new_word should replace it - how many chars to we need to replace? # ex: uncommon_chars("catch", "cab") == 3 @@ -284,7 +305,7 @@ def poll_keys(): while True: word_index = 0 current_word = "" - last_result = Results(0, [""], []) + last_result = Results("", [""], []) results = [ last_result ] result_index = 0 while True: diff --git a/fw/core/priority_words.txt b/fw/core/priority_words.txt new file mode 100644 index 0000000..977ede1 --- /dev/null +++ b/fw/core/priority_words.txt @@ -0,0 +1,11 @@ +i +in +to +my +is +no +of +be +as +it +so \ No newline at end of file diff --git a/fw/macos/led.py b/fw/macos/led.py index 7f67140..ca05685 100644 --- a/fw/macos/led.py +++ b/fw/macos/led.py @@ -3,10 +3,13 @@ def __init__(self): self.color = None def show_red(self): + print("set led to red") self.color = 'r' def show_green(self): + print("set led to green") self.color = 'g' def show_blue(self): + print("set led to blue") self.color = 'b' \ No newline at end of file diff --git a/fw/tiny2040/lib/README.md b/fw/tiny2040/README.md similarity index 81% rename from fw/tiny2040/lib/README.md rename to fw/tiny2040/README.md index a8ae4a6..a097243 100644 --- a/fw/tiny2040/lib/README.md +++ b/fw/tiny2040/README.md @@ -1,5 +1,5 @@ ## Required (Circuit/Micro)Python Libraries: -**Make sure the following files are in this folder, on your microcontroller** +**Make sure the following files are in a folder called `lib`, on your microcontroller** * adafruit_hid * `adafruit_hid/__init__.mpy` * `adafruit_hid/consumer_control_code.mpy`