Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
Commits on Mar 15, 2017
instead of being key code then mode, it is now mode then key code
Commits on Mar 22, 2017
Commits on Mar 23, 2017
Commits on Mar 26, 2017
Commits on Mar 28, 2017
Commits on Apr 01, 2017
Commits on Apr 04, 2017
Commits on Apr 06, 2017
Commits on Apr 16, 2017
Showing with 3,593 additions and 2,890 deletions.
  1. +124 −0 docs/modes.md
  2. +13 −1 module/config.mk
  3. +225 −0 module/edit_mode.c
  4. +12 −0 module/edit_mode.h
  5. +56 −0 module/flash.c
  6. +38 −0 module/flash.h
  7. +33 −0 module/globals.h
  8. +93 −1 module/{help.h → help_mode.c}
  9. +11 −0 module/help_mode.h
  10. +83 −0 module/keyboard_helper.h
  11. +170 −0 module/line_editor.c
  12. +26 −0 module/line_editor.h
  13. +277 −0 module/live_mode.c
  14. +14 −0 module/live_mode.h
  15. +226 −1,905 module/main.c
  16. +350 −0 module/pattern_mode.c
  17. +12 −0 module/pattern_mode.h
  18. +92 −0 module/preset_r_mode.c
  19. +12 −0 module/preset_r_mode.h
  20. +125 −0 module/preset_w_mode.c
  21. +11 −0 module/preset_w_mode.h
  22. +442 −0 module/usb_disk_mode.c
  23. +6 −0 module/usb_disk_mode.h
  24. +5 −4 simulator/Makefile
  25. +20 −19 simulator/tt.c
  26. +20 −11 src/command.c
  27. +61 −53 src/match_token.rl
  28. +0 −55 src/ops/constants.c
  29. +0 −54 src/ops/constants.h
  30. +18 −15 src/ops/controlflow.c
  31. +3 −4 src/ops/delay.c
  32. +13 −0 src/ops/earthsea.c
  33. +16 −0 src/ops/earthsea.h
  34. +15 −91 src/ops/hardware.c
  35. +0 −2 src/ops/hardware.h
  36. +1 −1 src/ops/maths.c
  37. +12 −0 src/ops/meadowphysics.c
  38. +15 −0 src/ops/meadowphysics.h
  39. +6 −6 src/ops/metronome.c
  40. +29 −17 src/ops/op.c
  41. +14 −11 src/ops/op.h
  42. +0 −2 src/ops/op_enum.h
  43. +20 −0 src/ops/orca.c
  44. +23 −0 src/ops/orca.h
  45. +158 −169 src/ops/patterns.c
  46. +7 −6 src/ops/stack.c
  47. +18 −0 src/ops/whitewhale.c
  48. +21 −0 src/ops/whitewhale.h
  49. +1 −1 src/scanner.h
  50. +18 −4 src/scanner.rl
  51. +242 −0 src/state.c
  52. +57 −6 src/state.h
  53. +68 −198 src/teletype.c
  54. +18 −43 src/teletype.h
  55. +18 −6 src/teletype_io.h
  56. +5 −4 tests/Makefile
  57. +6 −6 tests/main.c
  58. +176 −154 tests/parser_tests.c
  59. +38 −41 tests/process_tests.c
@@ -0,0 +1,124 @@

## Global key bindings

These bindings work everywhere.

| Key | Action |
|------------------------------|------------------------------------------------|
| `<tab>` | change modes, live to edit to pattern and back |
| `<esc>` | preset read mode, or return to last mode |
| `alt-<esc>` | preset write mode |
| `win-<esc>` | clear delays, stack and slews |
| `<print screen>` | help text, or return to last mode |
| `<F1>` to `<F8>` | run corresponding script |
| `<F8>` | run metro script |
| `<F9>` | run init script |
| `alt-<F1>` to `alt-<F8>` | edit corresponding script |
| `alt-<F8>` | edit metro script |
| `alt-<F9>` | edit init script |
| `<numpad-1>` to `<numpad-8>` | run corresponding script |

