-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathWidgetSettings.h
97 lines (79 loc) · 3.03 KB
/
WidgetSettings.h
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
/*
* This program 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 of the License, or
* (at your option) any later version.
*
* 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 Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* WidgetSettings.h
* Copyright (C) 2011 Simon Newton
*/
#include "Arduino.h"
#ifndef WIDGET_SETTINGS_H
#define WIDGET_SETTINGS_H
/**
* Manages reading & writing settings from EEPROM.
*/
class WidgetSettingsClass {
public:
WidgetSettingsClass()
: m_label_pending(false),
m_label_size(0)
{}
void Init();
unsigned int StartAddress() const { return m_start_address; };
void SetStartAddress(unsigned int start_address);
int EstaId() const;
void SetEstaId(int esta_id);
// helper method to compare an array of bytes against the esta id
bool MatchesEstaId(const byte *data) const;
long SerialNumber() const;
void SetSerialNumber(long serial_number);
// helper method to compare an array of bytes against the serial #
bool MatchesSerialNumber(const byte *data) const;
byte DeviceLabel(char *label, byte length) const;
void SetDeviceLabel(const char *new_label, byte length);
unsigned long DevicePowerCycles() const;
void SetDevicePowerCycles(unsigned long count);
void IncrementDevicePowerCycles();
int SensorValue() const;
void SaveSensorValue(int value);
byte Personality() const { return m_personality; }
void SetPersonality(byte value);
// perform any pending writes
bool PerformWrite();
private:
static const int MAGIC_NUMBER;
static const long DEFAULT_SERIAL_NUMBER;
static const char DEFAULT_LABEL[];
enum { MAX_LABEL_LENGTH = 32};
static const byte MAGIC_NUMBER_OFFSET;
static const byte START_ADDRESS_OFFSET;
static const byte ESTA_ID_OFFSET;
static const byte SERIAL_NUMBER_OFFSET;
static const byte DEVICE_LABEL_SIZE_OFFSET;
static const byte DEVICE_LABEL_OFFSET;
static const byte DEVICE_POWER_CYCLES_OFFSET;
static const byte SENSOR_0_RECORDED_VALUE;
static const byte DMX_PERSONALITY_VALUE;
unsigned int m_start_address;
byte m_personality;
// background writing of the label
char m_label_buffer[MAX_LABEL_LENGTH];
bool m_label_pending;
byte m_label_size;
unsigned int ReadInt(unsigned int offset) const;
void WriteInt(unsigned int offset, int data);
unsigned long ReadLong(unsigned long offset) const;
void WriteLong(unsigned long offset, long data);
};
extern WidgetSettingsClass WidgetSettings;
#endif // USBPRO_SENDER_H