Beispiel #1
0
void consume_power_task(void *pvParam)
{
    prepare_mobile(false);
    power_screen(true);
    LED_Light(led_white, true);
    draw_rectangle(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    while(1);
}
Beispiel #2
0
void LED_Light(uint16 led, bool on)
{
	switch(led)
	{
		case led_white:
			LED_Light(led_red,on);
			LED_Light(led_green,on);
			LED_Light(led_blue,on);
			/*if(on){
				GPIO1->DATA |= led_red_pin;
				GPIO2->DATA |= led_blue_pin;
				GPIO3->DATA |= led_green_pin;
			}else{
				GPIO1->DATA &= ~led_red_pin;
				GPIO2->DATA &= ~led_blue_pin;
				GPIO3->DATA &= ~led_green_pin;
			}*/
			
			break;
			
		case led_red:
			if(on) {
				GPIO1->DATA |= led_red_pin;
			} else {
				GPIO1->DATA &= ~led_red_pin;
			}
			break;
		
		case led_green:
			if(on) {
				GPIO2->DATA |= led_blue_pin;
			} else {
				GPIO2->DATA &= ~led_blue_pin;
			}
			break;
		
		case led_blue:
			if(on) {
				GPIO3->DATA |= led_green_pin;
			} else {
				GPIO3->DATA &= ~led_green_pin;
			}
			break;
	}
}
Beispiel #3
0
void protocol_task(void *pvParam)
{
	logd("protocol_task enter");	
	if(KEY_PowerOff()) {
			post_trace("power key is down");
			POWER_Off();
		
			return;
	}	
	{			
		POWER_Control(dev_mobile, pt_on);
		post_trace("mobile power on");
	}
	LED_Light(led_red, false);
	LED_Light(led_green, false);
	LED_Light(led_blue, false);
	
	while(1) {
		if(KEY_Pressed(KEY_State(), key_right)) {		 			// 如果是KEY1被按下
			while(KEY_Pressed(KEY_State(), key_right));	 		// 等待按键释放
			protocol_upload();
		}	else if(KEY_Pressed(KEY_State(), key_left)) {	 // 如果是KEY2被按下
			while(KEY_Pressed(KEY_State(), key_left));	 	 // 等待按键释放
			protocol_download();		
		} else if(KEY_Pressed(KEY_State(), key_alarm)) {			
			while(KEY_Pressed(KEY_State(), key_alarm));	 	// 等待按键释放
		} else if(KEY_Pressed(KEY_State(), key_service)) {
			while(KEY_Pressed(KEY_State(), key_service));	 // 等待按键释放
		} else if(KEY_Pressed(KEY_State(), key_broadcast)) {
			while(KEY_Pressed(KEY_State(), key_broadcast));	// 等待按键释放
		} else if(KEY_PowerOff()) {
			POWER_Off();
			
			return;			
		}	
	}
}
void OTPWriter_Init(void)
{
	u16 res;

#ifndef OTPWriter_IAP
	HS_PacketInfo PacketInfo;
#endif
	delay_init(72);
	//NVIC_Configuration();
	USB_Disconnect_Config();	  //USB软连接断开控制引脚
	//Console_init();
#ifdef OTPWriter_IAP
    u8 key = 0;
	printf("%s\r\n", SysInfo_OTPWriter_IAP);

	key = g_KEY.IsReleased();

	if(key==1)
	{
		MSD0_SPI_Configuration();
		//挂载文件系统
		disk_initialize(0);
		res = f_mount(0,&fs);
		if(res != FR_OK){
			printf("mount filesystem 0 failed : %d\r\n",res);
		}

		OTPWriter_IAP_from_SD();
		Execute_New_program();
	}
	else
		Execute_New_program();

#else		 //#ifdef OTPWriter_IAP
	printf("%s\r\n", SysInfo_OTPWriter);
	usb_init();
	//OTP_SPI_Init();
	MSD0_SPI_Configuration();
	//挂载文件系统
	disk_initialize(0);
	res = f_mount(0,&fs);
	if(res != FR_OK){
		printf("mount filesystem 0 failed : %d\r\n",res);
	}
	LED_Light(5);
#endif
}
Beispiel #5
0
void component_init()
{    
	power_screen(true);
	LED_Light(led_red, true);
	LED_Light(led_green, true);
	LED_Light(led_blue, true);
	screen_step(0);
						
	RTC_Clock clock = { 0, 0, 30, 23, 0, 8, 8, 12 };

	SetTime(&clock);
	screen_step(1);      
	screen_step(2);
		mobile_state();
	screen_step(3);
    screen_step(4);
	prepare_mobile(false);
	screen_step(5);
	
	play_media(rand() % 9 + 1);
	screen_step(6);

	{
		char szSize[piece_size];
		
		sprintf(szSize, "mount tf card %s", (pf_open("temp") == FR_OK) ? "correcttly" : "fault");
		post_trace(szSize);
	}
	screen_step(7);	
	
	screen_step(8);
	report_content("初始化过程完成,现在开始运行测试程序");
	screen_step(9);
	screen_step(10);
	
	LED_Light(led_red, false);
	LED_Light(led_green, false);
	LED_Light(led_blue, false);
	display_clear();

	power_screen(false);
}
Beispiel #6
0
void work_task(void *pvParam)
{	
	while(1) {
		if(KEY_PowerOff()) {
			POWER_Off();
			
			return;
		} else if(KEY_Pressed(KEY_State(), key_broadcast)) {
			power_screen(true);			
			LED_Light(led_red, true);
			LED_Light(led_green, true);
			LED_Light(led_blue, true);		
			
			{
				strcpy(watcher_data->sid, "18000000000072");
				upgrade();
			}
			LED_Light(led_red, false);
			LED_Light(led_green, false);
			LED_Light(led_blue, false);	
			power_screen(false);
		}
	}
}
Beispiel #7
0
void state_task(void *pvParam)
{	
	LED_Light(led_red, false);
	LED_Light(led_green, false);
	LED_Light(led_blue, false);	
	
	power_screen(true);
	while(1) {
		if(KEY_Pressed(KEY_State(), key_right)) {		 			// 如果是KEY1被按下
			while(KEY_Pressed(KEY_State(), key_right));	 		// 等待按键释放
			post_trace("power on");
			POWER_Control(dev_mobile, pt_on);
			display_clear();
			screen_step(0);
		}	else if(KEY_Pressed(KEY_State(), key_left)) {	 // 如果是KEY2被按下
			while(KEY_Pressed(KEY_State(), key_left));	 	 // 等待按键释放
			post_trace("power off");
			//POWER_Control(dev_mobile, pt_off);
			power_device(ED_SWITCH, EP_OFF);
			display_clear();
			screen_step(1);		
		} else if(KEY_Pressed(KEY_State(), key_alarm)) {			
			while(KEY_Pressed(KEY_State(), key_alarm));	 	// 等待按键释放
			mobile_state();
			display_clear();
			screen_step(4);	
		} else if(KEY_Pressed(KEY_State(), key_service)) {
            uint8 nPowerState;
			
			while(KEY_Pressed(KEY_State(), key_service));	// 等待按键释放
			mobile_state();
			nPowerState = POWER_State(dev_mobile);
			if(pt_comm == nPowerState) {
				post_trace("shutdown gsm");
				power_device(ED_GSM, EP_OFF);
			} else {
				post_trace("poweron gsm");
				power_device(ED_GSM, EP_ON);
			}
			display_clear();
			screen_step(2);
		} else if(KEY_Pressed(KEY_State(), key_broadcast)) {			
			uint8 nPowerState;
			
			while(KEY_Pressed(KEY_State(), key_broadcast));	// 等待按键释放
			mobile_state();
			nPowerState = POWER_State(dev_mobile);
			if(pt_hibernation == nPowerState) {
				post_trace("wakup");
				POWER_Control(dev_mobile, pt_wakeup);
			} else {
				post_trace("hibernation");
				POWER_Control(dev_mobile, pt_hibernation);
			}
			display_clear();
			screen_step(3);
		} else if(KEY_PowerOff()) {
			POWER_Off();
			
			return;			
		}	
	}
}
Beispiel #8
0
void power_task(void *pvParam)
{	
	LED_Light(led_red, true);
	LED_Light(led_green, true);
	LED_Light(led_blue, true);		
	if(KEY_PowerOff()) {
			post_trace("power key is down");
			POWER_Off();
		
			return;
	}	
	{			
		POWER_Control(dev_mobile, pt_off);
		POWER_Control(dev_mobile, pt_on);
		power_device(ED_GPRS, EP_OFF);
		power_device(ED_GSM, EP_OFF);
		power_device(ED_BLUETOOTH, EP_OFF);
		power_device(ED_GPS, EP_OFF);
		post_trace("mobile power on");
	}
	LED_Light(led_red, false);
	LED_Light(led_green, false);
	LED_Light(led_blue, false);	
	
	while(1) {
		if(KEY_Pressed(KEY_State(), key_right)) {		 			// 如果是KEY1被按下
			while(KEY_Pressed(KEY_State(), key_right));	 		// 等待按键释放
			post_trace("mobile hibernation");
			POWER_Control(dev_mobile, pt_hibernation);
		}	else if(KEY_Pressed(KEY_State(), key_left)) {	 // 如果是KEY2被按下
			while(KEY_Pressed(KEY_State(), key_left));	 	 // 等待按键释放
			post_trace("mobile wakeup");
			power_device(ED_GSM, EP_ON);	
		} else if(KEY_Pressed(KEY_State(), key_alarm)) {		
			static bool bOn = false;			
			
			while(KEY_Pressed(KEY_State(), key_alarm));	 	// 等待按键释放
			
			if(!bOn) {
				power_screen(true);
				draw_rectangle(55, 0, 18, 64);
				bOn = true;
			} else {
				power_screen(false);
				bOn = false;
			}
		} else if(KEY_Pressed(KEY_State(), key_service)) {
			static bool bOn = false;
			
			while(KEY_Pressed(KEY_State(), key_service));	 // 等待按键释放
			
			if(!bOn) {
				LED_Light(led_red, true);
				bOn = true;
			} else {
				LED_Light(led_red, false);
				bOn = false;
			}
		} else if(KEY_Pressed(KEY_State(), key_broadcast)) {
			while(KEY_Pressed(KEY_State(), key_broadcast));	// 等待按键释放
			post_trace("arm hibernation");
			POWER_Control(dev_system, pt_hibernation);
		} else if(KEY_PowerOff()) {
			POWER_Off();
			
			return;		
		}	
	}
}
Beispiel #9
0
void component_key_alarm()
{
	const uint8 DATA_SIZE = sizeof(HMC5883L_data) + sizeof(RTC_Clock) + sizeof(MMA8451_data);
	char szTrace[piece_size];
	HMC5883L_data data_5883;
	RTC_Clock clock;
	Sensor data_8451;
	uint8 nIndex = 0;
    uint32 nVotage = 0;
	
	LED_Light(led_blue, true);
	sprintf(szTrace, "key = alarm, led = blue");
	post_trace(szTrace);
	
	for(nIndex = 0; nIndex < 60; ++nIndex) {
		HMC5883L_ReadXYZ(&data_5883);
		sprintf(szTrace, "hmc5883 x = %d, y = %d, z = %d", data_5883.x, data_5883.y, data_5883.z);
		post_trace(szTrace);
		
		clock = GetTime();			
		sprintf(szTrace, "sd2058: 20%02d:%02d:%02d %02d:%02d:%02d", clock.year, clock.month, clock.day, clock.hour, clock.minute, clock.second);
		post_trace(szTrace);
		
        if((MMA845x_readbyte(MMA845x_STATUS_00) & 0x08) != 0) { //三个轴数据更新	
            MMA845x_readData(&data_8451);
            if(data_8451.x == -1 && data_8451.y == -1 && data_8451.z == -1) {
                post_trace("MMA8451: read error data");
            } else {
                sprintf(szTrace, "MMA8451: x = %d, y = %d, z = %d", data_8451.x, data_8451.y, data_8451.z);
                post_trace(szTrace);
            }
        } else {
            post_trace("MMA8451: read error");
        }
        
        nVotage = ADC_Read();
        sprintf(szTrace, "votage = %d", nVotage);
		post_trace(szTrace);
		}
	
	memcpy(szTrace, &data_5883, sizeof(HMC5883L_data));
	memcpy(szTrace + sizeof(HMC5883L_data), &clock, sizeof(RTC_Clock));
	memcpy(szTrace + sizeof(HMC5883L_data) + sizeof(RTC_Clock), &data_8451, sizeof(MMA8451_data));
	write_file("temp", szTrace, DATA_SIZE);
	post_trace("save sensor data in file named \"temp\" in tf card");	
	
	{
		InfoBase base_info = { 0 };
		InfoState state_info = { 0 };
		
		if(get_base_info(&base_info)) {
			sprintf(szTrace, "base info, sid = %s, imei = %s", base_info.sid, base_info.imei);
			post_trace(szTrace);
		}
		
		if(get_state_info(&state_info)) {
			sprintf(szTrace, "state info, charging: %s, quantity: %d, sim card: %s, signal: %d, lac: %s, cell: %s, lng: %s, lat: %s", 
			(is_charging(&state_info) ? "yes" : "no"), get_quantity(&state_info), 
			(is_sim_card_exist(&state_info) ? (is_sim_card_valid(&state_info) ? "normal" : "error") : "lost"), get_signal(&state_info),
			state_info.lac, state_info.cell, state_info.lng, state_info.lat);
			post_trace(szTrace);
		}
	}
	post_trace("alarm completed");
	
	LED_Light(led_blue, false);
}
Beispiel #10
0
void init_file_task(void *pvParam)
{
	const char *REPORT_HEALTH = "您今天共走了2850步,睡眠6小时23分钟,午睡42分钟,您整体的活动量适中,睡眠质量不错。";
	const char *REPORT_WARM = "今天是2012年10月9日,今天天气晴朗,适合户外运动,建议你今天至少保持两个小时的适度户外活动。";
	Config conf_server = { 0 };
	ConfigInfo conf_info = { 0 };
	ConfigDownload conf_down = { 0 };
	Relation relation = { 0 };
	Remind remind = { 0 };
	Supervise supervise = { 0 };

	LED_Light(led_green, true);

	conf_server.valid |= (VALID_SMS | VALID_PHONE | VALID_AUTO_ALARM);
	strcpy(conf_server.service_number, "18601920800");
	strcpy(conf_server.name, "E伴健康导航仪");
	conf_server.upgrade_begin.hour = 1;
	conf_server.upgrade_end.hour = 2;
	conf_server.warm_begin.hour = 7;
	conf_server.warm_end.hour = 12;
	conf_server.health_begin.hour = 12;
	conf_server.health_end.hour = 20;
	save_server_config(&conf_server);
	
	conf_info.registered = true;
	strcpy(conf_info.sid, "18000000000072");
	save_general_config(&conf_info);

	conf_down.grade = 4;
	conf_down.point = 86;
	conf_down.download_count[ECT_RELATION] = 1;
	conf_down.download_count[ECT_REMIND] = 1;
	conf_down.download_count[ECT_SUPERVISE] = 1;
// 	conf_down.warm_file_size = strlen(REPORT_HEALTH);
// 	conf_down.health_file_size = strlen(REPORT_WARM);
	save_down_config(&conf_down);
	
	strcpy(relation.name, "紧急联系人");
	strcpy(relation.phone, "18601920800");
	write_file("relat/0", &relation, sizeof(Relation));
	
	remind.repeat = REPEAT_DAY;
	remind.time.hour = 10;
	remind.time.minute = 30;
	strcpy(remind.content, "E伴亲情提醒测试");
	write_file("remind/0", &remind, sizeof(Remind));
	
	supervise.project = PROJECT_RESET;
	supervise.begin.hour = 14;
	supervise.begin.minute = 30;
	supervise.end.hour = 16;
	supervise.end.minute = 40;	
	supervise.type = WR_SLIGHT;
	strcpy(supervise.suggestion, "E伴督导测试");
	write_file("spvs/0", &supervise, sizeof(Supervise));
	
	write_file("rep/fit0", REPORT_HEALTH, strlen(REPORT_HEALTH));
	write_file("rep/warm0", REPORT_WARM, strlen(REPORT_WARM));
	
	LED_Light(led_green, false);
	
    while(1);
}