Beispiel #1
0
/*
 * key RIGHT pressed callback
 * args:
 *    data - pointer to user data
 *
 * asserts:
 *    data (device) is not null
 *
 * returns: error code
 */
int key_RIGHT_callback(void *data)
{
	v4l2_dev_t *device = (v4l2_dev_t *) data;

	/*assertions*/
	assert(device != NULL);

	if(device->has_pantilt_control_id)
    {
		int id = V4L2_CID_PAN_RELATIVE;
		int value = - device->pan_step;

		v4l2_ctrl_t *control = v4l2core_get_control_by_id(device, id);

		if(control)
		{
			control->value =  value;

			if(v4l2core_set_control_value_by_id(device, id))
				fprintf(stderr, "GUVCVIEW: error setting pan/tilt value\n");

			return 0;
		}
	}

	return -1;
}
Beispiel #2
0
/*
 * key RIGHT pressed callback
 * args:
 *    data - pointer to user data
 *
 * asserts:
 *    none
 *
 * returns: error code
 */
int key_RIGHT_callback(void *data)
{
	if(v4l2core_has_pantilt_id())
    {
		int id = V4L2_CID_PAN_RELATIVE;
		int value = - v4l2core_get_pan_step();

		v4l2_ctrl_t *control = v4l2core_get_control_by_id(id);

		if(control)
		{
			control->value =  value;

			if(v4l2core_set_control_value_by_id(id))
				fprintf(stderr, "GUVCVIEW: error setting pan/tilt value\n");

			return 0;
		}
	}

	return -1;
}
/*
 * load the device control values from a profile file
 * args:
 *   vd - pointer to video device data
 *   filename - profile filename
 *
 * asserts:
 *   vd is not null
 *
 * returns: error code (0 -E_OK)
 */
int load_control_profile(v4l2_dev_t *vd, const char *filename)
{
	/*assertions*/
	assert(vd != NULL);

	FILE *fp;
	int major=0, minor=0, rev=0;

	if((fp = fopen(filename,"r"))!=NULL)
	{
		char line[200];
		if(fgets(line, sizeof(line), fp) != NULL)
		{
			if(sscanf(line,"#V4L2/CTRL/%3i.%3i.%3i", &major, &minor, &rev) == 3)
			{
                //check standard version if needed
			}
			else
			{
				fprintf(stderr, "V4L2_CORE: (load_control_profile) no valid header found\n");
				fclose(fp);
				return(E_NO_DATA);
			}
		}
		else
		{
			fprintf(stderr, "V4L2_CORE: (load_control_profile) no valid header found\n");
            fclose(fp);
			return(E_NO_DATA);
		}

		while (fgets(line, sizeof(line), fp) != NULL)
		{
			int id = 0;
			int min = 0, max = 0, step = 0, def = 0;
			int32_t val = 0;
			int64_t val64 = 0;

			if ((line[0]!='#') && (line[0]!='\n'))
			{
				if(sscanf(line,"ID{0x%08x};CHK{%5i:%5i:%5i:%5i}=VAL{%5i}",
					&id, &min, &max, &step, &def, &val) == 6)
				{
					v4l2_ctrl_t *current = v4l2core_get_control_by_id(vd, id);

					if(current)
					{
                        /*check values*/
						if(current->control.minimum == min &&
						   current->control.maximum == max &&
						   current->control.step == step &&
						   current->control.default_value == def)
						{
							current->value = val;
						}
					}
				}
				else if(sscanf(line,"ID{0x%08x};CHK{0:0:0:0}=VAL64{%" PRId64 "}",
					&id, &val64) == 2)
				{
					v4l2_ctrl_t *current = v4l2core_get_control_by_id(vd, id);

					if(current)
					{
						current->value64 = val64;
					}
				}
				else if(sscanf(line,"ID{0x%08x};CHK{%5i:%5i:%5i:0}=STR{\"%*s\"}",
					&id, &min, &max, &step) == 5)
				{
					v4l2_ctrl_t *current = v4l2core_get_control_by_id(vd, id);

					if(current)
					{
                        /*check values*/
						if(current->control.minimum == min &&
						   current->control.maximum == max &&
						   current->control.step == step)
						{
							char str[max+1];
							char fmt[48];
							sprintf(fmt,"ID{0x%%*x};CHK{%%*i:%%*i:%%*i:0}==STR{\"%%%is\"}", max);
							sscanf(line, fmt, str);

							/*we are only scannig for max chars so this should never happen*/
							if(strlen(str) > max) /*FIXME: should also check (minimum +N*step)*/
							{
                                fprintf(stderr, "V4L2_CORE: (load_control_profile) string bigger than maximum buffer size (%i > %i)\n",
									(int) strlen(str), max);
								if(current->string)
									free(current->string);
								current->string = strndup(str, max); /*FIXME: does max includes '\0' ?*/
							}
							else
                            {
								if(current->string)
									free(current->string);
								current->string = strndup(str, strlen(str)+1);
							}
						}
					}
				}
			}
		}

		set_v4l2_control_values(vd);
		get_v4l2_control_values(vd);
	}
    else
    {
        fprintf(stderr, "V4L2_CORE: (load_control_profile) Could not open for %s read: %s\n",
			filename, strerror(errno));
        return (E_FILE_IO_ERR);
    }

    fclose(fp);
    return (E_OK);
}