#include "DST_Common.h" #include "DST_EEPROM.h" #include "DST_HostInterface.h" #include "DST_GlobalVariables.h" #include "DST_CommonAPI.h" #include "DST_ChannelTune.h" #include "DST_WinManagerTask.h" //ui #include "DST_DB_Engine.h" #include "DST_DB.h" struct CONFIG { const char* name; int value; int min; int max; int default_value; }; static CONFIG config[] = { {"NeedReset", 0, 0, 1, 0}, {"First", 0, 0, 1, 1}, {"TuneMode", 0, 0, 2, 1}, {"Volume", 0, 0, 50, 25}, {"CC", 0, 0, 1, 0}, {"RF", 0, 0, 154, 0}, // RFÀÇ index¸¦ ÀúÀåÇÑ´Ù. {"program_number", 0, 0, 0xFFFF, 0}, {"aspect_4x3o_4x3i", 0, 0, 2, 1}, {"aspect_4x3o_16x9i", 0, 0, 2, 1}, {"AudioPref", 0, 0, 1, 0}, {"VI", 0, 0, 1, 0}, {"PreferredConn", 0, 0, 1, 0} }; // unsigned aspect_4x3o_4x3i:2; // 0~2 // unsigned aspect_4x3o_16x9i:2; // 0~2 // unsigned aspect_16x9o_4x3i:2; // 0~2 // unsigned aspect_16x9o_16x9i:2; // 0~2 void DST_EEPROM_SetAspect(bool bSource4x3, int nVal) { if (bSource4x3) { DST_EEPROM_SetConfig("aspect_4x3o_4x3i", 1); } else { DST_EEPROM_SetConfig("aspect_4x3o_16x9i", nVal); } } int DST_EEPROM_GetAspect(bool bSource4x3) { //µðÆúÆ®°ª 4:3À϶§´Â ³ë¸» if (bSource4x3) return DST_EEPROM_GetConfig("aspect_4x3o_4x3i"); return DST_EEPROM_GetConfig("aspect_4x3o_16x9i"); } static void DST_LoadEEPROM() { // Áߺ¹ ½ÇÇà ¹æÁö static bool bFirst = true; if (bFirst == false) return; bFirst = false; CDB db; db.Query("create table if not exists config (name text primary key, value int)"); int nCount = sizeof(config)/sizeof(CONFIG); //DST_Printf("%s|nCount=%d\n", __func__, nCount); for (int i =0; i < nCount; i++) { db.GetTable("select value from config where name=%Q", config[i].name); config[i].value = (db.GetRow() < 1) ? config[i].default_value : atoi(db.GetResult(1)); if (config[i].value < config[i].min || config[i].value > config[i].max) config[i].value = config[i].default_value; } } void DST_EEPROM_SetConfig(const char * name, int value) { DST_LoadEEPROM(); int nCount = sizeof(config)/sizeof(CONFIG); //DST_Printf("%s|nCount=%d\n", __func__, nCount); int nPos = -1; for (int i =0; i < nCount; i++) { if (strcmp(config[i].name, name) != 0) continue; nPos = i; break; } if (nPos < 0) { DST_Printf("%s|%d|ERROR|%s|%d\n", __func__, __LINE__, name, value); return; } if (config[nPos].value == value) return; config[nPos].value = value; if (config[nPos].value < config[nPos].min || config[nPos].value > config[nPos].max) config[nPos].value = config[nPos].default_value; CDB db; db.Query("insert or replace into config values(%Q, %d)", name, config[nPos].value); DST_DB_Sync(); } int DST_EEPROM_GetConfig(const char *name) { DST_LoadEEPROM(); int nCount = sizeof(config)/sizeof(CONFIG); //DST_Printf("%s|nCount=%d\n", __func__, nCount); int nPos = -1; for (int i =0; i < nCount; i++) { if (strcmp(config[i].name, name) != 0) continue; nPos = i; break; } if (nPos < 0) { DST_Printf("%s|%d|ERROR|%s\n", __func__, __LINE__, name); return 0; } return config[nPos].value; } void DST_EEPROM_FactoryInit() { int nCount = sizeof(config)/sizeof(CONFIG); for (int i =0; i < nCount; i++) { DST_EEPROM_SetConfig(config[i].name,config[i].default_value); } } void DST_SetSleepTimer(DS_U8 value) { DST_g_SleepTimer = (value < 5) ? value : 0; } DS_U8 DST_GetSleepTimer() { return (DST_g_SleepTimer < 5) ? DST_g_SleepTimer : 0; }