#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <linux/input.h>
#include <pthread.h>

typedef struct saveGroup
{
	int backLight;
	int screenSaverPara;
	int startUpPara;
	int language;
	int startUpTemp;
} EVEN_SAVE_GROUP;

static EVEN_SAVE_GROUP saveObj = {6, 0, 0, 0, 225};

void setBackLight(int val)
{
	printf("setBackLight:%d\n", val);
	saveObj.backLight = val;
	return;
}
void setScreenSaverPara(int val)
{
	printf("setScreenSaverPara:%d\n", val);
	saveObj.screenSaverPara = val;
	return;
}
void setStartUpPara(int val)
{
	printf("setStartUpPara:%d\n", val);
	saveObj.startUpPara = val;
	return;
}
void setLanguage(int val)
{
	printf("setLanguage:%d\n", val);
	saveObj.language = val;
	return;
}
void setStartUpTemp(int val)
{
	printf("setStartUpTemp:%d\n", val);
	saveObj.startUpTemp = val;
	return;
}

int getBackLight(void)
{
	int tempVal = saveObj.backLight;
	printf("getBackLight:%d\n", tempVal);
	return tempVal;
}
int getScreenSaverPara(void)
{
	int tempVal = saveObj.screenSaverPara;
	printf("getScreenSaverPara:%d\n", tempVal);
	return tempVal;
}
int getStartUpPara(void)
{
	int tempVal = saveObj.startUpPara;
	printf("getStartUpPara:%d\n", tempVal);
	return tempVal;
}
int getLanguage(void)
{
	int tempVal = saveObj.language;
	printf("getLanguage:%d\n", tempVal);
	return tempVal;
}
int getStartUpTemp(void)
{
	int tempVal = saveObj.startUpTemp;
	printf("getStartUpTemp:%d\n", tempVal);
	return tempVal;
}

void saveOption(void)
{
	FILE *fp = fopen("/usr/local/quicknode/file/user.cfg", "w+");

	if (fp == NULL)
		return;

	fwrite(&saveObj, sizeof(saveObj), 1, fp);

	fflush(fp);

	fsync(fileno(fp));

	fclose(fp);
}
void readOption(void)
{
	FILE *fp = fopen("/usr/local/quicknode/file/user.cfg", "w+");

	if (fp == NULL)
		return;

	fread(&saveObj, sizeof(saveObj), 1, fp);

	fclose(fp);
}
void clearOption(void)
{
	saveObj={0,0,0,0,0};
}
