Skip to content
Permalink
Browse files

Added live variable display (keystroke: ~)

Docs updated, feature implemented.
  • Loading branch information
burnsauce committed Oct 22, 2017
1 parent 245c643 commit 3ef02dedf5e712f812f43207e07253c12119f15f
Showing with 73 additions and 10 deletions.
  1. +1 −0 docs/keys.md
  2. +2 −1 module/help_mode.c
  3. +52 −1 module/live_mode.c
  4. +1 −0 module/live_mode.h
  5. +5 −2 module/main.c
  6. +1 −0 src/ops/op.c
  7. +9 −6 src/state.h
  8. +2 −0 src/teletype_io.h
@@ -51,6 +51,7 @@ In most cases, the clipboard is shared between _live_, _edit_ and the 2 _preset_
| `<down>` / `C-n` | history next |
| `<up>` / `C-p` | history previous |
| `<enter>` | execute command |
| `~` | toggle variables |
| `[` / `]` | switch to edit mode |

## Edit mode
@@ -17,7 +17,7 @@

#define HELP_PAGES 8

#define HELP1_LENGTH 46
#define HELP1_LENGTH 47
const char* help1[HELP1_LENGTH] = { "1/8 HELP",
"[ ] NAVIGATE HELP PAGES",
"UP/DOWN TO SCROLL",
@@ -40,6 +40,7 @@ const char* help1[HELP1_LENGTH] = { "1/8 HELP",
"ENTER|EXECUTE",
"UP|PREVIOUS",
"SH-BSP|CLEAR",
"~|TOGGLE VARS",
" ",
"// EDIT",
"[ ]|PREV, NEXT SCRIPT",
@@ -35,6 +35,7 @@ static bool show_welcome_message;
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_VARS = 1 << 3;
static const uint8_t D_ALL = 0xFF;
static uint8_t dirty;

@@ -45,6 +46,10 @@ static const uint8_t A_STACK = 1 << 3;
static const uint8_t A_MUTES = 1 << 4;
static uint8_t activity_prev;
static uint8_t activity;
static bool show_vars = false;
static int16_t vars_prev[8];
char var_names[] = { 'A', 0, 'B', 0, 'C', 0, 'D', 0,
'X', 0, 'Y', 0, 'Z', 0, 'T', 0 };

// teletype_io.h
void tele_has_delays(bool has_delays) {
@@ -80,6 +85,10 @@ void set_metro_icon(bool display) {
activity &= ~A_METRO;
}

void set_vars_updated() {
dirty |= D_VARS;
}

// main mode functions
void init_live_mode() {
status = E_OK;
@@ -88,6 +97,9 @@ void init_live_mode() {
activity_prev = 0xFF;
history_top = -1;
history_line = -1;
for (int i = 0; i < 7; i++)
var_names[i * 2 + 1] = 0;
show_vars = false;
}

void set_live_mode() {
@@ -164,6 +176,13 @@ void process_live_keys(uint8_t k, uint8_t m, bool is_held_key) {
match_no_mod(m, k, HID_CLOSE_BRACKET)) {
set_mode(M_EDIT);
}
// tilde: show the variables
else if (match_no_mod(m, k, HID_TILDE)) {
show_vars = !show_vars;
if (show_vars)
dirty |= D_VARS; // combined with this...
dirty |= D_LIST; // cheap flag to indicate mode just switched
}
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;
@@ -173,6 +192,7 @@ void process_live_keys(uint8_t k, uint8_t m, bool is_held_key) {

bool screen_refresh_live() {
bool screen_dirty = false;

if (dirty & D_INPUT) {
line_editor_draw(&le, '>', &line[7]);
screen_dirty = true;
@@ -211,8 +231,39 @@ bool screen_refresh_live() {
dirty &= ~D_MESSAGE;
}

if (show_vars && ((dirty & D_VARS) || (dirty & D_LIST))) {
int16_t* vp = &scene_state.variables.a;
char s[8];

for (int i = 1; i < 6; i++) region_fill(&line[i], 0);

bool changed = dirty & D_LIST;
if (!changed)
for (int i = 0; i < 8; i++)
if (vp[i] != vars_prev[i]) {
vars_prev[i] = vp[i];
changed = true;
break;
}

if (changed) {
for (int i = 0; i < 8; i++) {
uint8_t x = (8 * (i % 4 + 1)) - 2;
uint8_t y = 2 * (i / 4) + 1;
// print header
font_string_region_clip_right(&line[y], var_names + (i * 2), x * 4, 0, 0x1, 0);
// print value
itoa(vp[i], s, 10);
font_string_region_clip_right(&line[y + 1], s, x * 4, 0, 0xf, 0);
}
screen_dirty = true;
}
dirty &= ~D_VARS;
dirty &= ~D_LIST;
}

if (dirty & D_LIST) {
for (int i = 0; i < 6; i++) region_fill(&line[i], 0);
for (int i = 1; i < 6; i++) region_fill(&line[i], 0);

screen_dirty = true;
dirty &= ~D_LIST;
@@ -10,5 +10,6 @@ void init_live_mode(void);
void set_live_mode(void);
void process_live_keys(uint8_t key, uint8_t mod_key, bool is_held_key);
bool screen_refresh_live(void);
void set_vars_updated(void);

#endif
@@ -679,11 +679,14 @@ void tele_kill() {
}
}


bool tele_get_input_state(uint8_t n) {
return gpio_get_pin_value(A00 + n) > 0;
}

void tele_vars_updated() {
set_vars_updated();
}


////////////////////////////////////////////////////////////////////////////////
// main
@@ -708,7 +711,7 @@ int main(void) {
init_oled();
init_i2c_master();

print_dbg("\r\n\n// teletype! //////////////////////////////// ");
print_dbg("\r\n\r\n// teletype! //////////////////////////////// ");

ss_init(&scene_state);

@@ -186,6 +186,7 @@ void op_poke_i16(const void *data, scene_state_t *ss, exec_state_t *NOTUSED(es),
size_t offset = (size_t)data;
int16_t *ptr = (int16_t *)(base + offset);
*ptr = cs_pop(cs);
tele_vars_updated();
}

void op_simple_i2c(const void *data, scene_state_t *NOTUSED(ss),
@@ -30,14 +30,20 @@
// SCENE STATE /////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

//clang-format off
typedef struct {
// Maintaining this order allows for efficient access to the group
int16_t a;
int16_t b;
int16_t c;
int16_t d;
int16_t x;
int16_t y;
int16_t z;
int16_t t;
int16_t cv[CV_COUNT];
int16_t cv_off[CV_COUNT];
int16_t cv_slew[CV_COUNT];
int16_t d;
int16_t drunk;
int16_t drunk_max;
int16_t drunk_min;
@@ -46,7 +52,7 @@ typedef struct {
int16_t in;
int16_t m;
bool m_act;
bool mutes[TRIGGER_INPUTS];
bool mutes[TRIGGER_INPUTS]; // TODO: replace with uint8_t bits
int16_t o;
int16_t o_inc;
int16_t o_min;
@@ -57,16 +63,13 @@ typedef struct {
int16_t q[Q_LENGTH];
int16_t q_n;
int16_t scene;
int16_t t;
int16_t time;
int16_t time_act;
int16_t tr[TR_COUNT];
int16_t tr_pol[TR_COUNT];
int16_t tr_time[TR_COUNT];
int16_t x;
int16_t y;
int16_t z;
} scene_variables_t;
//clang-format on

typedef struct {
int16_t idx;
@@ -31,6 +31,8 @@ extern void tele_scene(uint8_t i);
// called when a pattern is updated
extern void tele_pattern_updated(void);

extern void tele_vars_updated(void);

extern void tele_kill(void);
extern void tele_mute(void);
extern bool tele_get_input_state(uint8_t);

0 comments on commit 3ef02de

Please sign in to comment.