| [2] | 1 | #include "DST_Common.h" |
|---|
| 2 | #include "DST_EEPROM.h" |
|---|
| 3 | #include "DST_HostInterface.h" |
|---|
| 4 | #include "DST_GlobalVariables.h" |
|---|
| 5 | #include "DST_CommonAPI.h" |
|---|
| 6 | #include "DST_ChannelTune.h" |
|---|
| 7 | #include "DST_WinManagerTask.h" //ui |
|---|
| 8 | |
|---|
| 9 | #include "DST_DB_Engine.h" |
|---|
| 10 | #include "DST_DB.h" |
|---|
| 11 | |
|---|
| 12 | struct CONFIG |
|---|
| 13 | { |
|---|
| 14 | const char* name; |
|---|
| 15 | int value; |
|---|
| 16 | int min; |
|---|
| 17 | int max; |
|---|
| 18 | int default_value; |
|---|
| 19 | }; |
|---|
| 20 | |
|---|
| 21 | static CONFIG config[] = |
|---|
| 22 | { |
|---|
| 23 | {"NeedReset", 0, 0, 1, 0}, |
|---|
| 24 | {"First", 0, 0, 1, 1}, |
|---|
| 25 | {"TuneMode", 0, 0, 2, 1}, |
|---|
| 26 | {"Volume", 0, 0, 50, 25}, |
|---|
| 27 | {"CC", 0, 0, 1, 0}, |
|---|
| 28 | {"RF", 0, 0, 154, 0}, // RFÀÇ index¸¦ ÀúÀåÇÑ´Ù. |
|---|
| 29 | {"program_number", 0, 0, 0xFFFF, 0}, |
|---|
| 30 | {"aspect_4x3o_4x3i", 0, 0, 2, 1}, |
|---|
| 31 | {"aspect_4x3o_16x9i", 0, 0, 2, 1}, |
|---|
| 32 | {"AudioPref", 0, 0, 1, 0}, |
|---|
| 33 | {"VI", 0, 0, 1, 0}, |
|---|
| 34 | {"PreferredConn", 0, 0, 1, 0} |
|---|
| 35 | }; |
|---|
| 36 | // unsigned aspect_4x3o_4x3i:2; // 0~2 |
|---|
| 37 | // unsigned aspect_4x3o_16x9i:2; // 0~2 |
|---|
| 38 | // unsigned aspect_16x9o_4x3i:2; // 0~2 |
|---|
| 39 | // unsigned aspect_16x9o_16x9i:2; // 0~2 |
|---|
| 40 | void DST_EEPROM_SetAspect(bool bSource4x3, int nVal) |
|---|
| 41 | { |
|---|
| 42 | if (bSource4x3) |
|---|
| 43 | { |
|---|
| 44 | DST_EEPROM_SetConfig("aspect_4x3o_4x3i", 1); |
|---|
| 45 | } |
|---|
| 46 | else |
|---|
| 47 | { |
|---|
| 48 | DST_EEPROM_SetConfig("aspect_4x3o_16x9i", nVal); |
|---|
| 49 | } |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | int DST_EEPROM_GetAspect(bool bSource4x3) |
|---|
| 53 | { |
|---|
| 54 | //µðÆúÆ®°ª 4:3À϶§´Â ³ë¸» |
|---|
| 55 | if (bSource4x3) return DST_EEPROM_GetConfig("aspect_4x3o_4x3i"); |
|---|
| 56 | return DST_EEPROM_GetConfig("aspect_4x3o_16x9i"); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | static void DST_LoadEEPROM() |
|---|
| 60 | { |
|---|
| 61 | // Áߺ¹ ½ÇÇà ¹æÁö |
|---|
| 62 | static bool bFirst = true; |
|---|
| 63 | if (bFirst == false) return; |
|---|
| 64 | bFirst = false; |
|---|
| 65 | |
|---|
| 66 | CDB db; |
|---|
| 67 | db.Query("create table if not exists config (name text primary key, value int)"); |
|---|
| 68 | |
|---|
| 69 | int nCount = sizeof(config)/sizeof(CONFIG); |
|---|
| 70 | //DST_Printf("%s|nCount=%d\n", __func__, nCount); |
|---|
| 71 | for (int i =0; i < nCount; i++) |
|---|
| 72 | { |
|---|
| 73 | db.GetTable("select value from config where name=%Q", config[i].name); |
|---|
| 74 | config[i].value = (db.GetRow() < 1) ? config[i].default_value : atoi(db.GetResult(1)); |
|---|
| 75 | if (config[i].value < config[i].min || config[i].value > config[i].max) config[i].value = config[i].default_value; |
|---|
| 76 | } |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | void DST_EEPROM_SetConfig(const char * name, int value) |
|---|
| 80 | { |
|---|
| 81 | DST_LoadEEPROM(); |
|---|
| 82 | int nCount = sizeof(config)/sizeof(CONFIG); |
|---|
| 83 | //DST_Printf("%s|nCount=%d\n", __func__, nCount); |
|---|
| 84 | int nPos = -1; |
|---|
| 85 | for (int i =0; i < nCount; i++) |
|---|
| 86 | { |
|---|
| 87 | if (strcmp(config[i].name, name) != 0) continue; |
|---|
| 88 | nPos = i; |
|---|
| 89 | break; |
|---|
| 90 | } |
|---|
| 91 | if (nPos < 0) |
|---|
| 92 | { |
|---|
| 93 | DST_Printf("%s|%d|ERROR|%s|%d\n", __func__, __LINE__, name, value); |
|---|
| 94 | return; |
|---|
| 95 | } |
|---|
| 96 | if (config[nPos].value == value) return; |
|---|
| 97 | config[nPos].value = value; |
|---|
| 98 | if (config[nPos].value < config[nPos].min || config[nPos].value > config[nPos].max) config[nPos].value = config[nPos].default_value; |
|---|
| 99 | CDB db; |
|---|
| 100 | db.Query("insert or replace into config values(%Q, %d)", name, config[nPos].value); |
|---|
| 101 | DST_DB_Sync(); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | int DST_EEPROM_GetConfig(const char *name) |
|---|
| 105 | { |
|---|
| 106 | DST_LoadEEPROM(); |
|---|
| 107 | int nCount = sizeof(config)/sizeof(CONFIG); |
|---|
| 108 | //DST_Printf("%s|nCount=%d\n", __func__, nCount); |
|---|
| 109 | int nPos = -1; |
|---|
| 110 | for (int i =0; i < nCount; i++) |
|---|
| 111 | { |
|---|
| 112 | if (strcmp(config[i].name, name) != 0) continue; |
|---|
| 113 | nPos = i; |
|---|
| 114 | break; |
|---|
| 115 | } |
|---|
| 116 | if (nPos < 0) |
|---|
| 117 | { |
|---|
| 118 | DST_Printf("%s|%d|ERROR|%s\n", __func__, __LINE__, name); |
|---|
| 119 | return 0; |
|---|
| 120 | } |
|---|
| 121 | return config[nPos].value; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | void DST_EEPROM_FactoryInit() |
|---|
| 127 | { |
|---|
| 128 | int nCount = sizeof(config)/sizeof(CONFIG); |
|---|
| 129 | for (int i =0; i < nCount; i++) |
|---|
| 130 | { |
|---|
| 131 | DST_EEPROM_SetConfig(config[i].name,config[i].default_value); |
|---|
| 132 | } |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | void DST_SetSleepTimer(DS_U8 value) |
|---|
| 136 | { |
|---|
| 137 | DST_g_SleepTimer = (value < 5) ? value : 0; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | DS_U8 DST_GetSleepTimer() |
|---|
| 141 | { |
|---|
| 142 | return (DST_g_SleepTimer < 5) ? DST_g_SleepTimer : 0; |
|---|
| 143 | } |
|---|
| 144 | |
|---|