コード例 #1
0
/**
* @brief 时钟电池监测
* @param pbuf 告警缓存区指针
*/
static void ClockBatMonitor(alarm_t *pbuf)
{
	int stat = GpioGetValue(GPIO_BATLOW);

	if(0 == stat && 0 == RunState.battery) { //bat low
		PrintLog(LOGTYPE_ALARM, "clock battery voltage too low!!\n");

		RunStateModify()->battery = 1;

		memset((unsigned char *)pbuf, 0, sizeof(alarm_t));
		pbuf->erc = 13;
		pbuf->len = 3;
		pbuf->data[0] = 0;
		pbuf->data[1] = 0x80;
		pbuf->data[2] = 0x10;
		MakeAlarm(ALMFLAG_ABNOR, pbuf);
	}
}
コード例 #2
0
/**
* @brief 市电状态监测
* @param pbuf 告警缓存区指针
*/
static void PowerMonitor(alarm_t *pbuf)
{
	int stat = GpioGetValue(GPIO_POWER_STATUS);

	#if 1
	if(stat) {  //power off
		if(0 == RunState.pwroff) {
			runstate_t *prun = RunStateModify();
			sysclock_t clock;

			PrintLog(LOGTYPE_ALARM, "power off!!\n");
			Sleep(200);

			prun->pwroff = 1;

			memset((unsigned char *)pbuf, 0, sizeof(alarm_t));
			pbuf->erc = 14;
			pbuf->len = 5;
			//记录停电时间	
			SysClockReadCurrent(&clock);
			prun->timepoweroff[0] = pbuf->min = clock.minute;
			prun->timepoweroff[1] = pbuf->hour = clock.hour;
			prun->timepoweroff[2] = pbuf->day = clock.day;
			prun->timepoweroff[3] = pbuf->mon = clock.month;
			prun->timepoweroff[4] = pbuf->year = clock.year;
			HexToBcd(&pbuf->min, 5);
			MakeAlarm(ALMFLAG_ABNOR, pbuf);
			
			if(TimerIdPowerOff >= 0) {
				SysStopCTimer(TimerIdPowerOff);
				TimerIdPowerOff = -1;
			}
			TimerIdPowerOff = SysAddCTimer(180, CTimerPowerOff, 0);
		}
		else {
			if(TimerIdPowerOff < 0)
				TimerIdPowerOff = SysAddCTimer(180, CTimerPowerOff, 0);
		}
	}
	else {  //power on
		if(RunState.pwroff) {
			sysclock_t clock;

			RunStateModify()->pwroff = 0;
			if(TimerIdPowerOff >= 0) {
				SysStopCTimer(TimerIdPowerOff);
				TimerIdPowerOff = -1;
			}

			memset((unsigned char *)pbuf, 0, sizeof(alarm_t));
			pbuf->erc = 14;
			pbuf->len = 5;
			//记录上次停电时间			
			pbuf->min = RunState.timepoweroff[0];
			pbuf->hour = RunState.timepoweroff[1];
			pbuf->day = RunState.timepoweroff[2];
			pbuf->mon = RunState.timepoweroff[3];
			pbuf->year = RunState.timepoweroff[4];
			HexToBcd(&pbuf->min, 5);

			SysClockReadCurrent(&clock);
			pbuf->data[0] = clock.minute;
			pbuf->data[1] = clock.hour;
			pbuf->data[2] = clock.day;
			pbuf->data[3] = clock.month;
			pbuf->data[4] = clock.year;
			HexToBcd(pbuf->data, 5);
			MakeAlarm(ALMFLAG_NORMAL, pbuf);
		}
	}
	#else
	runstate_t *prun = RunStateModify();

	prun->pwroff = 0;
	#endif
}
コード例 #3
0
ファイル: lcdialog.c プロジェクト: rstephan/lcdialog
int ButtonGetCursor(LcdSpi *lcd, ScreenData *screen, CursorData cur)
{
	int ret;
	int fd1;
	int fd2;
	int fd3;
	uint8_t val1;
	uint8_t val2;
	uint8_t val3;
	uint8_t val1_old = 0;
	uint8_t val2_old = 0;
	uint8_t val3_old = 0;
	int result = 0;
	int counter = COUNTER_MAX;
	ScreenData *screenOut;
	long int start;
	long int end;
	
	ret = 0;
	ret += GpioFdOpen(PIN_KEY_1, &fd1);
	ret += GpioFdOpen(PIN_KEY_2, &fd2);
	ret += GpioFdOpen(PIN_KEY_3, &fd3);

	if (ret != 3) {
		return -1;
	}

	if (!screen) {
		return 0;
	}
	screenOut = ScreenInit(screen->mX, screen->mY);
	ScreenCopy(screenOut, screen);
	start = GetTime();
	while (!gEnde) {
		if (gConfig.mTimeout) {
			end = GetTime();
			if (end - start >= gConfig.mTimeout) {
				result = ASCII_CAN;
				break;
			}
		}
		counter++;
		if (counter > COUNTER_MAX) {
			ScreenBlink(screenOut, cur);
			LcdWriteImageScreen(lcd, screenOut);
			counter = 0;
		}

		GpioGetValue(PIN_KEY_1, &val1);
		GpioGetValue(PIN_KEY_2, &val2);
		GpioGetValue(PIN_KEY_3, &val3);
		
		if (val1 != val1_old && val1 == 0) {
			usleep(DEBOUNCE * 1000);
			result = '1';
			break;
		}
		if (val2 != val2_old && val2 == 0) {
			usleep(DEBOUNCE * 1000);
			result = '2';
			break;
		}
		if (val3 != val3_old && val3 == 0) {
			usleep(DEBOUNCE * 1000);
			result = '3';
			break;
		}
		
		val1_old = val1;
		val2_old = val2;
		val3_old = val3;
		usleep(50 * 1000);
	}
	ScreenDestroy(screenOut);

	return result;
}
コード例 #4
0
ファイル: lcdialog.c プロジェクト: rstephan/lcdialog
int ButtonGet(void)
{
	int ret;
	int fd1;
	int fd2;
	int fd3;
	long int start;
	long int end;
#if 0
	struct pollfd pollKey[3];
	int retPoll;
	char buffer[2];
#endif
	uint8_t val1;
	uint8_t val2;
	uint8_t val3;
	uint8_t val1_old = 0;
	uint8_t val2_old = 0;
	uint8_t val3_old = 0;
	int result = 0;
	
	ret = 0;
	ret += GpioFdOpen(PIN_KEY_1, &fd1);
	ret += GpioFdOpen(PIN_KEY_2, &fd2);
	ret += GpioFdOpen(PIN_KEY_3, &fd3);

	if (ret != 3) {
		return -1;
	}
#if 0
	bzero(pollKey, sizeof(pollKey));
	pollKey[0].fd = fd1;
	pollKey[0].events = POLLPRI;
	pollKey[1].fd = fd2;
	pollKey[1].events = POLLPRI;
	pollKey[2].fd = fd3;
	pollKey[2].events = POLLPRI;
	
	
	while (!ende) {
		retPoll = poll(pollKey, 3, 1000);
		if (retPoll < 0) {
			if (errno == EINTR) {
				continue;
			} else {
				printf("Error: %i\n", errno);
				break;
			}
		} else if (retPoll == 0) {
			// timeout
			//printf(".\n");
		} else {
			if (pollKey[0].revents & POLLPRI) {
				ret = read(fd1, buffer, 2);
				printf("Taste 1: %c\n", buffer[0]);
				usleep(DEBOUNCE * 1000);
				lseek(fd1, 0, SEEK_SET);
				result = '1';
				break;
			}
			if (pollKey[1].revents & POLLPRI) {
				ret = read(fd2, buffer, 2);
				printf("Taste 2: %c\n", buffer[0]);
				usleep(DEBOUNCE * 1000);
				lseek(fd2, 0, SEEK_SET);
				result = '2';
				break;
			}
			if (pollKey[2].revents & POLLPRI) {
				ret = read(fd3, buffer, 2);
				printf("Taste 3: %c\n", buffer[0]);
				usleep(DEBOUNCE * 1000);
				lseek(fd3, 0, SEEK_SET);
				result = '3';
				break;
			}
		}
	}
	GpioFdClose(fd1);
	GpioFdClose(fd2);
	GpioFdClose(fd3);
#endif

	start = GetTime();
	while (!gEnde) {
		if (gConfig.mTimeout) {
			end = GetTime();
			if (end - start >= gConfig.mTimeout) {
				result = ASCII_CAN;
				break;
			}
		}
		GpioGetValue(PIN_KEY_1, &val1);
		GpioGetValue(PIN_KEY_2, &val2);
		GpioGetValue(PIN_KEY_3, &val3);
		
		if (val1 != val1_old && val1 == 0) {
			usleep(DEBOUNCE * 1000);
			result = '1';
			break;
		}
		if (val2 != val2_old && val2 == 0) {
			usleep(DEBOUNCE * 1000);
			result = '2';
			break;
		}
		if (val3 != val3_old && val3 == 0) {
			usleep(DEBOUNCE * 1000);
			result = '3';
			break;
		}
		
		val1_old = val1;
		val2_old = val2;
		val3_old = val3;
		usleep(50 * 1000);
	}

	return result;
}