## Text editing

These bindings work when entering text or code.

In most cases, the clipboard is shared between _live_, _edit_ and the 2 _preset_ modes.

| Key | Action |
|--------------------------------|-----------------------------------------|
| `<left>` / `ctrl-b` | move cursor left |
| `<right>` / `ctrl-f` | move cursor right |
| `<home>` / `ctrl-a` | move to beginning of line |
| `<end>` / `ctrl-e` | move to end of line |
| `<backspace>` / `ctrl-h` | backwards delete one character |
| `<delete>` / `ctrl-d` | forwards delete one character |
| `shift-<backspace>` / `ctrl-u` | delete from cursor to beginning |
| `shift-<delete>` / `ctrl-e` | delete from cursor to end |
| `alt-<backspace>` / `ctrl-w` | delete from cursor to beginning of word |
| `ctrl-x` / `alt-x` | cut to clipboard |
| `ctrl-c` / `alt-c` | copy to clipboard |
| `ctrl-v` / `alt-v` | paste to clipboard |

## Live mode

| Key | Action |
|------------------|---------------------|
| `<down>` / `C-n` | history next |
| `<up>` / `C-p` | history previous |
| `<enter>` | execute command |
| `[` / `]` | switch to edit mode |

## Edit mode

| Key | Action |
|--------------------|---------------------------|
| `<down>` / `C-n` | line down |
| `<up>` / `C-p` | line up |
| `[` | previous script |
| `]` | next script |
| `<enter>` | enter command |
| `shift-<enter>` | insert command |

## Pattern mode

The pattern mode clipboard is independent of text and code clipboard.

| Key | Action |
|---------------------|---------------------------------------------------------------------------------------|
| `<down>` | move down |
| `alt-<down>` | move a page down |
| `<up>` | move up |
| `alt-<up>` | move a page up |
| `<left>` | move left |
| `alt-<left>` | move to the very left |
| `<right>` | move right |
| `alt-<right>` | move to the very right |
| `[` | decrement by 1 |
| `]` | increment by 1 |
| `<backspace>` | delete a digit |
| `shift-<backspace>` | delete an entry, shift numbers up |
| `<enter>` | move down (increase length only if on the entry immediately after the current length) |
| `shift-<enter>` | duplicate entry and shift downwards (increase length as `<enter>`) |
| `alt-x` | cut value (n.b. `ctrl-x` not supported) |
| `alt-c` | copy value (n.b. `ctrl-c` not supported) |
| `alt-v` | paste value (n.b. `ctrl-v` not supported) |
| `shift-alt-v` | insert value |
| `shift-l` | set length to current position |
| `alt-l` | go to current length entry |
| `shift-s` | set start to current position |
| `alt-s` | go to start entry |
| `shift-e` | set end to current position |
| `alt-e` | go to end entry |
| `-` | negate value |
| `<space>` | toggle non-zero to zero, and zero to 1 |
| `0` to `9` | numeric entry |

## Preset read mode

| Key | Action |
|------------------|-------------|
| `<down>` / `C-n` | line down |
| `<up>` / `C-p` | line up |
| `<left>` / `[` | preset down |
| `<right>` / `]` | preset up |
| `<enter>` | load preset |

## Preset write mode

| Key | Action |
|------------------|-------------|
| `<down>` / `C-n` | line down |
| `<up>` / `C-p` | line up |
| `[` | preset down |
| `]` | preset up |
| `<enter>` | enter text |
| `alt-<enter>` | save preset |

## Help mode

