aboutsummaryrefslogtreecommitdiff
path: root/arduino/config.cc
diff options
context:
space:
mode:
authorMarc Sunet <msunet@shellblade.net>2022-12-01 10:38:12 -0800
committerMarc Sunet <msunet@shellblade.net>2022-12-01 10:38:12 -0800
commit8543b0f9df2e527cb242d0629d5b5574c0d76d30 (patch)
tree2d7e76478017cea9972afe8450e1213bc38d3a05 /arduino/config.cc
parente62be3b12d3c94d709a77d89f52c31f7c4ac475d (diff)
Move arduino program to rpmcount folder and rename cc files to cpp as the IDE expects.HEADmain
Diffstat (limited to 'arduino/config.cc')
-rwxr-xr-xarduino/config.cc61
1 files changed, 0 insertions, 61 deletions
diff --git a/arduino/config.cc b/arduino/config.cc
deleted file mode 100755
index a46c663..0000000
--- a/arduino/config.cc
+++ /dev/null
@@ -1,61 +0,0 @@
1#include "config.h"
2
3#include <Arduino.h>
4#include <EEPROM.h>
5
6#define ROM_INITIALISED 17
7
8#define DEFAULT_SIGNALS_PER_RPM 133
9#define DEFAULT_START_DELAY_MILLIS 1000
10#define DEFAULT_RPM_COUNT 5000
11
12static Config config;
13
14int writeLong (int address, unsigned long val)
15{
16 const char* p = (char*) &val;
17 int i = 0;
18 for (; i < sizeof(val); ++i, ++p)
19 {
20 EEPROM.write(address + i, *p);
21 }
22 return address + i;
23}
24
25int readLong (int address, unsigned long& val)
26{
27 char* p = (char*) &val;
28 int i = 0;
29 for (; i < sizeof(val); ++i, ++p)
30 {
31 *p = EEPROM.read(address + i);
32 }
33 return address + i;
34}
35
36const Config& readConfig ()
37{
38 byte initialised = EEPROM.read(0);
39 if (initialised != ROM_INITIALISED)
40 {
41 int addr = 1;
42 addr = writeLong(addr, DEFAULT_START_DELAY_MILLIS);
43 addr = writeLong(addr, DEFAULT_RPM_COUNT);
44 addr = writeLong(addr, DEFAULT_SIGNALS_PER_RPM);
45 EEPROM.write(0, ROM_INITIALISED);
46 }
47 int addr = 1;
48 addr = readLong(addr, config.startDelay);
49 addr = readLong(addr, config.rpmCount);
50 addr = readLong(addr, config.signalsPerRPM);
51 return config;
52}
53
54void writeConfig (const Config& config)
55{
56 int addr = 1;
57 addr = writeLong(addr, config.startDelay);
58 addr = writeLong(addr, config.rpmCount);
59 addr = writeLong(addr, config.signalsPerRPM);
60 EEPROM.write(0, ROM_INITIALISED);
61}