-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
settings.c
67 lines (60 loc) · 1.85 KB
/
settings.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Copyright (C) 2009-2014 The Paparazzi Team
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/**
* @file subsystems/settings.c
* Persistent settings interface.
*
*/
#include "subsystems/settings.h"
#include "generated/settings.h"
struct PersistentSettings pers_settings;
/** flag for setting feedback.
* if TRUE, was stored sucessfully.
* Also settings still need a variable,
* pure function call not possible yet.
*/
bool_t settings_store_flag;
void settings_init(void) {
#if USE_PERSISTENT_SETTINGS
if (persistent_read((uint32_t)&pers_settings, sizeof(struct PersistentSettings)))
return; // return -1 ?
/* from generated/settings.h */
persistent_settings_load();
#endif
}
/** store settings marked as persistent to flash
* @return 0 on success
*/
int32_t settings_store(void) {
#if USE_PERSISTENT_SETTINGS
if (settings_store_flag) {
/* from generated/settings.h */
persistent_settings_store();
if (!persistent_write((uint32_t)&pers_settings, sizeof(struct PersistentSettings))) {
/* persistent write was successful */
settings_store_flag = TRUE;
return 0;
}
}
#endif
settings_store_flag = FALSE;
return -1;
}