LOCAL int ICACHE_FLASH_ATTR
open_door_cmd_json_set(struct jsontree_context *js_ctx,
		struct jsonparse_state *parser) {
	int type;
	while ((type = jsonparse_next(parser)) != 0) {
		if (type == JSON_TYPE_PAIR_NAME) {
			char buffer[64];
			os_bzero(buffer, 64);
			if (jsonparse_strcmp_value(parser, "cmd") == 0) {
				jsonparse_next(parser);
				jsonparse_next(parser);
				jsonparse_copy_value(parser, buffer, sizeof(buffer));
				if (!strcoll(buffer, "on")) {
#ifdef MENJINDEBUG
					os_printf("JSON: door open \n");
#endif
					easygpio_outputSet(JIDIANQI_IO, 0);
				} else if (!strcoll(buffer, "off")) {
#ifdef MENJINDEBUG
					os_printf("JSON: door clease \n");
#endif
//					OLED_Print(0, 2, "              ", 2);
					OLED_Print(0, 2, "    Permission  ", 2);
//					OLED_Print(0, 4, "              ", 2);
					OLED_Print(0, 4, "      Denied    ", 2);
					easygpio_outputSet(JIDIANQI_IO, 1);
				}
			}
		}
	}
	return 0;
}
LOCAL int ICACHE_FLASH_ATTR
user_info_json_set(struct jsontree_context *js_ctx,
		struct jsonparse_state *parser) {
	int type;
	while ((type = jsonparse_next(parser)) != 0) {
		if (type == JSON_TYPE_PAIR_NAME) {
			char buffer[64];
			os_bzero(buffer, 64);
			if (jsonparse_strcmp_value(parser, "studentID") == 0) {
				jsonparse_next(parser);
				jsonparse_next(parser);
				jsonparse_copy_value(parser, buffer, sizeof(buffer));
#ifdef ESP8266OLED
				if (!strcoll(buffer, "0000000000")) {

				} else {
					//FIXME 添加OLED显示学号
//					OLED_Print(0, 2, "                ", 2);
					OLED_Print(0, 2, "     Welcome    ", 2);
					OLED_Print(0, 4, "    ", 2);
					OLED_Print(3, 4, buffer, 2);
				}
#endif
#ifdef MENJINDEBUG
				os_printf("\nstudent ID :%s\n", buffer);
#endif
			}
		}
	}
	return 0;
}
Ejemplo n.º 3
0
void restoreFactorySettings() {
	wifi_station_disconnect();
	wifi_set_opmode(0x3); //reset to STA+AP mode

	struct softap_config apConfig;
	wifi_softap_get_config(&apConfig);
	os_strncpy((char*)apConfig.ssid, "smartswitch", 18);
	apConfig.authmode = 0; //Disable security
	wifi_softap_set_config(&apConfig);

	struct station_config stconf;
	os_strncpy((char*)stconf.ssid, "", 2);
	os_strncpy((char*)stconf.password, "", 2);
	wifi_station_set_config(&stconf);

	OLED_CLS();
	OLED_Print(2, 0, "RESET", 1);
	os_printf("Reset completed. Restarting system...\n");

	ioOutput(0, GPIO_OUTPUT1);
	ioOutput(0, GPIO_OUTPUT2);

	while (!GPIO_INPUT_GET(GPIO_BUTTON1)) { os_printf("."); };
	while (!GPIO_INPUT_GET(GPIO_BUTTON2)) { os_printf("."); };

	system_restart();
}
void ICACHE_FLASH_ATTR oled_init() {
	OLED_Init();
	OLED_ON();
	OLED_Print(0, 0, " WXIT Smart Lab", 2);
	os_timer_disarm(&clean_oled_timer);
	os_timer_setfn(&clean_oled_timer, (os_timer_func_t *) clean_oled_cb,
			(void *) 0);
	os_timer_arm(&clean_oled_timer, CLEAN_OLED_DELAY, 1);
}
LOCAL int ICACHE_FLASH_ATTR
time_info_json_set(struct jsontree_context *js_ctx,
		struct jsonparse_state *parser) {
	int type;
	while ((type = jsonparse_next(parser)) != 0) {
		if (type == JSON_TYPE_PAIR_NAME) {
			char buffer[64];
			os_bzero(buffer, 64);
			if (jsonparse_strcmp_value(parser, "time") == 0) {
				jsonparse_next(parser);
				jsonparse_next(parser);
				jsonparse_copy_value(parser, buffer, sizeof(buffer));
				//TODO 添加显示时间!
				OLED_Print(0, 2, "      ", 2);
				OLED_Print(5, 2, buffer, 2);
				OLED_Print(10, 2, "     ", 2);

			}
		}
	}
	return 0;
}
/**
  * @brief  lcd_printf    12864?????
  * @param  void
  * @retval void
  */
