// // main_window_load // static void main_window_load(Window *window) { int i = 0; for( i = 0; i < MAX_DOTS;i++ ) { dotX[i] = -1; dotY[i] = -1; dotVelocity[i] = 1; } comms_init(); // // Create black background ... s_bmap_bg = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_EARTH); // bitmap_layer_set_background_color( s_bmap_bg, GColorBlack ); s_canvas = layer_create(GRect(0, 0, 144, 168)); s_sprite = sprite_add( RESOURCE_ID_IMAGE_ROCKET, 30, 42, 50, 100 ); s_sprite->offset_y = 40; Layer* motherLayer = window_get_root_layer(s_main_window); layer_set_update_proc(s_canvas, updateFast); // Black background. // yer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bmap_bg)); // Fast animation layer. layer_add_child(motherLayer, s_canvas); TICK_RATE_MS = FPS30; app_timer_register( TICK_RATE_MS , tick_fast_handler, NULL); }
void comms_main(void) { comms_init(); struct pollfd fds; fds.fd = fmu_fd; fds.events = POLLIN; debug("FMU: ready"); for (;;) { /* wait for serial data, but no more than 10ms */ poll(&fds, 1, 10); /* * Pull bytes from FMU and feed them to the HX engine. * Limit the number of bytes we actually process on any one iteration. */ if (fds.revents & POLLIN) { char buf[32]; ssize_t count = read(fmu_fd, buf, sizeof(buf)); for (int i = 0; i < count; i++) hx_stream_rx(stream, buf[i]); } /* * Decide if it's time to send an update to the FMU. */ static hrt_abstime last_report_time; hrt_abstime now, delta; /* should we send a report to the FMU? */ now = hrt_absolute_time(); delta = now - last_report_time; if ((delta > FMU_MIN_REPORT_INTERVAL) && (system_state.fmu_report_due || (delta > FMU_MAX_REPORT_INTERVAL))) { system_state.fmu_report_due = false; last_report_time = now; /* populate the report */ for (unsigned i = 0; i < system_state.rc_channels; i++) { report.rc_channel[i] = system_state.rc_channel_data[i]; } report.channel_count = system_state.rc_channels; report.armed = system_state.armed; report.battery_mv = system_state.battery_mv; report.adc_in = system_state.adc_in5; report.overcurrent = system_state.overcurrent; /* and send it */ hx_stream_send(stream, &report, sizeof(report)); } /* * Fetch ADC values, check overcurrent flags, etc. */ static hrt_abstime last_status_time; if ((now - last_status_time) > FMU_STATUS_INTERVAL) { /* * Coefficients here derived by measurement of the 5-16V * range on one unit: * * V counts * 5 1001 * 6 1219 * 7 1436 * 8 1653 * 9 1870 * 10 2086 * 11 2303 * 12 2522 * 13 2738 * 14 2956 * 15 3172 * 16 3389 * * slope = 0.0046067 * intercept = 0.3863 * * Intercept corrected for best results @ 12V. */ unsigned counts = adc_measure(ADC_VBATT); system_state.battery_mv = (4150 + (counts * 46)) / 10; system_state.adc_in5 = adc_measure(ADC_IN5); system_state.overcurrent = (OVERCURRENT_SERVO ? (1 << 0) : 0) | (OVERCURRENT_ACC ? (1 << 1) : 0); last_status_time = now; } } }