static void menu_store(void *ud) { priv_t *pr = PRIV(app_current); svc_compass_cal_in_t ci = { .x0 = minmax_get_center(&(pr->cal_x)), .y0 = minmax_get_center(&(pr->cal_y)), .z0 = minmax_get_center(&(pr->cal_z)), .sx = minmax_get_span(&(pr->cal_x)), .sy = minmax_get_span(&(pr->cal_y)), .sz = minmax_get_span(&(pr->cal_z)), }; svc_compass_set_cal(&ci); } static const svc_menu_item_text_t menu_item_store = { .type = SVC_MENU_ITEM_T_TEXT, .text = "store", .handler = menu_store }; static const svc_menu_item_unknown_t *menu_items[] = { (void*)&menu_item_x_c, (void*)&menu_item_y_c, (void*)&menu_item_z_c, (void*)&menu_item_x_s, (void*)&menu_item_y_s, (void*)&menu_item_z_s, (void*)&menu_item_store }; static const svc_menu_t menu = { .n_items = ARRAY_SIZE(menu_items), .items = (void*)menu_items, .handler_exit = menu_exit, .header = "cc", .header_pos = 8 }; void app_app_compass_cal_main(uint8_t view, const app_t *app, svc_main_proc_event_t event) { priv_t *p = PRIV(app); hal_compass_result_t r; if(!svc_compass_read(&r)) { minmax_update(&(p->cal_x), r.x); minmax_update(&(p->cal_y), r.y); minmax_update(&(p->cal_z), r.z); } svc_menu_run(&menu, &(PRIV(app)->cal_menu_state), event); return; } void app_app_compass_cal_enter(uint8_t view, const app_t *app) { priv_t *p = PRIV(app); minmax_init(&(p->cal_x)); minmax_init(&(p->cal_y)); minmax_init(&(p->cal_z)); }
void rpm_init (void) { // Enable timer3 overflow interrupt TIMSK3 = BV (TOIE3); TCCR3A = 0; // not using output compare pins TCCR3B = BV (CS32); // Set Normal mode, CLK/256 prescaler DDRE &= ~BV (5); // port E5 as input (INT5) PORTE |= BV (5); // turn on pullup on E5 EICRB |= BV (ISC50) | BV (ISC51); // interrupt on rising edge EIMSK |= BV (INT5); // enable int 5 median_init (&RpmMedian, 10); minmax_init(&RpmHourMax, 60, true); }