| Key | Action |
|------------------|---------------|
| `<down>` / `C-n` | line down |
| `<up>` / `C-p` | line up |
| `<left>` / `[` | previous page |
| `<right>` / `]` | next page |
@@ -62,7 +62,16 @@ TARGET = $(THIS).elf
# List of C source files.
CSRCS = \
../module/main.c \
../module/edit_mode.c \
../module/flash.c \
../module/gitversion.c \
../module/help_mode.c \
../module/line_editor.c \
../module/live_mode.c \
../module/pattern_mode.c \
../module/preset_r_mode.c \
../module/preset_w_mode.c \
../module/usb_disk_mode.c \
../src/command.c \
../src/helpers.c \
../src/match_token.c \
@@ -72,18 +81,21 @@ CSRCS = \
../src/teletype.c \
../src/ops/op.c \
../src/ops/ansible.c \
../src/ops/constants.c \
../src/ops/controlflow.c \
../src/ops/delay.c \
../src/ops/earthsea.c \
../src/ops/hardware.c \
../src/ops/justfriends.c \
../src/ops/maths.c \
../src/ops/meadowphysics.c \
../src/ops/metronome.c \
../src/ops/orca.c \
../src/ops/patterns.c \
../src/ops/queue.c \
../src/ops/stack.c \
../src/ops/telex.c \
../src/ops/variables.c \
../src/ops/whitewhale.c \
../libavr32/src/adc.c \
../libavr32/src/events.c \
../libavr32/src/euclidean/euclidean.c \
@@ -0,0 +1,225 @@
#include "edit_mode.h"

#include <string.h>

// this
#include "flash.h"
#include "globals.h"
#include "keyboard_helper.h"
#include "line_editor.h"

// libavr32
#include "font.h"
#include "kbd.h"
#include "region.h"
#include "util.h"

// asf
#include "conf_usb_host.h" // needed in order to include "usb_protocol_hid.h"
#include "usb_protocol_hid.h"

line_editor_t le;
uint8_t line_no;
uint8_t script;
error_t status;
char error_msg[TELE_ERROR_MSG_LENGTH];

static const uint8_t D_INPUT = 1 << 0;
static const uint8_t D_LIST = 1 << 1;
static const uint8_t D_MESSAGE = 1 << 2;
static const uint8_t D_ALL = 0xFF;
uint8_t dirty;

void set_edit_mode() {
status = E_OK;
error_msg[0] = 0;
line_no = 0;
line_editor_set_command(
&le, ss_get_script_command(&scene_state, script, line_no));
dirty = D_ALL;
}

void set_edit_mode_script(uint8_t new_script) {
script = new_script;
if (script >= SCRIPT_COUNT) script = SCRIPT_COUNT - 1;
}

