Exemplo n.º 1
0
static void thermal_loop()
{
    LOGI("Thermal daemon started.");
    while(1) {
        temperature_check();
        sleep(5);
    }
}
Exemplo n.º 2
0
// Run the tests for each of the temperature setpoints.
// ambient_temps MUST have 7 values or we'll segfault.
void test_temperature_spread( player *p, int ambient_temps[] )
{
    temperature_check( p, ambient_temps[0], BODYTEMP_FREEZING );
    temperature_check( p, ambient_temps[1], BODYTEMP_VERY_COLD );
    temperature_check( p, ambient_temps[2], BODYTEMP_COLD );
    temperature_check( p, ambient_temps[3], BODYTEMP_NORM );
    temperature_check( p, ambient_temps[4], BODYTEMP_HOT );
    temperature_check( p, ambient_temps[5], BODYTEMP_VERY_HOT );
    temperature_check( p, ambient_temps[6], BODYTEMP_SCORCHING );
}
void max77833_vibtonz_en(bool en)
{
	int error = 0, temperature_level;
	if (g_hap_data == NULL) {
		pr_err("[VIB] the motor is not ready!!!");
		return ;
	}

	if (en) {
		if (g_hap_data->running)
			return;
		max77833_haptic_i2c(g_hap_data, true);
		temperature_level = temperature_check();

		if (temperature_level != prev_temperature_level) {
			switch(temperature_level)
			{
				case 0:
					error = max77833_write_reg(g_hap_data->i2c,
						MAX77833_AUTORES_MIN_FREQ_LOW, g_hap_data->pdata->auto_res_min_low_low_temp);
					if (error < 0) {
						pr_err("[VIB] %s Failed to write REG(0x%02x) [%d]\n",
						__func__, MAX77833_AUTORES_MIN_FREQ_LOW, error);
					}
					error = max77833_write_reg(g_hap_data->i2c,
						MAX77833_AUTORES_MAX_FREQ_LOW, g_hap_data->pdata->auto_res_max_low_low_temp);
					if (error < 0) {
						pr_err("[VIB] %s Failed to write REG(0x%02x) [%d]\n",
						__func__, MAX77833_AUTORES_MAX_FREQ_LOW, error);
					}
					error = max77833_write_reg(g_hap_data->i2c,
						MAX77833_AUTORES_INIT_GUESS_LOW, g_hap_data->pdata->auto_res_init_low_low_temp);
					if (error < 0) {
						pr_err("[VIB] %s Failed to write REG(0x%02x) [%d]\n",
						__func__, MAX77833_AUTORES_INIT_GUESS_LOW, error);
					}
					break;
				case 1:
					error = max77833_write_reg(g_hap_data->i2c,
						MAX77833_AUTORES_MIN_FREQ_LOW, g_hap_data->pdata->auto_res_min_low);
					if (error < 0) {
						pr_err("[VIB] %s Failed to write REG(0x%02x) [%d]\n",
						__func__, MAX77833_AUTORES_MIN_FREQ_LOW, error);
					}
					error = max77833_write_reg(g_hap_data->i2c,
						MAX77833_AUTORES_MAX_FREQ_LOW, g_hap_data->pdata->auto_res_max_low);
					if (error < 0) {
						pr_err("[VIB] %s Failed to write REG(0x%02x) [%d]\n",
						__func__, MAX77833_AUTORES_MAX_FREQ_LOW, error);
					}
					error = max77833_write_reg(g_hap_data->i2c,
						MAX77833_AUTORES_INIT_GUESS_LOW, g_hap_data->pdata->auto_res_init_low);
					if (error < 0) {
						pr_err("[VIB] %s Failed to write REG(0x%02x) [%d]\n",
						__func__, MAX77833_AUTORES_INIT_GUESS_LOW, error);
					}
					break;
				case 2:
					error = max77833_write_reg(g_hap_data->i2c,
						MAX77833_AUTORES_MIN_FREQ_LOW, g_hap_data->pdata->auto_res_min_low_high_temp);
					if (error < 0) {
						pr_err("[VIB] %s Failed to write REG(0x%02x) [%d]\n",
						__func__, MAX77833_AUTORES_MIN_FREQ_LOW, error);
					}
					error = max77833_write_reg(g_hap_data->i2c,
						MAX77833_AUTORES_MAX_FREQ_LOW, g_hap_data->pdata->auto_res_max_low_high_temp);
					if (error < 0) {
						pr_err("[VIB] %s Failed to write REG(0x%02x) [%d]\n",
						__func__, MAX77833_AUTORES_MAX_FREQ_LOW, error);
					}
					error = max77833_write_reg(g_hap_data->i2c,
						MAX77833_AUTORES_INIT_GUESS_LOW, g_hap_data->pdata->auto_res_init_low_high_temp);
					if (error < 0) {
						pr_err("[VIB] %s Failed to write REG(0x%02x) [%d]\n",
						__func__, MAX77833_AUTORES_INIT_GUESS_LOW, error);
					}
					break;
				default:
					pr_err("[VIB] %s Failed to read temperature [%d]\n",
					__func__, temperature_level);
					break;
			}
		}
		prev_temperature_level = temperature_level;

		pwm_config(g_hap_data->pwm, prev_duty, g_hap_data->pdata->period);
		pwm_enable(g_hap_data->pwm);

		g_hap_data->running = true;

	} else {
		if (!g_hap_data->running)
			return;
		pwm_disable(g_hap_data->pwm);
		max77833_haptic_i2c(g_hap_data, false);
		g_hap_data->running = false;
	}
}
static void haptic_work(struct work_struct *work)
{
	struct max77833_haptic_data *hap_data
		= container_of(work, struct max77833_haptic_data, work);
	int error = 0, temperature_level;

	pr_info("[VIB] %s\n", __func__);
	if (hap_data->timeout > 0) {
		if (hap_data->running)
			return;
		max77833_haptic_i2c(hap_data, true);

		temperature_level = temperature_check();

		if (temperature_level != prev_temperature_level) {
			switch(temperature_level)
			{
				case 0:
					error = max77833_write_reg(hap_data->i2c,
						MAX77833_AUTORES_MIN_FREQ_LOW, hap_data->pdata->auto_res_min_low_low_temp);
					if (error < 0) {
						pr_err("[VIB] %s Failed to write REG(0x%02x) [%d]\n",
						__func__, MAX77833_AUTORES_MIN_FREQ_LOW, error);
					}
					error = max77833_write_reg(hap_data->i2c,
						MAX77833_AUTORES_MAX_FREQ_LOW, hap_data->pdata->auto_res_max_low_low_temp);
					if (error < 0) {
						pr_err("[VIB] %s Failed to write REG(0x%02x) [%d]\n",
						__func__, MAX77833_AUTORES_MAX_FREQ_LOW, error);
					}
					error = max77833_write_reg(hap_data->i2c,
						MAX77833_AUTORES_INIT_GUESS_LOW, hap_data->pdata->auto_res_init_low_low_temp);
					if (error < 0) {
						pr_err("[VIB] %s Failed to write REG(0x%02x) [%d]\n",
						__func__, MAX77833_AUTORES_INIT_GUESS_LOW, error);
					}
					break;
				case 1:
					error = max77833_write_reg(hap_data->i2c,
						MAX77833_AUTORES_MIN_FREQ_LOW, hap_data->pdata->auto_res_min_low);
					if (error < 0) {
						pr_err("[VIB] %s Failed to write REG(0x%02x) [%d]\n",
						__func__, MAX77833_AUTORES_MIN_FREQ_LOW, error);
					}
					error = max77833_write_reg(hap_data->i2c,
						MAX77833_AUTORES_MAX_FREQ_LOW, hap_data->pdata->auto_res_max_low);
					if (error < 0) {
						pr_err("[VIB] %s Failed to write REG(0x%02x) [%d]\n",
						__func__, MAX77833_AUTORES_MAX_FREQ_LOW, error);
					}
					error = max77833_write_reg(hap_data->i2c,
						MAX77833_AUTORES_INIT_GUESS_LOW, hap_data->pdata->auto_res_init_low);
					if (error < 0) {
						pr_err("[VIB] %s Failed to write REG(0x%02x) [%d]\n",
						__func__, MAX77833_AUTORES_INIT_GUESS_LOW, error);
					}
					break;
				case 2:
					error = max77833_write_reg(hap_data->i2c,
						MAX77833_AUTORES_MIN_FREQ_LOW, hap_data->pdata->auto_res_min_low_high_temp);
					if (error < 0) {
						pr_err("[VIB] %s Failed to write REG(0x%02x) [%d]\n",
						__func__, MAX77833_AUTORES_MIN_FREQ_LOW, error);
					}
					error = max77833_write_reg(hap_data->i2c,
						MAX77833_AUTORES_MAX_FREQ_LOW, hap_data->pdata->auto_res_max_low_high_temp);
					if (error < 0) {
						pr_err("[VIB] %s Failed to write REG(0x%02x) [%d]\n",
						__func__, MAX77833_AUTORES_MAX_FREQ_LOW, error);
					}
					error = max77833_write_reg(hap_data->i2c,
						MAX77833_AUTORES_INIT_GUESS_LOW, hap_data->pdata->auto_res_init_low_high_temp);
					if (error < 0) {
						pr_err("[VIB] %s Failed to write REG(0x%02x) [%d]\n",
						__func__, MAX77833_AUTORES_INIT_GUESS_LOW, error);
					}
					break;
				default:
					pr_err("[VIB] %s Failed to read temperature [%d]\n",
					__func__, temperature_level);
					break;
			}
		}

		prev_temperature_level = temperature_level;

		pwm_config(hap_data->pwm, hap_data->pdata->duty,
				hap_data->pdata->period);
		pwm_enable(hap_data->pwm);
		hap_data->running = true;
	} else {
		if (!hap_data->running)
			return;

		pwm_disable(hap_data->pwm);
		max77833_haptic_i2c(hap_data, false);
		hap_data->running = false;
	}
	return;
}
Exemplo n.º 5
0
void vend_check(void)
	{
	char pressed = -1;
	unsigned char i, mask = 0;
	static unsigned char prev_mask = 0, debounce_count;

	// Cycle through all eight buttons, check their values, and do the appropriate event
	digitalWrite(BEEP_PIN, HIGH);
	for (i = soda_count - 1; i < soda_count; i--)
		{
		mask <<= 1;
		if (!digitalRead(sodas[i].switch_pin))
			mask |= 1;
		}
	
	if (prev_mask != mask)
		{
		prev_mask = mask;
		debounce_count = 0;
		mask = 0;
		}
	else if (debounce_count <= MIN_DEBOUNCE_COUNT)
		{
		debounce_count++;
		mask = 0;
		}
	
	if (!mask)
		;
	else if (mask == 0x05)
		{
		if (sold_out & 0x10)
			{
			digitalWrite(BEEP_PIN, LOW);
			pressed = -1;
			}
		else
			pressed = 4;
		}
	else if (mask == 0x03)
		{
		temperature_check();
		return;
		}
	else if (mask == 0x06)
		larsen_on = 1;
	else if (mask == 0x0A)
		larsen_on = 0;
	else if (mask == (1 << RANDOM_SODA_NUMBER))
		do_random_vend(KIND_ANY);
	else if (mask == 0x30)
		do_random_vend(KIND_DIET);
	else if (mask == 0xC0)
		do_random_vend(KIND_REGULAR);
	else if (mask == 0xA0)
		digitalWrite(BEEP_PIN, LOW);
	else if (!(mask & (mask - 1))) /* If only one bit is set in the mask */
		{
		if (mask & sold_out)
			{
			digitalWrite(BEEP_PIN, LOW);
			pressed = -1;
			}
		else
			{
			pressed = 0;
			while (mask >>= 1)
				pressed++;
			}
		}
	set_vend(pressed);
	}