static void shell_cmd_load(char *args, void *data) { struct shell_argval argval[SHELL_CMD_LOAD_ARGS+1], *idx, *tab; unsigned char t, j; t = shell_arg_parser(args, argval, SHELL_CMD_LOAD_ARGS); idx = shell_get_argval(argval, 'i'); tab = shell_get_argval(argval, 't'); if ((t != 1) && ((idx == NULL) && (tab == NULL))) { shell_printf("load tab: [-i <tab index> | -t <tab number>]\n"); shell_printf(" -i <tab index> tab index (0 to %d)\n", tab_list[0]-1); shell_printf(" -t <tab id> tab id\n"); } else { if (idx != NULL) { j = atoi(idx->val); if (j < tab_list[0]) { shell_printf("Loading tab index %d of %d\n", j, tab_list[0]-1); load_tab(tab_list[j+1]); } else { shell_printf("Out of range [0 ... %d]\n", tab_list[0]-1); } } else { j = atoi(tab->val); shell_printf("Loading tab id %d\n", j); load_tab(j); } } }
static void build_tab_list(void) { struct widget_config *wcfg = &config.widgets[0]; unsigned char *p = &tab_list[1]; /* build tab list */ tab_list[0] = 0; while (wcfg->tab != TABS_END) { if (!search_on_list(tab_list, wcfg->tab)) { *p++ = wcfg->tab; tab_list[0]++; } wcfg++; if (tab_list[0] > (MAX_TABS-2)) break; } /* add an empty tab (tab 255) at the end */ *p++ = 255; tab_list[0]++; #if 0 DTABS("found %d tabs\n", tab_list[0]); int i; for (i = 0; i < tab_list[0]; i++) DTABS(" tab%d = %d\n", i, tab_list[i+1]); #endif /* load first tab */ load_tab(tab_list[1]); }
void tabs_init(void) { /* add mavlink parameters */ params_add(params_tabs); /* build tab list from config */ build_tab_list(); /* 5 seconds on tab 0 */ load_tab(0); add_timer(TIMER_ONCE, 5000, start_tab_switch_task, &config.tab_sw); }
static void tab_switch_flightmode_cbk(mavlink_message_t *msg, void *d) { unsigned char mav_type; val = mavlink_msg_heartbeat_get_custom_mode(msg); mav_type = mavlink_msg_heartbeat_get_type(msg); if (mav_type != MAV_TYPE_FIXED_WING) val += 100; /* don't switch tab in case failsafe triggers */ switch (val) { case PLANE_MODE_CIRCLE: case PLANE_MODE_AUTO: case PLANE_MODE_RTL: case PLANE_MODE_LOITER: case COPTER_MODE_AUTO: case COPTER_MODE_LOITER: case COPTER_MODE_RTL: case COPTER_MODE_CIRCLE: return; default: break; } if (val != prev_val) { /* mode changed */ DTABS("flightmode_cbk: mode has changed: tmr=%d source_mode=%d mode=%d\n", tmr, source_mode, val); if (tmr != TAB_TIMER_IDLE) { if (source_mode == val) { /* change to next tab */ DTABS("flightmode_cbk: back to the same mode in less than 2 sec\n"); active_tab_idx++; if (active_tab_idx >= tab_list[0]) active_tab_idx = 0; load_tab(tab_list[active_tab_idx+1]); } tmr = TAB_TIMER_IDLE; } else { DTABS("flightmode_cbk: starting timer\n"); tmr = 0; source_mode = prev_val; } prev_val = val; } }
int main (void) { mp_int p, q; char buf[4096]; int k, li; clock_t t1; srand (time (NULL)); load_tab(); printf ("Enter # of bits: \n"); fgets (buf, sizeof (buf), stdin); sscanf (buf, "%d", &k); printf ("Enter number of bases to try (1 to 8):\n"); fgets (buf, sizeof (buf), stdin); sscanf (buf, "%d", &li); mp_init (&p); mp_init (&q); t1 = clock (); pprime (k, li, &p, &q); t1 = clock () - t1; printf ("\n\nTook %ld ticks, %d bits\n", t1, mp_count_bits (&p)); mp_toradix (&p, buf, 10); printf ("P == %s\n", buf); mp_toradix (&q, buf, 10); printf ("Q == %s\n", buf); return 0; }
static void tab_switch_task(struct timer *t, void *d) { struct tab_change_config *cfg = (struct tab_change_config*) d; unsigned int idx; unsigned char new_tab; if (get_millis() < 5000) { if (active_tab != 0) load_tab(0); return; } else if (active_tab == 0) { load_tab(1); } switch (cfg->mode) { case TAB_CHANGE_CHANNEL: default: idx = ((val * tab_list[0]) / 101) + 1; new_tab = tab_list[idx]; if (new_tab != active_tab) { DTABS("tab_change_channel: change to tab %d\n", new_tab); load_tab((unsigned char) new_tab); } break; case TAB_CHANGE_FLIGHTMODE: /* idle */ if (tmr == TAB_TIMER_IDLE) { break; } else if (tmr < cfg->time_window) { tmr++; } else { tmr = TAB_TIMER_IDLE; } break; case TAB_CHANGE_TOGGLE: /* idle val not acquired */ if (val == 0) break; /* idle */ if (tmr == TAB_TIMER_IDLE) { break; } else if (tmr < cfg->time_window) { tmr++; /* switch returned to idle position */ if (prev_val == val) { /* next tab */ active_tab_idx++; if (active_tab_idx >= tab_list[0]) active_tab_idx = 0; load_tab(tab_list[active_tab_idx+1]); tmr = TAB_TIMER_IDLE; } } else if (tmr == cfg->time_window) { tmr++; /* previous tab */ if (active_tab_idx == 0) active_tab_idx = tab_list[0]-1; else active_tab_idx--; load_tab(tab_list[active_tab_idx+1]); } else { /* wait until switch returns to idle state */ if (val == prev_val) tmr = TAB_TIMER_IDLE; } break; case TAB_CHANGE_DEMO: tmr++; if (tmr > cfg->time_window) { /* next tab */ active_tab_idx++; if (active_tab_idx >= tab_list[0]) active_tab_idx = 0; load_tab(tab_list[active_tab_idx+1]); tmr = 0; } break; } }
void start_tab_switch_task(struct timer *t, void *d) { load_tab(1); /* tab switching task (100ms) */ add_timer(TIMER_ALWAYS, 100, tab_switch_task, d); }
static void tab_switch_task(struct timer *t, void *d) { static unsigned char tmr = TAB_TIMER_IDLE; static unsigned char prev_val = 255, active_tab_idx = 0, source_mode = 0xff; struct ch_switch *cfg = d; unsigned int val; u32 ch_age; switch (cfg->mode) { case SW_MODE_CHANNEL: default: val = get_sw_state(cfg, &ch_age); val = ((val * tab_list[0]) / 101) + 1; if ((unsigned char) val != prev_val) { DTABS("tab_change_channel: change to tab %d\n", tab_list[val]); load_tab((unsigned char) tab_list[val]); prev_val = (unsigned char) val; } break; case SW_MODE_TOGGLE: val = get_sw_state(cfg, &ch_age); if (ch_age > 2000) break; if (val < 50) val = 1; else val = 2; /* store idle position */ if (prev_val == 255) prev_val = (unsigned char) val; /* idle */ if (tmr == TAB_TIMER_IDLE) { if ((unsigned char) val != prev_val) tmr = 0; } else if (tmr < cfg->time) { tmr++; /* switch returned to idle position */ if (prev_val == (unsigned char) val) { /* next tab */ active_tab_idx++; if (active_tab_idx >= tab_list[0]) active_tab_idx = 0; load_tab(tab_list[active_tab_idx+1]); tmr = TAB_TIMER_IDLE; } } else if (tmr == cfg->time) { tmr++; /* previous tab */ if (active_tab_idx == 0) active_tab_idx = tab_list[0]-1; else active_tab_idx--; load_tab(tab_list[active_tab_idx+1]); } else { /* wait until switch returns to idle state */ if ((unsigned char) val == prev_val) tmr = TAB_TIMER_IDLE; } break; case SW_MODE_FLIGHTMODE: { mavlink_heartbeat_t *hb = mavdata_get(MAVLINK_MSG_ID_HEARTBEAT); unsigned char i; const unsigned char mode_ignore_list[] = { PLANE_MODE_CIRCLE, PLANE_MODE_AUTO, PLANE_MODE_RTL, PLANE_MODE_LOITER, COPTER_MODE_AUTO, COPTER_MODE_LOITER, COPTER_MODE_RTL, COPTER_MODE_CIRCLE, }; if (tmr < cfg->time) tmr++; else tmr = TAB_TIMER_IDLE; val = (unsigned char) hb->custom_mode; if (hb->type != MAV_TYPE_FIXED_WING) val += 100; /* don't switch tab in case failsafe triggers */ for (i = 0; i < sizeof(mode_ignore_list); i++) if (mode_ignore_list[i] == (unsigned char) val) return; if ((unsigned char) val != prev_val) { /* mode changed */ DTABS("flightmode_cbk: mode has changed: tmr=%d source_mode=%d mode=%d\n", tmr, source_mode, val); if (tmr != TAB_TIMER_IDLE) { if (source_mode == (unsigned char) val) { /* change to next tab */ DTABS("flightmode_cbk: back to the same mode in less than 2 sec\n"); active_tab_idx++; if (active_tab_idx >= tab_list[0]) active_tab_idx = 0; load_tab(tab_list[active_tab_idx+1]); } tmr = TAB_TIMER_IDLE; } else { DTABS("flightmode_cbk: starting timer\n"); tmr = 0; source_mode = prev_val; } prev_val = (unsigned char) val; } break; } case SW_MODE_DEMO: tmr++; if (tmr > cfg->time) { /* next tab */ active_tab_idx++; if (active_tab_idx >= tab_list[0]) active_tab_idx = 0; load_tab(tab_list[active_tab_idx+1]); tmr = 0; } break; } }