irom static app_action_t application_function_i2c_sensor_read(application_parameters_t ap)
{
	i2c_sensor_t sensor;

	sensor = atoi((*ap.args)[1]);

	if(!i2c_sensor_read(sensor, true, ap.size, ap.dst))
	{
		snprintf(ap.dst, ap.size, "> invalid i2c sensor: %d\n", (int)sensor);
		return(app_action_error);
	}

	return(app_action_normal);
}
irom static app_action_t application_function_i2c_sensor_dump(application_parameters_t ap)
{
	i2c_sensor_t sensor;
	uint16_t offset;
	bool_t all, verbose;
	char *orig_dst = ap.dst;

	all = false;
	verbose = false;

	if(ap.nargs > 1)
	{
		switch((uint8_t)atoi((*ap.args)[1]))
		{
			case(2):
				verbose = true;
			case(1):
				all = true;
			default:
				(void)0;
		}
	}

	for(sensor = 0; sensor < i2c_sensor_size; sensor++)
	{
		if(all || i2c_sensor_detected(sensor))
		{
			offset = i2c_sensor_read(sensor, verbose, ap.size, ap.dst);
			ap.dst	+= offset;
			ap.size	-= offset;
		}
	}

	if(ap.dst == orig_dst)
		snprintf(ap.dst, ap.size, "%s", "> no sensors detected\n");

	return(app_action_normal);
}
irom static app_action_t application_function_i2c_sensor_dump(const string_t *src, string_t *dst)
{
	i2c_sensor_t sensor;
	int option;
	bool_t all, verbose;
	int original_length = string_length(dst);

	all = false;
	verbose = false;

	if(parse_int(1, src, &option, 0) == parse_ok)
	{
		switch(option)
		{
			case(2):
				verbose = true;
			case(1):
				all = true;
			default:
				(void)0;
		}
	}

	for(sensor = 0; sensor < i2c_sensor_size; sensor++)
	{
		if(all || i2c_sensor_detected(sensor))
		{
			i2c_sensor_read(dst, sensor, verbose);
			string_cat(dst, "\n");
		}
	}

	if(string_length(dst) == original_length)
		string_cat(dst, "> no sensors detected\n");

	return(app_action_normal);
}
irom static app_action_t application_function_i2c_sensor_read(const string_t *src, string_t *dst)
{
	int intin;
	i2c_sensor_t sensor;

	if((parse_int(1, src, &intin, 0)) != parse_ok)
	{
		string_cat(dst, "> invalid i2c sensor\n");
		return(app_action_error);
	}

	sensor = (i2c_sensor_t)intin;

	if(!i2c_sensor_read(dst, sensor, true))
	{
		string_clear(dst);
		string_format(dst, "> invalid i2c sensor: %d\n", (int)sensor);
		return(app_action_error);
	}

	string_cat(dst, "\n");

	return(app_action_normal);
}