/* function name: draw_contour * Input Parameter * maze : maze array wich has maze information * map : array to draw contour map * type : maze type to run mouse * pos : current mouse location in the maze */ void draw_contour(unsigned char *maze, unsigned char *map, unsigned int type, unsigned char pos) { int i, contour_lvl = 1; int index; unsigned int item; char found_mouse = 0; struct circular_buffer *cb, contour_buffer; cb = &contour_buffer; circular_buffer_init(cb, contour_cb_buffer, CONTOUR_CB_BUFFER_MAX); /* Uninitialized contour map */ memset(map, 0, MAZEMAX); /* Seed value 1 as a goal */ switch (type) { case TO_GOAL_4X4: map[get_index(3, 3)] = contour_lvl; circular_buffer_write(cb, gen_contour_pos(contour_lvl, 0x33)); break; case TO_GOAL_8X8: map[get_index(7, 7)] = contour_lvl; circular_buffer_write(cb, gen_contour_pos(contour_lvl, 0x77)); break; case TO_GOAL_16X16: map[get_index(7, 7)] = contour_lvl; map[get_index(8, 7)] = contour_lvl; map[get_index(7, 8)] = contour_lvl; map[get_index(8, 8)] = contour_lvl; /* Add list of same level contour value */ circular_buffer_write(cb, gen_contour_pos(contour_lvl, 0x77)); circular_buffer_write(cb, gen_contour_pos(contour_lvl, 0x78)); circular_buffer_write(cb, gen_contour_pos(contour_lvl, 0x87)); circular_buffer_write(cb, gen_contour_pos(contour_lvl, 0x88)); break; case TO_START_4X4: case TO_START_8X8: case TO_START_16X16: map[get_index(0, 0)] = contour_lvl; circular_buffer_write(cb, gen_contour_pos(contour_lvl, 0x00)); break; default: if (type < MAZEMAX) { map[type] = contour_lvl; circular_buffer_write(cb, gen_contour_pos(contour_lvl, type)); } else { print_exit("Invalid target goal index!\n"); } break; } /* Get one contour number from circular buffer. * Put next higher value in next block if there is * no wall to there and save it inti circular buffer. * If contour map reaches to current mouse or * circular buffer is empty then it's done. */ while (!circular_buffer_empty(cb) && !found_mouse) { circular_buffer_read(cb, &item); index = get_contour_index(item); contour_lvl = get_contour_lvl(item) + 1; /* Calculate contour lvl around current cube */ for (i = NI; i <= WI; i++) { if (!(maze[index] & wall_bit(i)) && (map[index + maze_dxy[i]] == 0)) { map[index + maze_dxy[i]] = contour_lvl; circular_buffer_write(cb, gen_contour_pos(contour_lvl, index + maze_dxy[i])); if (index + maze_dxy[i] == pos) found_mouse = 1; } } #ifdef DEBUG if (debug_flag & DEBUG_CONTOUR) { print_map(map); usleep(20000); } #endif } if (!found_mouse) { /* Mouse alorighm should never hit this location */ print_map(map); print_exit("%s couldn't find mouse location\n", __func__); } }
void camera_start(void) { MMAL_STATUS_T status; motion_init(); circular_buffer_init(); camera_create(); /* ====== Create the camera preview port path ====== : | preview --(tunnel)--> resizer --> I420_callback --> jpeg_encoder --> mjpeg_callback | (draws on frame) (writes stream mjpeg.jpg) */ pikrellcam.mjpeg_height = pikrellcam.mjpeg_width * pikrellcam.camera_config.video_height / pikrellcam.camera_config.video_width; pikrellcam.mjpeg_width &= ~0xf; /* Make resize multiple of 16 */ pikrellcam.mjpeg_height &= ~0xf; resizer_create("stream_resizer", &stream_resizer, camera.component->output[CAMERA_PREVIEW_PORT], pikrellcam.mjpeg_width, pikrellcam.mjpeg_height); ports_tunnel_connect(&camera, CAMERA_PREVIEW_PORT, &stream_resizer); jpeg_encoder_create("mjpeg_encoder", &mjpeg_encoder, stream_resizer.component->output[0], pikrellcam.mjpeg_quality); ports_callback_connect(&stream_resizer, 0, &mjpeg_encoder, I420_video_callback); out_port_callback(&mjpeg_encoder, 0, mjpeg_callback); /* ====== Create the camera still port path ====== : | camera_capture --(tunnel)--> jpeg_encoder --> still_jpeg__callback | (writes stills and timelapse jpegs) */ jpeg_encoder_create("still_jpeg_encoder", &still_jpeg_encoder, NULL, pikrellcam.camera_adjust.still_quality); ports_tunnel_connect(&camera, CAMERA_CAPTURE_PORT, &still_jpeg_encoder); out_port_callback(&still_jpeg_encoder, 0, still_jpeg_callback); /* ====== Create the camera video port path ====== : | camera_video--(tunnel)-->h264 encoder-->video_h264_encoder_callback | (writes data into video circular buffer) | (records video / checks motion vectors) | (schedules mjpeg.jpg copy into previews) */ h264_encoder_create("video_h264_encoder", &video_h264_encoder, NULL); ports_tunnel_connect(&camera, CAMERA_VIDEO_PORT, &video_h264_encoder); out_port_callback(&video_h264_encoder, 0, video_h264_encoder_callback); time(&pikrellcam.t_start); /* Turn on the video stream. It free runs into the video circular buffer. */ if ((status = mmal_port_parameter_set_boolean( camera.component->output[CAMERA_VIDEO_PORT], MMAL_PARAMETER_CAPTURE, 1)) != MMAL_SUCCESS) log_printf("Video capture startup failed. Status %s\n", mmal_status[status]); /* With everything created and running, set the config'ed camera params. */ mmalcam_config_parameters_set_camera(); display_init(); video_circular_buffer.state = VCB_STATE_NONE; video_circular_buffer.pause = FALSE; }
void ma_filter_initialize(ma_filter* empty, circular_buffer* cb_data, float* buffer) { circular_buffer_init(cb_data, buffer, MA_FILTER_DEPTH); empty->cb = cb_data; empty->average = 0; }