TimJTi commented on code in PR #2228:
URL: https://github.com/apache/nuttx-apps/pull/2228#discussion_r1424268982


##########
system/settings/storage_eeprom.c:
##########
@@ -0,0 +1,408 @@
+/****************************************************************************
+ * apps/system/settings/storage_eeprom.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ *
+ * The EEPROM storage is similar to the binary type, but only saves out
+ * values if they've actually changed, to maximise device life.
+ *
+ * It can, of course, be used with other storage media types that have
+ * limited write cycle capabilities.
+ *
+ * RE-VISIT IN FUTURE - This could be enhanced by allowing for variable
+ * storage sizes, but gets complicated if the settings type, and hence size,
+ * changes as settings after the saved storage will need to move/change.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include "system/settings.h"
+#include <unistd.h>
+#include <errno.h>
+#include <assert.h>
+#include <fcntl.h>
+#include <nuttx/crc32.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <nuttx/config.h>
+#include <sys/types.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+FAR static setting_t *getsetting(char *key);
+size_t getsettingsize(enum settings_type_e type);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static size_t used_storage;
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+extern setting_t map[CONFIG_SYSTEM_SETTINGS_MAP_SIZE];
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: getsetting
+ *
+ * Description:
+ *    Gets the setting information from a given key.
+ *
+ * Input Parameters:
+ *    key        - key of the required setting
+ *
+ * Returned Value:
+ *   The setting
+ *
+ ****************************************************************************/
+
+FAR setting_t *getsetting(FAR char *key)
+{
+  int i;
+
+  for (i = 0; i < CONFIG_SYSTEM_SETTINGS_MAP_SIZE; i++)
+    {
+      FAR setting_t *setting = &map[i];
+
+      if (strcmp(key, setting->key) == 0)
+        {
+          return setting;
+        }
+
+      if (setting->type == SETTING_EMPTY)
+        {
+          return setting;
+        }
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: getsettingsize
+ *
+ * Description:
+ *    Helper function to gets the size of the setting type for a given type.
+ *
+ * Input Parameters:
+ *    type        - the type to get the size of
+ *
+ * Returned Value:
+ *   The setting
+ *
+ ****************************************************************************/
+
+size_t getsettingsize(enum settings_type_e type)
+{
+  switch (type)
+    {
+      case SETTING_STRING:
+        {
+          return CONFIG_SYSTEM_SETTINGS_VALUE_SIZE * (sizeof(char));
+        }
+      break;
+      case SETTING_BOOL:
+        {
+          return sizeof(bool);
+        }
+      break;
+      case SETTING_INT:
+        {
+          return sizeof(int);
+        }
+      break;
+      case SETTING_BYTE:
+        {
+          return sizeof(uint8_t);
+        }
+      break;
+      case SETTING_FLOAT:
+        {
+          return sizeof(float);

Review Comment:
   Good spot!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to