void process_edit_keys(uint8_t k, uint8_t m, bool is_held_key) {
// <down> or C-n: line down
if (match_no_mod(m, k, HID_DOWN) || match_ctrl(m, k, HID_N)) {
if (line_no < (SCRIPT_MAX_COMMANDS - 1) &&
line_no < ss_get_script_len(&scene_state, script)) {
line_no++;
line_editor_set_command(
&le, ss_get_script_command(&scene_state, script, line_no));
dirty |= D_LIST;
dirty |= D_INPUT;
}
}
// <up> or C-p: line up
else if (match_no_mod(m, k, HID_UP) || match_ctrl(m, k, HID_P)) {
if (line_no) {
line_no--;
line_editor_set_command(
&le, ss_get_script_command(&scene_state, script, line_no));
dirty |= D_LIST;
dirty |= D_INPUT;
}
}
// [: previous script
else if (match_no_mod(m, k, HID_OPEN_BRACKET)) {
status = E_OK;
error_msg[0] = 0;
if (script)
script--;
else
script = SCRIPT_COUNT - 1;
if (line_no > ss_get_script_len(&scene_state, script))
line_no = ss_get_script_len(&scene_state, script);
line_editor_set_command(
&le, ss_get_script_command(&scene_state, script, line_no));
dirty |= D_LIST;
dirty |= D_INPUT;
}
// ]: next script
else if (match_no_mod(m, k, HID_CLOSE_BRACKET)) {
status = E_OK;
error_msg[0] = 0;
script++;
if (script >= SCRIPT_COUNT) script = 0;
if (line_no > ss_get_script_len(&scene_state, script))
line_no = ss_get_script_len(&scene_state, script);
line_editor_set_command(
&le, ss_get_script_command(&scene_state, script, line_no));
dirty |= D_LIST;
dirty |= D_INPUT;
}
// ctrl-x or alt-x: override line editors cut
else if (match_ctrl(m, k, HID_X) || match_alt(m, k, HID_X)) {
line_editor_set_copy_buffer(line_editor_get(&le));
ss_delete_script_command(&scene_state, script, line_no);
if (line_no > ss_get_script_len(&scene_state, script)) {
line_no = ss_get_script_len(&scene_state, script);
}
line_editor_set_command(
&le, ss_get_script_command(&scene_state, script, line_no));

dirty |= D_LIST;
dirty |= D_INPUT;
}
// <enter>: enter command
else if (match_no_mod(m, k, HID_ENTER)) {
dirty |= D_MESSAGE; // something will happen

tele_command_t command;
status = parse(line_editor_get(&le), &command, error_msg);

if (status != E_OK)
return; // quit, screen_refresh_edit will display the error message

status = validate(&command, error_msg);
if (status != E_OK)
return; // quit, screen_refresh_edit will display the error message

if (command.length == 0) { // blank line, delete the command
ss_delete_script_command(&scene_state, script, line_no);
if (line_no > ss_get_script_len(&scene_state, script)) {
line_no = ss_get_script_len(&scene_state, script);
}
}
else {
ss_overwrite_script_command(&scene_state, script, line_no,
&command);
if (line_no < SCRIPT_MAX_COMMANDS - 1) { line_no++; }
}
line_editor_set_command(
&le, ss_get_script_command(&scene_state, script, line_no));
dirty |= D_LIST;
dirty |= D_INPUT;
}
// shift-<enter>: insert command
else if (match_shift(m, k, HID_ENTER)) {
dirty |= D_MESSAGE; // something will happen

tele_command_t command;
status = parse(line_editor_get(&le), &command, error_msg);

if (status != E_OK)
return; // quit, screen_refresh_edit will display the error message

status = validate(&command, error_msg);
if (status != E_OK)
return; // quit, screen_refresh_edit will display the error message

if (command.length > 0) {
ss_insert_script_command(&scene_state, script, line_no, &command);
if (line_no < (SCRIPT_MAX_COMMANDS - 1)) { line_no++; }
}

line_editor_set_command(
&le, ss_get_script_command(&scene_state, script, line_no));
dirty |= D_LIST;
dirty |= D_INPUT;
}
else { // pass the key though to the line editor
bool processed = line_editor_process_keys(&le, k, m, is_held_key);
if (processed) dirty |= D_INPUT;
}
}


bool screen_refresh_edit() {
bool screen_dirty = false;

if (dirty & D_INPUT) {
char prefix = script + '1';
if (script == METRO_SCRIPT)
prefix = 'M';
else if (script == INIT_SCRIPT)
prefix = 'I';

line_editor_draw(&le, prefix, &line[7]);
screen_dirty = true;
dirty &= ~D_INPUT;
}

if (dirty & D_MESSAGE) {
char s[32];
if (status != E_OK) {
strcpy(s, tele_error(status));
if (error_msg[0]) {
strcat(s, ": ");
strcat(s, error_msg);
error_msg[0] = 0;
}
status = E_OK;
}
else {
s[0] = 0;
}

region_fill(&line[6], 0);
font_string_region_clip(&line[6], s, 0, 0, 0x4, 0);

screen_dirty = true;
dirty &= ~D_MESSAGE;
}

if (dirty & D_LIST) {
for (int i = 0; i < 6; i++) {
uint8_t a = line_no == i;
region_fill(&line[i], a);
if (ss_get_script_len(&scene_state, script) > i) {
char s[32];
print_command(ss_get_script_command(&scene_state, script, i),
s);
region_string(&line[i], s, 2, 0, 0xf, a, 0);
}
}

screen_dirty = true;
dirty &= ~D_LIST;
}

return screen_dirty;
}

No commit comments for this range