forked from schneider42/moodlamp-rf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.c
148 lines (135 loc) · 4.53 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* vim:fdm=marker ts=4 et ai
* {{{
* moodlamp-ng - fnordlicht firmware next generation
*
* for additional information please
* see http://blinkenlichts.net/
* and http://koeln.ccc.de/prozesse/running/fnordlicht
*
* This is a modified version of the fnordlicht
* (c) by Alexander Neumann <[email protected]>
* Lars Noschinski <[email protected]>
*
* Modifications done by Tobias Schneider([email protected])
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
}}} */
#include <avr/eeprom.h>
#include <string.h>
#include "fnordlicht.h"
#include "settings.h"
#include "scripts.h"
#include "static_scripts.h"
#include "pwm.h"
#include "control.h"
struct settings_record_t global_settings_record EEMEM = {1,1};
struct global_pwm_t global_pwm_record EEMEM;
#if STATIC_SCRIPTS
struct thread_t script_threads_record[MAX_THREADS] EEMEM;
#endif
struct timeslots_t pwm_record EEMEM;
struct global_t global_record EEMEM;
struct settings_record_t global_settings;
//char name[50] EEMEM = "\x33master5.lamp.blinkenlichts.net";
char * name = (char *)(E2END - 50);
uint8_t idbuf[60];
void settings_readid(uint8_t * buf)
{
// eeprom_read_block(buf,&id,sizeof(id));
eeprom_read_block(buf,name,50);
}
uint8_t settings_compareid(uint8_t * buf)
{
if(strcmp((char*)idbuf,(char*)buf) == 0)
return 1;
return 0;
}
void settings_setid(uint8_t * buf)
{
return;
uint8_t len = strlen((char*)buf);
// if(len > (sizeof(id)-1)){
// len = sizeof(id)-1;
if(len > 50){
len = 49;
buf[len] = 0;
}
// eeprom_write_block(&id,buf,len+1);
eeprom_write_block(buf,name,len+1);
}
void settings_save(void)
{
return;
const void * temp;
global_settings.firstboot = 0;
eeprom_write_block(&global_settings, &global_settings_record,sizeof(global_settings));
temp =(const void *) &global_pwm; //Just to avoid compiler warnings
eeprom_write_block(
temp,
&global_pwm_record,
sizeof(global_pwm)
);
#if STATIC_SCRIPTS
eeprom_write_block(script_threads,&script_threads_record,sizeof(script_threads)*MAX_THREADS);
#endif
eeprom_write_block(&pwm,&pwm_record,sizeof(pwm));
temp = (const void *) &global;
eeprom_write_block(/*(struct global_t *)&global*/temp,&global_record,sizeof(global));
}
void settings_read(void)
{
void * temp;
//eeprom_read_block(&global_settings, &global_settings_record,sizeof(global_settings));
// if(global_settings.firstboot){
global_pwm.dim = 255;
#if STATIC_SCRIPTS
//#if RS485_CTRL == 0
script_threads[0].speed_adjustment = 0;
script_threads[0].handler.execute = &memory_handler_flash;
script_threads[0].handler.position = (uint16_t)(&colorchange_red);
script_threads[0].flags.disabled = 0;
//script_threads[2].handler.execute = &memory_handler_eeprom;
//script_threads[2].handler.position = (uint16_t) &testscript_eeprom;
//script_threads[2].flags.disabled = 0;
//#endif
#endif
//global_pwm.channels[0].brightness = 250;
//global_pwm.channels[0].target_brightness = 250;
global.flags.running = 1;
global.state = STATE_RUNNING;
//global.flags.rawmode = 0;
#if 0
}else{
temp = (void *) &global_pwm;
eeprom_read_block(/*(void *)&global_pwm*/temp,&global_pwm_record,sizeof(global_pwm));
#if STATIC_SCRIPTS
eeprom_read_block(script_threads,&script_threads_record,sizeof(script_threads)*MAX_THREADS);
#endif
eeprom_read_block(&pwm,&pwm_record,sizeof(pwm));
temp = (void *) &global;
eeprom_read_block(/*(struct global_t *)&global*/temp,&global_record,sizeof(global));
}
#endif
eeprom_read_block(idbuf,name,50);
#if 0
if(idbuf[0] == 255){
strcpy((char*)idbuf,"newlamp.local");
eeprom_write_block(idbuf,name,50);
}
#endif
// eeprom_read_block(idbuf,&id,sizeof(id));
}