overhaul oled code; set render function at startup; set OLED_UPDATE_INTERVAL to FRAME_TIMEOUT; use smaller data types; formatting
All checks were successful
Build / build-sporq (push) Successful in 2m0s
All checks were successful
Build / build-sporq (push) Successful in 2m0s
This commit is contained in:
parent
c31420083c
commit
dfcb569a13
@ -14,19 +14,12 @@ enum layers {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static uint16_t animation_timer = 0;
|
static uint16_t animation_timer = 0;
|
||||||
// 40 fps
|
#define FRAME_TIMEOUT (1000/60)
|
||||||
#define FRAME_TIMEOUT (1000/40)
|
#undef OLED_UPDATE_INTERVAL
|
||||||
|
#define OLED_UPDATE_INTERVAL FRAME_TIMEOUT
|
||||||
// 30 sec
|
// 30 sec
|
||||||
#define SLEEP_TIMEOUT 30000
|
#define SLEEP_TIMEOUT 30000
|
||||||
|
|
||||||
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
|
|
||||||
if (!is_keyboard_master()) {
|
|
||||||
return OLED_ROTATION_0;
|
|
||||||
}
|
|
||||||
return OLED_ROTATION_270;
|
|
||||||
animation_timer = timer_read();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Spaceship OLED starts here
|
// Spaceship OLED starts here
|
||||||
// code made by JBaguley and copied from crkbd/keymaps/retrograde/keymap.c
|
// code made by JBaguley and copied from crkbd/keymaps/retrograde/keymap.c
|
||||||
@ -230,47 +223,49 @@ static const char PROGMEM mask_row_4[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void render_space_animation(void) {
|
static void render_space_animation(void) {
|
||||||
const char wpm = get_current_wpm();
|
const uint8_t wpm = get_current_wpm();
|
||||||
|
const uint8_t wpm_div = wpm / 4;
|
||||||
char render_row[128];
|
char render_row[128];
|
||||||
int i;
|
uint8_t i;
|
||||||
oled_set_cursor(0,0);
|
|
||||||
for(i=0; i<wpm/4; i++) {
|
|
||||||
render_row[i] = pgm_read_byte(space_row_1+i+state);
|
|
||||||
};
|
|
||||||
for(i=wpm/4; i<128; i++) {
|
|
||||||
render_row[i] = (pgm_read_byte(space_row_1+i+state)&pgm_read_byte(mask_row_1+i-wpm/4)) | pgm_read_byte(ship_row_1+i-wpm/4);
|
|
||||||
};
|
|
||||||
|
|
||||||
oled_write_raw(render_row, 128);
|
oled_set_cursor(0, 0);
|
||||||
// oled_write_raw_P(space_row_1, 128);
|
for(i = 0; i < wpm_div; i++) {
|
||||||
oled_set_cursor(0,1);
|
render_row[i] = pgm_read_byte(space_row_1 + i + state);
|
||||||
for(i=0; i<wpm/4; i++) {
|
|
||||||
render_row[i] = pgm_read_byte(space_row_2+i+state);
|
|
||||||
};
|
};
|
||||||
for(i=wpm/4; i<128; i++) {
|
for(i = wpm_div; i < 128; i++) {
|
||||||
render_row[i] = (pgm_read_byte(space_row_2+i+state)&pgm_read_byte(mask_row_2+i-wpm/4)) | pgm_read_byte(ship_row_2+i-wpm/4);
|
render_row[i] = (pgm_read_byte(space_row_1 + i + state) & pgm_read_byte(mask_row_1 + i - wpm_div))
|
||||||
|
| pgm_read_byte(ship_row_1 + i - wpm_div);
|
||||||
};
|
};
|
||||||
oled_write_raw(render_row, 128);
|
oled_write_raw(render_row, 128);
|
||||||
oled_set_cursor(0,2);
|
oled_set_cursor(0, 1);
|
||||||
for(i=0; i<wpm/4; i++) {
|
for(i = 0; i < wpm_div; i++) {
|
||||||
render_row[i] = pgm_read_byte(space_row_3+i+state);
|
render_row[i] = pgm_read_byte(space_row_2 + i + state);
|
||||||
};
|
};
|
||||||
for(i=wpm/4; i<128; i++) {
|
for(i = wpm_div; i < 128; i++) {
|
||||||
render_row[i] = (pgm_read_byte(space_row_3+i+state)&pgm_read_byte(mask_row_3+i-wpm/4)) | pgm_read_byte(ship_row_3+i-wpm/4);
|
render_row[i] = (pgm_read_byte(space_row_2 + i + state) & pgm_read_byte(mask_row_2 + i - wpm_div))
|
||||||
|
| pgm_read_byte(ship_row_2 + i - wpm_div);
|
||||||
};
|
};
|
||||||
|
|
||||||
oled_write_raw(render_row, 128);
|
oled_write_raw(render_row, 128);
|
||||||
oled_set_cursor(0,3);
|
oled_set_cursor(0, 2);
|
||||||
for(i=0; i<wpm/4; i++) {
|
for(i = 0; i < wpm_div; i++) {
|
||||||
render_row[i] = pgm_read_byte(space_row_4+i+state);
|
render_row[i] = pgm_read_byte(space_row_3 + i + state);
|
||||||
};
|
};
|
||||||
for(i=wpm/4; i<128; i++) {
|
for(i = wpm_div; i < 128; i++) {
|
||||||
render_row[i] = (pgm_read_byte(space_row_4+i+state)&pgm_read_byte(mask_row_4+i-wpm/4)) | pgm_read_byte(ship_row_4+i-wpm/4);
|
render_row[i] = (pgm_read_byte(space_row_3 + i + state) & pgm_read_byte(mask_row_3 + i - wpm_div))
|
||||||
|
| pgm_read_byte(ship_row_3 + i - wpm_div);
|
||||||
|
};
|
||||||
|
oled_write_raw(render_row, 128);
|
||||||
|
oled_set_cursor(0, 3);
|
||||||
|
for(i = 0; i < wpm_div; i++) {
|
||||||
|
render_row[i] = pgm_read_byte(space_row_4 + i + state);
|
||||||
|
};
|
||||||
|
for(i = wpm_div; i < 128; i++) {
|
||||||
|
render_row[i] = (pgm_read_byte(space_row_4 + i + state) & pgm_read_byte(mask_row_4 + i - wpm_div))
|
||||||
|
| pgm_read_byte(ship_row_4 + i - wpm_div);
|
||||||
};
|
};
|
||||||
|
|
||||||
oled_write_raw(render_row, 128);
|
oled_write_raw(render_row, 128);
|
||||||
|
|
||||||
state = (state + 1 + (wpm/20)) % (128*2);
|
state = (state + 1 + (wpm / 15)) % (128 * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// End of Spaceship OLED
|
// End of Spaceship OLED
|
||||||
@ -473,25 +468,50 @@ static void render_layer_state(void) {
|
|||||||
|
|
||||||
// End of aurora corne things
|
// End of aurora corne things
|
||||||
|
|
||||||
|
// point to render_left() or render_right() after olet_int_user() ran
|
||||||
|
void (*render)(void);
|
||||||
|
|
||||||
|
void render_left(void) {
|
||||||
|
// Renders the current keyboard state (layers and mods)
|
||||||
|
render_logo();
|
||||||
|
render_logo_text();
|
||||||
|
render_space();
|
||||||
|
render_layer_state();
|
||||||
|
render_space();
|
||||||
|
render_mod_status_gui_alt(get_mods()|get_oneshot_mods());
|
||||||
|
render_mod_status_ctrl_shift(get_mods()|get_oneshot_mods());
|
||||||
|
render_kb_LED_state();
|
||||||
|
}
|
||||||
|
void render_right(void) {
|
||||||
|
render_space_animation();
|
||||||
|
}
|
||||||
|
|
||||||
|
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
|
||||||
|
// define what's rendered on each half
|
||||||
|
if (is_keyboard_master()) {
|
||||||
|
render = render_left;
|
||||||
|
rotation = OLED_ROTATION_270;
|
||||||
|
} else {
|
||||||
|
render = render_right;
|
||||||
|
rotation = OLED_ROTATION_0;
|
||||||
|
}
|
||||||
|
animation_timer = timer_read();
|
||||||
|
return rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
void keyboard_post_init_user(void) {
|
||||||
|
// Customise these values to desired behaviour
|
||||||
|
//debug_enable=true;
|
||||||
|
//debug_matrix=true;
|
||||||
|
//debug_keyboard=true;
|
||||||
|
//debug_mouse=true;
|
||||||
|
}
|
||||||
|
|
||||||
bool oled_task_user(void) {
|
bool oled_task_user(void) {
|
||||||
// time for the next frame?
|
|
||||||
if (timer_elapsed(animation_timer) < FRAME_TIMEOUT) {
|
if (timer_elapsed(animation_timer) < FRAME_TIMEOUT) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (is_keyboard_master()) {
|
(*render)(); // call render_left() or render_right()
|
||||||
// Renders the current keyboard state (layers and mods)
|
|
||||||
render_logo();
|
|
||||||
render_logo_text();
|
|
||||||
render_space();
|
|
||||||
render_layer_state();
|
|
||||||
render_space();
|
|
||||||
render_mod_status_gui_alt(get_mods()|get_oneshot_mods());
|
|
||||||
render_mod_status_ctrl_shift(get_mods()|get_oneshot_mods());
|
|
||||||
render_kb_LED_state();
|
|
||||||
} else {
|
|
||||||
render_space_animation();
|
|
||||||
}
|
|
||||||
// reset timer after drawing the frame.
|
|
||||||
animation_timer = timer_read();
|
animation_timer = timer_read();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user