// CGI to set settings
int ICACHE_FLASH_ATTR saveCGI(HttpdConnData *connData) {
	int len;
	char buff[10];
	//char bin[10];

	if (connData->conn == NULL) {
		//Connection aborted. Clean up.
		return HTTPD_CGI_DONE;
	}

	len = httpdFindArg(connData->getArgs, "power", buff, sizeof(buff));
	if (len != 0) ac_set_power(buff);

	len = httpdFindArg(connData->getArgs, "mode", buff, sizeof(buff));
	if (len != 0) ac_set_mode(buff);

	len = httpdFindArg(connData->getArgs, "temp", buff, sizeof(buff));
	if (len != 0) ac_set_temp(buff);

	len = httpdFindArg(connData->getArgs, "fan", buff, sizeof(buff));
	if (len != 0) ac_set_fan(buff);

	len = httpdFindArg(connData->getArgs, "swing", buff, sizeof(buff));
	if (len != 0) ac_set_swing(buff);

	ir_send();
	mqttPublishSettings(0);
	CFG_Save();

	httpdStartResponse(connData, 200);
	httpdHeader(connData, "Content-Type", "text/html");
	httpdEndHeaders(connData);

	os_strcpy(buff, "OK");
	httpdSend(connData, buff, -1);

	return HTTPD_CGI_DONE;
}
예제 #2
0
/**
 * \brief Main function.
 */
int main(void)
{
	enum ac_status_t status;

	pmic_init();
	board_init();
	sysclk_init();
	sleepmgr_init();

	ac_set_interrupt_callback(&ACA, example_aca_interrupt_callback);


	/* Setup the analog comparator B in window mode. */
	ac_set_mode(&aca_config, AC_MODE_WINDOW);
	ac_set_voltage_scaler(&aca_config, 11);
	ac_set_hysteresis(&aca_config, AC_HYSMODE_LARGE_gc);
	ac_set_negative_reference(&aca_config, AC_MUXNEG_SCALER_gc);
	ac_set_positive_reference(&aca_config, AC_MUXPOS_PIN1_gc);
	ac_set_interrupt_mode(&aca_config, AC_INT_MODE_INSIDE_WINDOW);
	ac_set_interrupt_level(&aca_config, AC_INT_LVL_MED);

	/*
	 * Write configuration of analog comparator B channel 0, half of window
	 * configuration.
	 */
	ac_write_config(&ACA, 0, &aca_config);

	/* Set the lower reference of the compare window. */
	ac_set_negative_reference(&aca_config, AC_MUXNEG_BANDGAP_gc);

	/*
	 * Write configuration of analog comparator B channel 1, other half of
	 * window configuration.
	 */
	ac_write_config(&ACA, 1, &aca_config);

	/* Enable all the analog comparator channels. */
	ac_enable(&ACA, 0);
	ac_enable(&ACA, 1);

	/*
	 * Wait for analog comparator to stabilize (muxing, voltage scaler,
	 * bandgap voltage, etc).
	 */
	mdelay(1);

	/* Check comparator status and initialize the LEDs. */
	status = ac_get_status(&ACA, 0);
	example_ac_update_window_leds(status);

	/*
	 * Read back analog comparator channel 0 configuration, to be used when
	 * updating the window interrupt mode in the interrupt callback
	 * function.
	 */
	ac_read_config(&ACA, 0, &aca_config);

	cpu_irq_enable();

	for (;;) {
		/* Go to sleep, everything is handled by interrupts. */
		sleepmgr_enter_sleep();
	}
}