void fading_led_custom(uint8_t *value) { static uint8_t index = 0; static uint16_t last = 0; if (backlight_config.level == 7) { if (idle_state == 0) { uint8_t max = value[0]; for (uint8_t i = 1; i < LED_COUNT; i++) { if (value[i] > max) max = value[i]; } rgb_set_brightness(max); if (max == 0) { idle_last = timer_read(); idle_state = 1; } } if (idle_state == 1) { if (timer_elapsed(idle_last) > 3000) { breathing_led_set_index_all(0); index = 0; idle_state = 2; } } if (idle_state == 2) { if (timer_elapsed(last) > 500) { last = timer_read(); breathing_led_enable_once(index); index = (index + 1) % 6; } } } }
bool process_record_user(uint16_t keycode, keyrecord_t *record) { uint8_t layer; layer = biton32(layer_state); // get the current layer //custom layer handling for tri_layer, switch (keycode) { case FNKEY: if (record->event.pressed) { key_timer = timer_read(); singular_key = true; layer_on(_FUNCTION); } else { if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) { layer_off(_FUNCTION); } } update_tri_layer(_FUNCTION, _SHIFTED, _FUNCSHIFT); return false; break; //SHIFT is handled as LSHIFT in the general case case SHIFT: if (record->event.pressed) { key_timer = timer_read(); singular_key = true; layer_on(_SHIFTED); register_code(KC_LSFT); } else { if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) { layer_off(_SHIFTED); unregister_code(KC_LSFT); } } update_tri_layer(_FUNCTION, _SHIFTED, _FUNCSHIFT); return false; break; //If any other key was pressed during the layer mod hold period, //then the layer mod was used momentarily, and should block latching default: singular_key = false; break; } //FUNCSHIFT has been shifted by the SHIFT handling, some keys need to be excluded if (layer == _FUNCSHIFT) { //F1-F12 should be sent as unshifted keycodes, //and ] needs to be unshifted or it is sent as } if ( (keycode >= KC_F1 && keycode <= KC_F12) || keycode == KC_RBRC ) { if (record->event.pressed) { unregister_mods(MOD_LSFT); } else { register_mods(MOD_LSFT); } } } return true; };
void mousekey_task(void) { if (timer_elapsed(last_timer) < (mousekey_repeat ? mk_interval : mk_delay*10)) return; if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) return; if (mousekey_repeat != UINT8_MAX) mousekey_repeat++; if (mouse_report.x > 0) mouse_report.x = move_unit(); if (mouse_report.x < 0) mouse_report.x = move_unit() * -1; if (mouse_report.y > 0) mouse_report.y = move_unit(); if (mouse_report.y < 0) mouse_report.y = move_unit() * -1; /* diagonal move [1/sqrt(2) = 0.7] */ if (mouse_report.x && mouse_report.y) { mouse_report.x *= 0.7; mouse_report.y *= 0.7; } if (timer_elapsed(last_timer) < (mousekey_repeat ? mk_wheel_interval : mk_delay*10)) return; if (mouse_report.v > 0) mouse_report.v = wheel_unit(); if (mouse_report.v < 0) mouse_report.v = wheel_unit() * -1; if (mouse_report.h > 0) mouse_report.h = wheel_unit(); if (mouse_report.h < 0) mouse_report.h = wheel_unit() * -1; mousekey_send(); }
bool process_record_user(uint16_t keycode, keyrecord_t *record) { static uint16_t code_timer; switch (keycode) { case KC_MCBR: if(record->event.pressed){ code_timer= timer_read(); SEND_STRING("{"); } else { if (timer_elapsed(code_timer) > TAPPING_TERM) { SEND_STRING("}" SS_TAP(X_LEFT)); } } return false; break; case KC_MBRC: if(record->event.pressed){ code_timer= timer_read(); SEND_STRING("["); } else { if (timer_elapsed(code_timer) > TAPPING_TERM) { SEND_STRING("]" SS_TAP(X_LEFT)); } } return false; break; case KC_MPRN: if(record->event.pressed){ code_timer= timer_read(); SEND_STRING("("); } else { if (timer_elapsed(code_timer) > TAPPING_TERM) { SEND_STRING(")" SS_TAP(X_LEFT)); } } return false; break; case KC_MABK: if(record->event.pressed){ code_timer= timer_read(); if (get_mods() & MODS_SHIFT_MASK){ SEND_STRING("<"); } else { SEND_STRING(","); } } else { if (timer_elapsed(code_timer) > TAPPING_TERM) { if (get_mods() & MODS_SHIFT_MASK){ SEND_STRING(">" SS_TAP(X_LEFT)); } } } return false; break; } return true; }
void locinfo_print_time() { printf("locinfo total:\t\t\t%f\n" "\tfind_add_str:\t\t\t%f\n" "\tlocinfo_read:\t\t\t%f\n" "\tlocinfo_write:\t\t\t%f\n" ,timer_elapsed(locinfo_timer) ,timer_elapsed(locinfo_parse_find_add_str_timer) ,timer_elapsed(locinfo_read_timer) ,timer_elapsed(locinfo_write_timer) ); }
static void load_thread (void *seq_no_) { int seq_no = (int) seq_no_; int sleep_time = TIMER_FREQ * (10 + seq_no); int spin_time = sleep_time + TIMER_FREQ * THREAD_CNT; int exit_time = TIMER_FREQ * (THREAD_CNT * 2); timer_sleep (sleep_time - timer_elapsed (start_time)); while (timer_elapsed (start_time) < spin_time) continue; timer_sleep (exit_time - timer_elapsed (start_time)); }
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { static uint16_t start; // MACRODOWN only works in this function switch(id) { case 0: if (record->event.pressed) { register_code(KC_RSFT); } else { unregister_code(KC_RSFT); } break; case 1: if (record->event.pressed) { start = timer_read(); return MACRO(D(LCTRL), END); } else { if (timer_elapsed(start) > 150) { return MACRO(U(LCTRL), END); } else { return MACRO(U(LCTRL), D(LGUI), T(V), U(LGUI), END); } } break; case 2: if (record->event.pressed) { start = timer_read(); return MACRO(D(LCTRL),END); } else { if (timer_elapsed(start) > 150){ return MACRO(U(LCTRL),END); } else { return MACRO(U(LCTRL),D(LGUI),T(C),U(LGUI),END); } } break; case 3: if (record->event.pressed) { start = timer_read(); return MACRO(D(LCTRL),D(LSFT),D(LALT),END); } else { if (timer_elapsed(start) > 150){ return MACRO(U(LCTRL),U(LSFT),U(LALT),END); } else { return MACRO(U(LCTRL),U(LALT),T(EQL),U(LSFT),END); //cannot use DE_ACUT here, as macro needs KC_ prefix } } break; } return MACRO_NONE; };
int main(void) { byte* buffer; byte* pivots; size_t i; comb_init(); buffer = malloc(NUM_COMBS_ITER * COMB_SIZE); pivots = malloc(NUM_FILES * COMB_SIZE); for (i = 0; i < NUM_ITERS; i++) { printf("\nIteration %d of %d.\n\n", i + 1, NUM_ITERS); printf("Filling combinations buffer..."); timer_reset(); fill_comb_buffer(buffer); printf(" DONE in %fs.\n", timer_elapsed()); printf("Sorting combinations buffer..."); timer_reset(); qsort(buffer, NUM_COMBS_ITER, COMB_SIZE, comb_sum_cmp); printf(" DONE in %fs.\n", timer_elapsed()); if (i == 0) { printf("Creating output files..."); create_output_files(); printf(" DONE.\n"); printf("Getting and saving pivots..."); get_pivots(pivots, buffer); save_pivots(pivots); printf(" DONE.\n"); } printf("Saving sorted combinations buffer..."); timer_reset(); save_comb_buffer(buffer, pivots); printf(" DONE in %fs.\n", timer_elapsed()); } free(buffer); free(pivots); comb_free(); return 0; }
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { // MACRODOWN only works in this function switch(id) { //switch multiplexing for media, short tap for volume up, long press for play/pause case VOLU: if (record->event.pressed) { key_timer = timer_read(); // if the key is being pressed, we start the timer. } else { // this means the key was just released, so we can figure out how long it was pressed for (tap or "held down"). if (timer_elapsed(key_timer) > LONGPRESS_DELAY) { // LONGPRESS_DELAY being 150ms, the threshhold we pick for counting something as a tap. return MACRO(T(MPLY), END); } else { return MACRO(T(VOLU), END); } } break; //switch multiplexing for media, short tap for volume down, long press for next track case VOLD: if (record->event.pressed) { key_timer = timer_read(); } else { if (timer_elapsed(key_timer) > LONGPRESS_DELAY) { return MACRO(T(MNXT), END); } else { return MACRO(T(VOLD), END); } } break; //switch multiplexing for escape, short tap for escape, long press for context menu case ESCM: if (record->event.pressed) { key_timer = timer_read(); } else { if (timer_elapsed(key_timer) > LONGPRESS_DELAY) { return MACRO(T(APP), END); } else { return MACRO(T(ESC), END); } } break; break; } return MACRO_NONE; };
int main( int argc, char** argv ) { tick_t start, time; tick_t tick, freq, res; printf( "Timer test\n" ); timer_lib_initialize(); res = 0xFFFFFFFFFFFFFFFFULL; freq = timer_ticks_per_second(); start = timer_current(); while( 1 ) { time = timer_current(); do { tick = timer_elapsed_ticks( time ); } while( !tick ); if( tick < res ) res = tick; if( timer_elapsed( start ) > 10.0 ) break; } printf( "Resolution: %lfms (%d ticks)\n", 1000.0 * (double)timer_ticks_to_seconds( res ), (int)res ); timer_lib_shutdown(); return 0; }
void matrix_scan_tap_dance () { if (qk_tap_dance_state.keycode && timer_elapsed (qk_tap_dance_state.timer) > TAPPING_TERM) { process_tap_dance_action (qk_tap_dance_state.keycode); reset_tap_dance (&qk_tap_dance_state); } }
void test_mlfqs_block (void) { int64_t start_time; struct lock lock; ASSERT (thread_mlfqs); msg ("Main thread acquiring lock."); lock_init (&lock); lock_acquire (&lock); msg ("Main thread creating block thread, sleeping 25 seconds..."); thread_create ("block", PRI_DEFAULT, block_thread, &lock); timer_sleep (25 * TIMER_FREQ); msg ("Main thread spinning for 5 seconds..."); start_time = timer_ticks (); while (timer_elapsed (start_time) < 5 * TIMER_FREQ) continue; msg ("Main thread releasing lock."); lock_release (&lock); msg ("Block thread should have already acquired lock."); }
bool process_leader(uint16_t keycode, keyrecord_t *record) { // Leader key set-up if (record->event.pressed) { #ifdef LEADER_PER_KEY_TIMING leader_time = timer_read(); #endif if (!leading && keycode == KC_LEAD) { leader_start(); leading = true; #ifndef LEADER_PER_KEY_TIMING leader_time = timer_read(); #endif leader_time = timer_read(); leader_sequence_size = 0; leader_sequence[0] = 0; leader_sequence[1] = 0; leader_sequence[2] = 0; leader_sequence[3] = 0; leader_sequence[4] = 0; return false; } if (leading && timer_elapsed(leader_time) < LEADER_TIMEOUT) { leader_sequence[leader_sequence_size] = keycode; leader_sequence_size++; return false; } } return true; }
void scan_rgblight_fadeout(void) { // Don't effing change this function .... rgblight_sethsv is supppppper intensive bool litup = false; for (uint8_t light_index = 0 ; light_index < RGBLED_NUM ; ++light_index ) { if (lights[light_index].enabled && timer_elapsed(lights[light_index].timer) > 10) { rgblight_fadeout *light = &lights[light_index]; litup = true; if (light->life) { light->life -= 1; if (biton32(layer_state) == 0) { sethsv(light->hue + rand() % 0xF, 255, light->life, (LED_TYPE *)&led[light_index]); } light->timer = timer_read(); } else { if (light->enabled && biton32(layer_state) == 0) { rgblight_sethsv_default_helper(light_index); } litup = light->enabled = false; } } } if (litup && biton32(layer_state) == 0) { rgblight_set(); } }
/*! Sleeps for approximately TICKS timer ticks. Interrupts must be turned on. */ void timer_sleep(int64_t ticks) { int64_t start = timer_ticks(); ASSERT(intr_get_level() == INTR_ON); while (timer_elapsed(start) < ticks) thread_yield(); }
/* Sleeps for approximately TICKS timer ticks. Interrupts must be turned on. */ void timer_sleep (int64_t ticks) { int64_t start = timer_ticks (); ASSERT (intr_get_level () == INTR_ON); #if 0 /* pj1 */ while (timer_elapsed (start) < ticks) thread_yield (); #endif #if 1 /* pj1 */ if (ticks <= 0) return; /* add current thread to sleep thread list in order, * and set its wake up time. Then schedule a new thread. */ struct thread *cur = thread_current(); enum intr_level old_level; lock_acquire(&sleep_list_lock); old_level = intr_disable(); cur->wake_up_ticks = start + ticks; list_insert_ordered(&sleep_list, &cur->elem, (list_less_func *)cmp_thread_wake_ticks, NULL); lock_release(&sleep_list_lock); thread_block(); intr_set_level(old_level); #endif }
void test_mlfqs_load_60 (void) { int i; ASSERT (thread_mlfqs); start_time = timer_ticks (); msg ("Starting %d niced load threads...", THREAD_CNT); for (i = 0; i < THREAD_CNT; i++) { char name[16]; snprintf(name, sizeof name, "load %d", i); thread_create (name, PRI_DEFAULT, load_thread, NULL); } msg ("Starting threads took %d seconds.", timer_elapsed (start_time) / TIMER_FREQ); for (i = 0; i < 90; i++) { int64_t sleep_until = start_time + TIMER_FREQ * (2 * i + 10); int load_avg; //printf("LIST NUMBER : %d\n", get_list_size ()); timer_sleep (sleep_until - timer_ticks ()); load_avg = thread_get_load_avg (); msg ("After %d seconds, load average=%d.%02d.", i * 2, load_avg / 100, load_avg % 100); } }
void rgblight_effect_rgbtest(void) { static uint8_t pos = 0; static uint16_t last_timer = 0; static uint8_t maxval = 0; uint8_t g; uint8_t r; uint8_t b; if (timer_elapsed(last_timer) < pgm_read_word(&RGBLED_RGBTEST_INTERVALS[0])) { return; } if( maxval == 0 ) { LED_TYPE tmp_led; sethsv(0, 255, RGBLIGHT_LIMIT_VAL, &tmp_led); maxval = tmp_led.r; } last_timer = timer_read(); g = r = b = 0; switch( pos ) { case 0: r = maxval; break; case 1: g = maxval; break; case 2: b = maxval; break; } rgblight_setrgb(r, g, b); pos = (pos + 1) % 3; }
void rgblight_effect_rainbow_swirl(uint8_t interval) { static uint16_t current_hue = 0; static uint16_t last_timer = 0; uint16_t hue; uint8_t i; if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2])) { return; } last_timer = timer_read(); for (i = 0; i < RGBLED_NUM; i++) { hue = (360 / RGBLED_NUM * i + current_hue) % 360; sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); } rgblight_set(); if (interval % 2) { current_hue = (current_hue + 1) % 360; } else { if (current_hue - 1 < 0) { current_hue = 359; } else { current_hue = current_hue - 1; } } }
void Outro::on_draw() { if (m_snd_game_exit != NULL) { if (timer_elapsed() > static_cast<unsigned int>(m_snd_game_exit->length_in_ms) + 100) { next_state(); } } Globals g; g.render().DrawTile(0,0, g.values().res_w(), g.values().res_h(), m_img_mainmenu); string text1 = g.snd2txt().text(); string text2 = ""; if (text1.length() >= 25) { text2 = text1; text1.erase(25, string::npos); text2.erase(0, 25); } g.render().DrawText(500, 400, 1.0, 1.0, 1.0, text1); g.render().DrawText(500, 450, 1.0, 1.0, 1.0, text2); }
void reset_keyboard(void) { clear_keyboard(); #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) process_midi_all_notes_off(); #endif #ifdef AUDIO_ENABLE #ifndef NO_MUSIC_MODE music_all_notes_off(); #endif uint16_t timer_start = timer_read(); PLAY_SONG(goodbye_song); shutdown_user(); while(timer_elapsed(timer_start) < 250) wait_ms(1); stop_all_notes(); #else shutdown_user(); wait_ms(250); #endif // this is also done later in bootloader.c - not sure if it's neccesary here #ifdef BOOTLOADER_CATERINA *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific #endif bootloader_jump(); }
int handle_event_stop_going_down(int event, int order_table[N_FLOORS][N_BUTTONS]) { int next_state = STOP_GOING_DOWN; switch (event) { case EMERGENCY_BUTTON: activate_emergency(order_table); next_state = EMERGENCY; break; case GO_UP: if(timer_elapsed() > DOOR_DELAY){ close_door(); change_speed(S_STOP, S_UP); next_state = GOING_UP; }else{ next_state = STOP_GOING_UP; } break; case GO_DOWN: if(timer_elapsed() > DOOR_DELAY){ close_door(); change_speed(S_STOP, S_DOWN); next_state = GOING_DOWN; }else{ next_state = STOP_GOING_DOWN; } break; case STOP: if(timer_elapsed() > DOOR_DELAY){ close_door(); next_state = IDLE; }else{ next_state = STOP_GOING_DOWN; } break; case OBSTRUCTION: timer_set(); next_state = STOP_GOING_DOWN; break; } return next_state; }
int main(int argc, char *argv[]) { struct timer *timer = timer_new(); sleep(1); printf("Elapsed: %lu ms\n", timer_elapsed(timer, NULL)); timer_stop(timer); sleep(1); printf("Elapsed: %lu ms\n", timer_elapsed(timer, NULL)); timer_continue(timer); sleep(1); printf("Elapsed: %lu ms\n", timer_elapsed(timer, NULL)); timer_destroy(&timer); return 0; }
void matrix_scan_user(void) { if (runonce && timer_elapsed(my_timer) > 1000) { runonce = false; rgblight_sethsv(0x0, 0xff, 0x80); rgblight_mode(9); rgblight_enable(); } }
int main(void) { bool suspended = false; #if USB_COUNT_SOF uint16_t last_timer = timer_read(); #endif #if !defined(__AVR_ATmega32__) CLKPR = 0x80, CLKPR = 0; #endif #ifndef PS2_USE_USART uart_init(UART_BAUD_RATE); #endif keyboard_init(); host_set_driver(vusb_driver()); debug("initForUsbConnectivity()\n"); initForUsbConnectivity(); debug("main loop\n"); while (1) { #if USB_COUNT_SOF if (usbSofCount != 0) { suspended = false; usbSofCount = 0; last_timer = timer_read(); } else { // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1) if (timer_elapsed(last_timer) > 5) { suspended = true; /* uart_putchar('S'); _delay_ms(1); cli(); set_sleep_mode(SLEEP_MODE_PWR_DOWN); sleep_enable(); sleep_bod_disable(); sei(); sleep_cpu(); sleep_disable(); _delay_ms(10); uart_putchar('W'); */ } } #endif if (!suspended) { usbPoll(); // TODO: configuration process is incosistent. it sometime fails. // To prevent failing to configure NOT scan keyboard during configuration if (usbConfiguration && usbInterruptIsReady()) { keyboard_task(); } vusb_transfer_keyboard(); } } }
uint8_t matrix_scan(void) { for (uint8_t row = 0; row < MATRIX_ROWS; row++) { select_row(row); _delay_us(15); // without this wait it will read unstable value. 10? 50? matrix_row_t cols = read_cols(); if (cols) LedInfo1_On(); else LedInfo1_Off(); if (matrix_debouncing[row] != cols) { //dprintf("bounce %u\r\n", row); matrix_debouncing[row] = cols; debouncing_times[row] = timer_read(); debouncing[row] = true; } unselect_rows(); } for (uint8_t row = 0; row < MATRIX_ROWS; row++) { if (debouncing[row]) { LedInfo2_On(); if (timer_elapsed(debouncing_times[row]) > DEBOUNCE_TIME) { //dprintf("bounced %u\r\n", row); matrix[row] = matrix_debouncing[row]; debouncing[row] = false; send_row_to_other_side(row, matrix[row]); mcpu_send_typematrix_row(row, matrix[row]); animation_typematrix_row(row, matrix[row]); } } else { LedInfo2_Off(); } } splitbrain_communication_task(); #ifdef BACKLIGHT_ENABLE animate(); #endif return 1; }
static void load_thread (void *ti_) { struct thread_info *ti = ti_; int64_t sleep_time = 5 * TIMER_FREQ; int64_t spin_time = sleep_time + 30 * TIMER_FREQ; int64_t last_time = 0; thread_set_nice (ti->nice); timer_sleep (sleep_time - timer_elapsed (ti->start_time)); while (timer_elapsed (ti->start_time) < spin_time) { int64_t cur_time = timer_ticks (); if (cur_time != last_time) ti->tick_count++; last_time = cur_time; } }
/* Sleeps for approximately TICKS timer ticks. Interrupts must be turned on. */ void timer_sleep (int64_t ticks) { int64_t start = timer_ticks (); printf("Thread Name: %s\n", thread_name ()); ASSERT (intr_get_level () == INTR_ON); while (timer_elapsed (start) < ticks) thread_yield (); }
void matrix_scan_user() { for (uint8_t index = 0 ; index < TH_EVENTS_COUNT ; ++index ) { tap_hold_t *th_event = &th_events[index]; if ( th_event->is_pressed && timer_elapsed(th_event->timer) > LONGPRESS_DELAY) { register_code(th_event->kc_hold); unregister_code(th_event->kc_hold); th_event->is_pressed = false; } } }
void rgblight_effect_rainbow_mood(uint8_t interval) { static uint16_t current_hue = 0; static uint16_t last_timer = 0; if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_RAINBOW_MOOD_INTERVALS[interval])) { return; } last_timer = timer_read(); rgblight_sethsv_noeeprom_old(current_hue, rgblight_config.sat, rgblight_config.val); current_hue = (current_hue + 1) % 360; }