Example #1
0
/**
 * Function called from inside lua to print a graphical representation of 
 * a color tracker packet. Send the relevant pieces of the color tracker 
 * data structure over as a ScripterMsg.
 */
int print_color_tracker(lua_State *_l) {
    cc3_track_pkt_t *pkt = checktracker(_l, 1);

    // only send messages if we're in debug mode
    if (debug_on) {
        init_packet();

        // first the ID we have to put it in two bytes
        // big endian
        put_slip_char(get_msg_id_most_repr(TRACKER_MSG_ID));
        put_slip_char(get_msg_id_least_repr(TRACKER_MSG_ID));
        
        // now the param count. 1 bytes
        put_slip_char(8);

        // now the parameters
        put_slip_integer(cc3_g_pixbuf_frame.width);  // image width
        put_slip_integer(cc3_g_pixbuf_frame.height); // image height
        put_slip_integer(pkt->centroid_x); // centroid x
        put_slip_integer(pkt->centroid_y); // centroid y
        put_slip_integer(pkt->x0); // x0
        put_slip_integer(pkt->y0); // y0
        put_slip_integer(pkt->x1); // x1
        put_slip_integer(pkt->y1); // y1

        finish_packet();
    }

    return 0;
}
Example #2
0
/**
 * Function called from inside lua to print an oval on the CamScripter. 
 * Send over the oval information (upper_left_x, upper_left_y, width, height).
 * Color is an optional argument.
 */
int print_oval(lua_State *_l) {
    int x, y, width, height;
    int red, green, blue;

    if (!debug_on) return 0;

    x = luaL_checkint(_l, 1);
    y = luaL_checkint(_l, 2);
    width = luaL_checkint(_l, 3);
    height = luaL_checkint(_l, 4);
    red = luaL_optnumber(_l, 5, 0); // colors are optional, 0 is the default
    green = luaL_optnumber(_l, 6, 0);
    blue = luaL_optnumber(_l, 7, 0);

    // now push them across to the CamScripter
    init_packet();
    
    put_slip_char(get_msg_id_most_repr(OVAL_MSG_ID));
    put_slip_char(get_msg_id_least_repr(OVAL_MSG_ID));

    put_slip_char(7); // number of params

    // now the parameters
    put_slip_integer(x);
    put_slip_integer(y);
    put_slip_integer(width);
    put_slip_integer(height);
    put_slip_integer(red);
    put_slip_integer(green);
    put_slip_integer(blue);

    finish_packet();

    return 0;
}
Example #3
0
/**
 * Function called from inside lua to print a line on the CamScripter.
 * Send over the relevant information (startx, starty, endx, endy).
 */
int print_line(lua_State *_l) {
    int start_x, start_y, end_x, end_y;
    int red, green, blue;

    if (!debug_on) return 0;

    start_x = luaL_checkint(_l, 1);
    start_y = luaL_checkint(_l, 2);
    end_x = luaL_checkint(_l, 3);
    end_y = luaL_checkint(_l, 4);
    red = luaL_optnumber(_l, 5, 0); // colors are optional, 0 is the default
    green = luaL_optnumber(_l, 6, 0);
    blue = luaL_optnumber(_l, 7, 0);

    // now push them across to the CamScripter
    init_packet();
    
    put_slip_char(get_msg_id_most_repr(LINE_MSG_ID));
    put_slip_char(get_msg_id_least_repr(LINE_MSG_ID));

    put_slip_char(7); // number of params

    // now the parameters
    put_slip_integer(start_x);
    put_slip_integer(start_y);
    put_slip_integer(end_x);
    put_slip_integer(end_y);
    put_slip_integer(red);
    put_slip_integer(green);
    put_slip_integer(blue);

    finish_packet();
    return 0;
}
Example #4
0
/**
 * Streams a message instead of getting the entire msg as a byte array
 * and then sending the bytes accross.
 */
void stream_msg(ScripterMsg* msg) {
	init_packet();
	// send header
	put_slip_char(get_msg_id_most_repr(msg->id));
	put_slip_char(get_msg_id_least_repr(msg->id));
	put_slip_char(msg->param_count);
		
	// send parameters
	MsgParam* param = msg->parameters;
	while(param != NULL) {
		// size is 3 bytes, so we first get
		// rid of most representative byte
		if (param->type == PT_BYTE_STREAM) {
			int size = (*(param->data.data_stream.fp_get_size))(&param->data.data_stream);
			put_slip_char(get_size_most_repr(size));
			put_slip_char(get_size_middle_repr(size));
			put_slip_char(get_size_least_repr(size));
			char *c = NULL;
			while( (c =(*(param->data.data_stream.fp_get_char))(&param->data.data_stream)) != NULL ) {
				put_slip_char(*c);
			}
		} else {
			put_slip_char(get_size_most_repr(param->data.data_blob.size));
			put_slip_char(get_size_middle_repr(param->data.data_blob.size));
			put_slip_char(get_size_least_repr(param->data.data_blob.size));
			int i;
			for(i=0; i<(int)param->data.data_blob.size; i++) {
				put_slip_char(*(param->data.data_blob.data+i));
			}
		}
		param = param->next_param;
	}
	finish_packet();	
}
Example #5
0
/**
 * Function called from within Lua to wipe the camscripter graphics area clean.
 * Just forward on across the serial port.
 */
int clear_graphics(lua_State *_l) {
    init_packet();
    put_slip_char(get_msg_id_most_repr(CLEAR_GRAPHICS_MSG_ID));
    put_slip_char(get_msg_id_least_repr(CLEAR_GRAPHICS_MSG_ID));
    put_slip_char(0); // number of params
    finish_packet();
    return 0;
}
Example #6
0
/**
 * Sends the picture currently in the pixbuf over serial
 */
int send_picture_msg(lua_State *_l) {
	uint32_t x, y;
  	uint32_t size_x, size_y;

    // only send if we're in debug mode
    if (debug_on) {
        init_packet();
        // First the header
        // first the ID we have to put it in two bytes
        // big endian
        put_slip_char(get_msg_id_most_repr(PPM_MSG_ID));
        put_slip_char(get_msg_id_least_repr(PPM_MSG_ID));
        
        // now the param count. 1 bytes
        put_slip_char(1);
        
        cc3_pixbuf_rewind(); // just in case
        uint8_t *row = cc3_malloc_rows(1);
        
        // now parameters
        size_x = cc3_g_pixbuf_frame.width;
        size_y = cc3_g_pixbuf_frame.height;
        char* head = malloc(20);
        sprintf(head,"P6\n%d %d\n255\n",size_x,size_y );
        uint32_t size = strlen(head)+size_x*size_y*3;
        
        // size is 3 bytes, so we first get
        // rid of most representative byte
        put_slip_char(get_size_most_repr(size));
        put_slip_char(get_size_middle_repr(size));
        put_slip_char(get_size_least_repr(size));
        put_slip_string(head);
        free(head);
        
		bool led_on = false;
        for (y = 0; y < size_y; y++) {
            cc3_pixbuf_read_rows(row, 1);
        	cc3_led_set_state(0, led_on=!led_on);
            for (x = 0; x < size_x * 3U; x++) {
                /* Sleep to prevent byte-loss. Seems a bit extreme, but 
                   I saw problems with even 1000 and 500 as intervals. */
                if (x % 100 == 0) {
                    cc3_timer_wait_ms (5);
                }
                put_slip_char(row[x]);
            }
        }
        cc3_led_set_state(0, false);
        free(row);
        finish_packet();
    }    
    return 0;
}