void OLED_Printf(unsigned char x,unsigned char y,const char *fmt,...)
{
	static unsigned char last_len[4]={0,0,0,0};	
	static char LCD_BUF[128]={0}; 
	unsigned char len;
	unsigned char i;
	__va_list ap;
	
	va_start(ap,fmt);
	vsprintf((char *)LCD_BUF,fmt,ap);
	va_end(ap);
	
	len=strlen((char *)LCD_BUF)+2*y;
	for(i=len;i<last_len[x];i++)
	{
		LCD_BUF[i-2*y]=' ';
	}
	LCD_BUF[i-2*y]=0;
	OLED_Print(x,y,LCD_BUF);
	last_len[x]=len;
}
void ICACHE_FLASH_ATTR get_dht11(uint8_t *bufftemperature,
		uint8_t *buffhumidity) {
	DHT_Sensor_Data data;
	uint8_t pin;
	pin = pin_num[sensor.pin];
	if (DHTRead(&sensor, &data)) {
#ifdef MENJINDEBUG
		os_printf("GPIO%d\r\n", pin);
		os_printf("Temperature: %s *C\r\n",
				DHTFloat2String(bufftemperature, data.temperature));
#endif
		DHTFloat2String(bufftemperature, data.temperature);
#ifdef MENJINDEBUG
		os_printf("Humidity: %s %%\r\n",
				DHTFloat2String(buffhumidity, data.humidity));
#endif
		DHTFloat2String(buffhumidity, data.humidity);
#ifdef ESP8266OLED
		OLED_Print(2, 7, combine_env_strings(bufftemperature, buffhumidity), 1);
#endif
		if (lasthumidity != data.humidity
				|| lasttemperature != data.temperature)
			isNeedSendENV = true;
		else
			isNeedSendENV = false;
		lasttemperature = data.temperature;
		lasthumidity = data.humidity;
	} else {
#ifdef MENJINDEBUG
		os_printf("Failed to read temperature and humidity sensor on GPIO%d\n",
				pin);
#endif
	}
	os_free(data);
	os_free(pin);
}
Ejemplo n.º 8
0
void MPU9250_Init()
{
	uint32_t Device_ID;

    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_7);

    GPIOPinConfigure(GPIO_PA2_SSI0CLK);
    GPIOPinConfigure(GPIO_PA3_SSI0FSS);
    GPIOPinConfigure(GPIO_PA4_SSI0RX);
    GPIOPinConfigure(GPIO_PA5_SSI0TX);

    GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5);
    GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

    SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_3, SSI_MODE_MASTER, 1000000, 8);

    SSIEnable(SSI0_BASE);

    //
    // Display the example setup on the console.
    //
    UARTprintf("\nPower up.\n");

    // MPU-6500 Device ID check and initial
    Device_ID = 0x0;
    Device_ID = MPU9250_ReadReg(MPU6500_WHO_AM_I);
    if(Device_ID == MPU6500_Device_ID)
    {
    	UARTprintf("MPU6500 Device ID: 0x%X\n--- MPU6500 Initialization done.\n", Device_ID);
    }
    else
    {
    	OLED_Print(0,0,"MPU6500 ERR");
    	UARTprintf("MPU6500 Device ID: 0x%X\n--- MPU6500 Initialization error.\n", Device_ID);
    	while (1);
    }
	MPU9250_SetParameter();

#ifdef USE_MAG
    // AK9875 Device ID check
    // if AK9875 ID check check failed with no reason, re-power-up the system.
	MPU9250_WriteAuxReg(AK8963_CNTL2, 0x01);	//soft reset
	MPU9250_Delay_nop(100000);

    Device_ID = 0x00;
    Device_ID = MPU9250_ReadAuxReg(AK8963_WIA);

    if(Device_ID == AK8963_Device_ID)
    {
    	UARTprintf("AK8963 Device ID: 0x%X\n--- AK8963 Initialization done.\n", Device_ID);
    	LED_Blue_Off();
    }
    else
    {
    	UARTprintf("AK8963 Device ID: 0x%X\n--- AK8963 Initialization error.\n", Device_ID);
    	OLED_Print(0,0,"AK8963 Init ERR");
    	LED_Red_Off();
    	LED_Green_Off();
    }
    MPU9250_GetMagAdjValue();
    MPU9250_WriteAuxReg(AK8963_CNTL1, 0x16);	// 16-bits, Rate 100Hz
    //MPU9250_WriteAuxReg(AK8963_CNTL1, 0x2);	// 14-bits, Rate 8Hz
    Device_ID = MPU9250_ReadAuxReg(AK8963_CNTL1);
#else
    UARTprintf("AK8963 is disabled.\n");
#endif
}
void ICACHE_FLASH_ATTR clean_oled_cb(void *arg) {
	os_timer_disarm(&clean_oled_timer);
	OLED_Print(0, 2, "              ", 2);
	OLED_Print(0, 4, "              ", 2);
	os_timer_arm(&clean_oled_timer, CLEAN_OLED_DELAY, 1);
}