void image_get() { int i, t, index; char *filename; for (t = 0; t < IMAGE_QUERY_TURN; t++) { printf("%d .. ", IMAGE_QUERY_TURN - t); fflush(stdout); for (i = 0; i < video.buffer.req.count; i++) { buffer_dequeue(i); buffer_enqueue(i); } } printf("%d ..\n", IMAGE_QUERY_TURN - t); fflush(stdout); index = 0; buffer_dequeue(index); update_image_pixels(index); filename = get_file_name("swc", "jpeg"); save_image(filename); printf("%s saved.\n", filename); free(filename); buffer_enqueue(index); }
void screen_mainloop () { int i; for (i = 0; screen.running && i <= video.buffer.req.count; i++) { if (i == video.buffer.req.count) { i = 0; } buffer_dequeue (i); update_rgb_surface (i); if (SDL_PollEvent (&screen.event) == 1) { switch (screen.event.type) { case SDL_KEYDOWN: switch (screen.event.key.keysym.sym) { case SDLK_q: puts ("bye"); screen.running = 0; break; default: break; } break; case SDL_QUIT: screen.running = 0; break; default: break; } } buffer_enqueue (i); } }
void send_buffered_ints_rs485() { if (buffer_count_elements(&sendBuffer) > 0) { struct Candy* candy = buffer_dequeue(&sendBuffer); // We convert the int to an array of 4 bytes int value = candy->rpmTicksStamp; U8 buffer[INT_SIZE]; buffer[0] = (U8)value; value >>= 8; buffer[1] = (U8)value; value >>= 8; buffer[2] = (U8)value; value >>= 8; buffer[3] = (U8)value; // We calculate the checksum for the 4 bytes crc_t crc; crc = crc_init(); crc = crc_update(crc, (unsigned char *)buffer, INT_SIZE); crc = crc_finalize(crc); // We pack all the bytes in one array and sends it U8 toSend[INT_SIZE + 1]; toSend[0] = (U8)crc; toSend[1] = buffer[0]; toSend[2] = buffer[1]; toSend[3] = buffer[2]; toSend[4] = buffer[3]; ecrobot_send_rs485(toSend, 0, INT_SIZE+1); } }