hurricane/security_camera/settings.c

/*******************************************************************************
* # License
* Copyright 2019 Silicon Laboratories Inc. www.silabs.com
*******************************************************************************
*
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/
#include "common.h"
#define SETTINGS_MAGIC_NUMBER 0x010002
GOS_NVM_DEFINES_START
// GOS_NVM_DEFINE_TYPE(HURRICANE, 0), This is defined by the hurricane library
GOS_NVM_DEFINE_ENTRY(HURRICANE, CAMERA_SETTINGS, 0, sizeof(security_camera_settings_t)),
GOS_NVM_DEFINES_END
#define DEFAULT_CAMERA_SETTINGS \
{ \
.setting = { \
[ARDUCAM_SETTING_RESOLUTION] = ARDUCAM_RES_160x120, \
[ARDUCAM_SETTING_BRIGHTNESS] = 0, \
[ARDUCAM_SETTING_CONTRAST] = 0, \
[ARDUCAM_SETTING_SATURATION] = 0, \
[ARDUCAM_SETTING_QUALITY] = 1, \
[ARDUCAM_SETTING_MIRROR] = 0, \
[ARDUCAM_SETTING_FLIP] = 0, \
[ARDUCAM_SETTING_SPECIALEFFECT] = ARDUCAM_SPECIALEFFECT_NONE \
}, \
.update_interval_ms = DEFAULT_UPDATE_INTERNVAL_MS, \
.gps_antenna = HURRICANE_GPS_ANT_INTERNAL \
}
GOS_NVM_CREATE_DEFAULT_ENTRY(HURRICANE, CAMERA_SETTINGS, security_camera_settings_t, DEFAULT_CAMERA_SETTINGS);
security_camera_settings_t* camera_settings;
GOS_CMD_CREATE_GETTER_SETTER(camera, gps_antenna, "camera.gps.antenna", SC3('c','a','g','a'), 0, 1);
GOS_CMD_CREATE_GETTER(camera, update_interval, "camera.update_interval", SC2('c','a','u'), 0);
/*************************************************************************************************/
gos_result_t settings_init(void)
{
gos_result_t result;
if(GOS_FAILED(result, gos_load_app_settings_once("settings.ini", SETTINGS_MAGIC_NUMBER)))
{
}
else if(GOS_FAILED(result, GOS_NVM_GET(HURRICANE, CAMERA_SETTINGS, camera_settings)))
{
}
return result;
}
/*************************************************************************************************/
gos_result_t settings_save(void)
{
return gos_nvm_save();
}
/*************************************************************************************************/
static gos_cmd_result_t camera_set_gps_antenna_command(int argc, char **argv)
{
if(strcmp(argv[1], "internal") == 0)
{
camera_settings->gps_antenna = HURRICANE_GPS_ANT_INTERNAL;
hurricane_gps_set_antenna(HURRICANE_GPS_ANT_INTERNAL);
}
else if(strcmp(argv[1], "external") == 0)
{
camera_settings->gps_antenna = HURRICANE_GPS_ANT_EXTERNAL;
hurricane_gps_set_antenna(HURRICANE_GPS_ANT_EXTERNAL);
}
else
{
}
}
/*************************************************************************************************/
static gos_cmd_result_t camera_get_gps_antenna_command(int argc, char **argv)
{
const char* antenna = (camera_settings->gps_antenna == HURRICANE_GPS_ANT_INTERNAL) ? "internal" : "external";
}
/*************************************************************************************************/
static gos_cmd_result_t camera_get_update_interval_command(int argc, char **argv)
{
gos_cmd_format_response(GOS_CMD_SUCCESS, "%d", camera_settings->update_interval_ms);
}