Chameleon-Mini
Settings.h
Go to the documentation of this file.
1 /*
2  * Settings.h
3  *
4  * Created on: 21.12.2013
5  * Author: skuser
6  */
8 #ifndef SETTINGS_H_
9 #define SETTINGS_H_
10 
11 #include "Button.h"
12 #include "Configuration.h"
13 #include "Log.h"
14 #include "LED.h"
15 #include "Memory.h"
16 #include <avr/eeprom.h>
17 
18 #define SETTINGS_COUNT (MEMORY_SIZE / MEMORY_SIZE_PER_SETTING)
19 #define SETTINGS_FIRST 1
20 #define SETTINGS_LAST (SETTINGS_FIRST + SETTINGS_COUNT - 1)
21 
26 typedef struct {
27  ButtonActionEnum ButtonActions[BUTTON_TYPE_COUNT];
28  LogModeEnum LogMode;
29  ConfigurationEnum Configuration;
30  LEDHookEnum LEDRedFunction;
31  LEDHookEnum LEDGreenFunction;
32  uint16_t PendingTaskTimeout;
33  uint16_t ReaderThreshold;
35 
36 typedef struct {
37  uint8_t ActiveSettingIdx;
38  SettingsEntryType *ActiveSettingPtr;
39  SettingsEntryType Settings[SETTINGS_COUNT];
40 } SettingsType;
41 
42 extern SettingsType GlobalSettings, StoredSettings;
43 
44 INLINE void SettingUpdate(const void *addr, uint16_t size) {
45 #if ENABLE_EEPROM_SETTINGS
46  uintptr_t EEAddr = (uintptr_t)addr - (uintptr_t)&GlobalSettings + (uintptr_t)&StoredSettings;
47  switch (size) {
48  case 1:
49  eeprom_update_byte((uint8_t *)EEAddr, *(uint8_t *)addr);
50  break;
51 
52  case 2:
53  eeprom_update_word((uint16_t *)EEAddr, *(uint16_t *)addr);
54  break;
55 
56  default:
57  eeprom_update_block((uint8_t *)addr, (uint8_t *)EEAddr, size);
58  }
59 #endif
60 }
61 
62 #define SETTING_UPDATE(x) SettingUpdate(&(x), sizeof(x))
63 
64 void SettingsLoad(void);
65 void SettingsSave(void);
66 
67 void SettingsCycle(void);
68 bool SettingsSetActiveById(uint8_t Setting);
69 uint8_t SettingsGetActiveById(void);
70 void SettingsGetActiveByName(char *SettingOut, uint16_t BufferSize);
71 bool SettingsSetActiveByName(const char *Setting);
72 
73 #endif /* SETTINGS_H_ */
uint16_t ReaderThreshold
Timeout for timeout commands for this setting, in multiples of 100 ms.
Definition: Settings.h:33
LogModeEnum LogMode
Button actions for this setting.
Definition: Settings.h:28
Definition: Settings.h:26
LEDHookEnum LEDGreenFunction
Red LED function for this setting.
Definition: Settings.h:31
uint16_t PendingTaskTimeout
Green LED function for this setting.
Definition: Settings.h:32
ConfigurationEnum Configuration
Log mode for this setting.
Definition: Settings.h:29
LEDHookEnum LEDRedFunction
Active configuration for this setting.
Definition: Settings.h:30