Last active
August 29, 2015 14:18
-
-
Save ChuckM/c0ed758f937a3e21a0a9 to your computer and use it in GitHub Desktop.
Processing optically encoder knobs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void | |
update_cursor(int cursor_num) | |
{ | |
struct cursor_data_struct *cursor; | |
uint32_t timer; | |
int x, y; | |
int16_t delta; | |
int c_limit; | |
int16_t cur; | |
/* invalid cursor */ | |
if ((cursor_num < 0) || (cursor_num >= MAX_CURSORS)) { | |
return; | |
} | |
cursor = &cursor_data[cursor_num]; | |
c_limit = (cursor->hv == IS_HORIZ) ? 240 : 300; /* reticule width */ | |
timer = cursor->timer; | |
/* if timer is non-null figure out if the user has turned the knob */ | |
if (timer) { | |
cur = timer_get_counter(timer); | |
delta = cur - cursor->prev; | |
if (delta) { | |
printf("Delta : %d\n", delta); | |
} | |
/* scaling function */ | |
if (delta != 0) { | |
if (abs(delta) < 10) { | |
delta = (delta < 0) ? -1 : 1; | |
} else if (abs(delta) < 100) { | |
delta = (delta < 0) ? -5 : 5; | |
} else { | |
delta = (delta < 0) ? -20 : 20; | |
} | |
} | |
cursor->prev = cur; | |
cursor->ndx += delta; | |
cursor->ndx = (cursor->ndx < 0) ? 0 : cursor->ndx; | |
cursor->ndx = (cursor->ndx >= c_limit) ? c_limit - 1 : cursor->ndx; | |
} | |
if (cursor->hv == IS_HORIZ) { | |
x = 0; | |
y = cursor->ndx; | |
} else { | |
x = cursor->ndx; | |
y = 0; | |
} | |
eve_move_to(x, y); | |
eve_set_color(cursor->color); | |
eve_draw_bitmap(cursor->bitmap); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment