Many new settings to support the new state machine functionality.
This commit is contained in:
parent
583995097a
commit
998f93134a
5 changed files with 90 additions and 28 deletions
|
@ -24,10 +24,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <SystemK.h>
|
#include <SystemK.h>
|
||||||
|
#include "Key_Value.h"
|
||||||
#define MAX_LINE_LENGTH 140
|
|
||||||
#define MAX_KEY_LENGTH 64
|
|
||||||
#define MAX_VALUE_LENGTH 64
|
|
||||||
|
|
||||||
static const char *TAG = "NVM KV";
|
static const char *TAG = "NVM KV";
|
||||||
static const char *TEMP_FILE = "/usb/esp/temp.txt";
|
static const char *TEMP_FILE = "/usb/esp/temp.txt";
|
||||||
|
@ -52,10 +49,10 @@ static int KV_Parse_Line(char *line, char *key, char *value)
|
||||||
if (delimiter == NULL)
|
if (delimiter == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
*delimiter = '\0';
|
*delimiter = '\0';
|
||||||
strncpy(key, line, MAX_KEY_LENGTH - 1);
|
strncpy(key, line, KV_MAX_KEY_LENGTH - 1);
|
||||||
strncpy(value, delimiter + 1, MAX_VALUE_LENGTH - 1);
|
strncpy(value, delimiter + 1, KV_MAX_VALUE_LENGTH - 1);
|
||||||
key[MAX_KEY_LENGTH - 1] = '\0';
|
key[KV_MAX_KEY_LENGTH - 1] = '\0';
|
||||||
value[MAX_VALUE_LENGTH - 1] = '\0';
|
value[KV_MAX_VALUE_LENGTH - 1] = '\0';
|
||||||
KV_Trim(key);
|
KV_Trim(key);
|
||||||
KV_Trim(value);
|
KV_Trim(value);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -70,8 +67,8 @@ SystemKResult_T KV_Get_Value_string(const char *filename, const char *search_key
|
||||||
return SYSTEMK_RESULT_FILE_NOT_FOUND;
|
return SYSTEMK_RESULT_FILE_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
char line[MAX_LINE_LENGTH];
|
char line[KV_MAX_LINE_LENGTH];
|
||||||
char key[MAX_KEY_LENGTH];
|
char key[KV_MAX_KEY_LENGTH];
|
||||||
|
|
||||||
while (fgets(line, sizeof(line), file))
|
while (fgets(line, sizeof(line), file))
|
||||||
{
|
{
|
||||||
|
@ -104,16 +101,16 @@ SystemKResult_T KV_Set_Value_string(const char *filename, const char *set_key, c
|
||||||
return SYSTEMK_RESULT_WRITE_FAILED;
|
return SYSTEMK_RESULT_WRITE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
char line[MAX_LINE_LENGTH];
|
char line[KV_MAX_LINE_LENGTH];
|
||||||
char line_copy[MAX_LINE_LENGTH];
|
char line_copy[KV_MAX_LINE_LENGTH];
|
||||||
char key[MAX_KEY_LENGTH];
|
char key[KV_MAX_KEY_LENGTH];
|
||||||
char value[MAX_VALUE_LENGTH];
|
char value[KV_MAX_VALUE_LENGTH];
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
|
||||||
while (fgets(line, sizeof(line), file))
|
while (fgets(line, sizeof(line), file))
|
||||||
{
|
{
|
||||||
strncpy(line_copy, line, MAX_LINE_LENGTH);
|
strncpy(line_copy, line, KV_MAX_LINE_LENGTH);
|
||||||
line_copy[MAX_LINE_LENGTH - 1] = '\0'; // Ensure null-termination
|
line_copy[KV_MAX_LINE_LENGTH - 1] = '\0'; // Ensure null-termination
|
||||||
|
|
||||||
if (KV_Parse_Line(line, key, value) && strcmp(key, set_key) == 0)
|
if (KV_Parse_Line(line, key, value) && strcmp(key, set_key) == 0)
|
||||||
{
|
{
|
||||||
|
@ -142,7 +139,7 @@ SystemKResult_T KV_Set_Value_string(const char *filename, const char *set_key, c
|
||||||
|
|
||||||
SystemKResult_T KV_Get_Value_uint32(const char *filename, const char *search_key, uint32_t *value)
|
SystemKResult_T KV_Get_Value_uint32(const char *filename, const char *search_key, uint32_t *value)
|
||||||
{
|
{
|
||||||
char value_str[MAX_VALUE_LENGTH];
|
char value_str[KV_MAX_VALUE_LENGTH];
|
||||||
|
|
||||||
SystemKResult_T result = KV_Get_Value_string(filename, search_key, value_str);
|
SystemKResult_T result = KV_Get_Value_string(filename, search_key, value_str);
|
||||||
if (result != SYSTEMK_RESULT_SUCCESS)
|
if (result != SYSTEMK_RESULT_SUCCESS)
|
||||||
|
@ -179,10 +176,10 @@ SystemKResult_T KV_Get_Value_uint32(const char *filename, const char *search_key
|
||||||
|
|
||||||
SystemKResult_T KV_Set_Value_uint32(const char *filename, const char *set_key, uint32_t *set_value)
|
SystemKResult_T KV_Set_Value_uint32(const char *filename, const char *set_key, uint32_t *set_value)
|
||||||
{
|
{
|
||||||
char value_str[MAX_VALUE_LENGTH];
|
char value_str[KV_MAX_VALUE_LENGTH];
|
||||||
int written = snprintf(value_str, MAX_VALUE_LENGTH, "%lu", *set_value);
|
int written = snprintf(value_str, KV_MAX_VALUE_LENGTH, "%lu", *set_value);
|
||||||
|
|
||||||
if (written < 0 || written >= MAX_VALUE_LENGTH)
|
if (written < 0 || written >= KV_MAX_VALUE_LENGTH)
|
||||||
{
|
{
|
||||||
KLOG_ERROR(TAG, "Error converting uint32_t to string for key %s!", set_key);
|
KLOG_ERROR(TAG, "Error converting uint32_t to string for key %s!", set_key);
|
||||||
return SYSTEMK_RESULT_WRONG_DATATYPE;
|
return SYSTEMK_RESULT_WRONG_DATATYPE;
|
||||||
|
@ -215,10 +212,10 @@ SystemKResult_T KV_Get_Value_uint8(const char *filename, const char *search_key,
|
||||||
|
|
||||||
SystemKResult_T KV_Set_Value_uint8(const char *filename, const char *set_key, uint8_t *set_value)
|
SystemKResult_T KV_Set_Value_uint8(const char *filename, const char *set_key, uint8_t *set_value)
|
||||||
{
|
{
|
||||||
char value_str[MAX_VALUE_LENGTH];
|
char value_str[KV_MAX_VALUE_LENGTH];
|
||||||
int written = snprintf(value_str, MAX_VALUE_LENGTH, "%u", *set_value);
|
int written = snprintf(value_str, KV_MAX_VALUE_LENGTH, "%u", *set_value);
|
||||||
|
|
||||||
if (written < 0 || written >= MAX_VALUE_LENGTH)
|
if (written < 0 || written >= KV_MAX_VALUE_LENGTH)
|
||||||
{
|
{
|
||||||
KLOG_ERROR(TAG, "Error converting uint8_t to string for key %s!", set_key);
|
KLOG_ERROR(TAG, "Error converting uint8_t to string for key %s!", set_key);
|
||||||
return SYSTEMK_RESULT_WRONG_DATATYPE;
|
return SYSTEMK_RESULT_WRONG_DATATYPE;
|
||||||
|
|
|
@ -19,6 +19,10 @@
|
||||||
* file in the root of this repository. If not, see <http://www.gnu.org/licenses/>.
|
* file in the root of this repository. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define KV_MAX_LINE_LENGTH 140
|
||||||
|
#define KV_MAX_KEY_LENGTH 64
|
||||||
|
#define KV_MAX_VALUE_LENGTH 64
|
||||||
|
|
||||||
SystemKResult_T KV_Get_Value_string(const char *filename, const char *search_key, char *value);
|
SystemKResult_T KV_Get_Value_string(const char *filename, const char *search_key, char *value);
|
||||||
SystemKResult_T KV_Set_Value_string(const char *filename, const char *set_key, const char *set_value);
|
SystemKResult_T KV_Set_Value_string(const char *filename, const char *set_key, const char *set_value);
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
* file in the root of this repository. If not, see <http://www.gnu.org/licenses/>.
|
* file in the root of this repository. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
#include <SystemK.h>
|
#include <SystemK.h>
|
||||||
#include <NVM.h>
|
#include <NVM.h>
|
||||||
|
|
||||||
|
@ -27,6 +28,8 @@ static const uint8_t UNINTIALIZED_UINT8 = UINT8_MAX;
|
||||||
static uint8_t Cached_Team_ID = UNINTIALIZED_UINT8;
|
static uint8_t Cached_Team_ID = UNINTIALIZED_UINT8;
|
||||||
static uint8_t Cached_Player_ID = UNINTIALIZED_UINT8;
|
static uint8_t Cached_Player_ID = UNINTIALIZED_UINT8;
|
||||||
static uint8_t Cached_Weapon_ID = UNINTIALIZED_UINT8;
|
static uint8_t Cached_Weapon_ID = UNINTIALIZED_UINT8;
|
||||||
|
static uint8_t Cached_Max_Health = UNINTIALIZED_UINT8;
|
||||||
|
static uint8_t Cached_N_Special_Weapons_On_Reentry = UNINTIALIZED_UINT8;
|
||||||
|
|
||||||
SystemKResult_T SETTINGS_get_uint8_t(SystemKSettingID_T id, uint8_t *value)
|
SystemKResult_T SETTINGS_get_uint8_t(SystemKSettingID_T id, uint8_t *value)
|
||||||
{
|
{
|
||||||
|
@ -55,7 +58,6 @@ SystemKResult_T SETTINGS_get_uint8_t(SystemKSettingID_T id, uint8_t *value)
|
||||||
key = "Team_ID";
|
key = "Team_ID";
|
||||||
cached_value = &Cached_Team_ID;
|
cached_value = &Cached_Team_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SYSTEMK_SETTING_PLAYERID:
|
case SYSTEMK_SETTING_PLAYERID:
|
||||||
|
@ -84,6 +86,32 @@ SystemKResult_T SETTINGS_get_uint8_t(SystemKSettingID_T id, uint8_t *value)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SYSTEMK_SETTING_MAX_HEALTH:
|
||||||
|
if (Cached_Max_Health != UNINTIALIZED_UINT8)
|
||||||
|
{
|
||||||
|
*value = Cached_Max_Health;
|
||||||
|
result = SYSTEMK_RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
key = "Max_Health";
|
||||||
|
cached_value = &Cached_Max_Health;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SYSTEMK_SETTING_N_SPECIAL_WEAPONS_ON_REENTRY:
|
||||||
|
if (Cached_N_Special_Weapons_On_Reentry != UNINTIALIZED_UINT8)
|
||||||
|
{
|
||||||
|
*value = Cached_N_Special_Weapons_On_Reentry;
|
||||||
|
result = SYSTEMK_RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
key = "N_Special_Weapons_On_Reentry";
|
||||||
|
cached_value = &Cached_N_Special_Weapons_On_Reentry;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
result = SYSTEMK_RESULT_WRONG_DATATYPE;
|
result = SYSTEMK_RESULT_WRONG_DATATYPE;
|
||||||
break;
|
break;
|
||||||
|
@ -142,6 +170,16 @@ SystemKResult_T SETTINGS_set_uint8_t(SystemKSettingID_T id, uint8_t value)
|
||||||
result = KV_Set_Value_uint8(CONFIG_FILE, "Weapon_ID", &value);
|
result = KV_Set_Value_uint8(CONFIG_FILE, "Weapon_ID", &value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SYSTEMK_SETTING_MAX_HEALTH:
|
||||||
|
Cached_Max_Health = value;
|
||||||
|
result = KV_Set_Value_uint8(CONFIG_FILE, "Max_Health", &value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SYSTEMK_SETTING_N_SPECIAL_WEAPONS_ON_REENTRY:
|
||||||
|
Cached_N_Special_Weapons_On_Reentry = value;
|
||||||
|
result = KV_Set_Value_uint8(CONFIG_FILE, "N_Special_Weapons_On_Reentry", &value);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
result = SYSTEMK_RESULT_WRONG_DATATYPE;
|
result = SYSTEMK_RESULT_WRONG_DATATYPE;
|
||||||
break;
|
break;
|
||||||
|
@ -166,6 +204,10 @@ SystemKResult_T SETTINGS_get_uint32_t(SystemKSettingID_T id, uint32_t *value)
|
||||||
key = "T_Start_Game_in_ms";
|
key = "T_Start_Game_in_ms";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SYSTEMK_SETTING_T_GAME_LENGTH_in_ms:
|
||||||
|
key = "T_Game_Length_in_ms";
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
result = SYSTEMK_RESULT_WRONG_DATATYPE;
|
result = SYSTEMK_RESULT_WRONG_DATATYPE;
|
||||||
break;
|
break;
|
||||||
|
@ -199,6 +241,10 @@ SystemKResult_T SETTINGS_set_uint32_t(SystemKSettingID_T id, uint32_t value)
|
||||||
result = KV_Set_Value_uint32(CONFIG_FILE, "T_Start_Game_in_ms", &value);
|
result = KV_Set_Value_uint32(CONFIG_FILE, "T_Start_Game_in_ms", &value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SYSTEMK_SETTING_T_GAME_LENGTH_in_ms:
|
||||||
|
result = KV_Set_Value_uint32(CONFIG_FILE, "T_Game_Length_in_ms", &value);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
result = SYSTEMK_RESULT_WRONG_DATATYPE;
|
result = SYSTEMK_RESULT_WRONG_DATATYPE;
|
||||||
break;
|
break;
|
||||||
|
@ -209,13 +255,21 @@ SystemKResult_T SETTINGS_set_uint32_t(SystemKSettingID_T id, uint32_t value)
|
||||||
|
|
||||||
SystemKResult_T SETTINGS_get_device_name(char* name)
|
SystemKResult_T SETTINGS_get_device_name(char* name)
|
||||||
{
|
{
|
||||||
SystemKResult_T result = SYSTEMK_RESULT_NOT_IMPLEMENTED;
|
char buffer[KV_MAX_VALUE_LENGTH];
|
||||||
|
SystemKResult_T result = KV_Get_Value_string(CONFIG_FILE, "Device_Name", buffer);
|
||||||
|
|
||||||
|
if (result == SYSTEMK_RESULT_SUCCESS)
|
||||||
|
{
|
||||||
|
memcpy(name, buffer, SYSTEMK_MAX_CHARS_IN_DEVICE_NAME);
|
||||||
|
buffer[SYSTEMK_MAX_CHARS_IN_DEVICE_NAME] = 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemKResult_T SETTINGS_set_device_name(char* name)
|
SystemKResult_T SETTINGS_set_device_name(char* name)
|
||||||
{
|
{
|
||||||
SystemKResult_T result = SYSTEMK_RESULT_NOT_IMPLEMENTED;
|
SystemKResult_T result = KV_Set_Value_string(CONFIG_FILE, "Device_Name", name);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 82ec410264cd43e5dbd1778a1dc51ebf36f2f0b5
|
Subproject commit 47822bbdec20eda1a4c21871c7b4fe17c36bb731
|
|
@ -6,15 +6,22 @@
|
||||||
Config_Version=1
|
Config_Version=1
|
||||||
Model=2024A
|
Model=2024A
|
||||||
|
|
||||||
|
; Device-Specific
|
||||||
|
Device_Name=Another 32ESP'al
|
||||||
|
|
||||||
; Game Settings
|
; Game Settings
|
||||||
Player_ID=1
|
Player_ID=1
|
||||||
Team_ID=1
|
Team_ID=1
|
||||||
Weapon_ID=10
|
Weapon_ID=10
|
||||||
|
Max_Health=100
|
||||||
|
N_Special_Weapons_On_Reentry=1
|
||||||
|
T_Start_Game_in_ms=30000
|
||||||
|
T_Game_Length_in_ms=600000
|
||||||
|
Secondary_Color=0
|
||||||
|
|
||||||
; Hardware Settings
|
; Hardware Settings
|
||||||
Is_Right_Handed=1
|
Is_Right_Handed=1
|
||||||
Audio_Volume=30
|
Audio_Volume=30
|
||||||
T_Start_Game_in_ms=30000
|
|
||||||
|
|
||||||
; WiFi
|
; WiFi
|
||||||
; SSID and password of the network this device should connect to when it is in range.
|
; SSID and password of the network this device should connect to when it is in range.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue