|
| 1 | +/* |
| 2 | + SmartHome mappa della EEPROM dell'ESP8266 |
| 3 | +
|
| 4 | + 0 -> SmartHome Tapparella 1 - Tapparella_tempo_max (long 4th byte) |
| 5 | + 1 -> SmartHome Tapparella 1 - Tapparella_tempo_max (long 3th byte) |
| 6 | + 2 -> SmartHome Tapparella 1 - Tapparella_tempo_max (long 2nd byte) |
| 7 | + 3 -> SmartHome Tapparella 1 - Tapparella_tempo_max (long 1st byte) |
| 8 | + 4 -> SmartHome Tapparella 2 - Tapparella_tempo_max (long 4th byte) |
| 9 | + 5 -> SmartHome Tapparella 2 - Tapparella_tempo_max (long 3th byte) |
| 10 | + 6 -> SmartHome Tapparella 2 - Tapparella_tempo_max (long 2nd byte) |
| 11 | + 7 -> SmartHome Tapparella 2 - Tapparella_tempo_max (long 1st byte) |
| 12 | + 8 -> SmartHome Tapparella 3 - Tapparella_tempo_max (long 4th byte) |
| 13 | + 9 -> SmartHome Tapparella 3 - Tapparella_tempo_max (long 3th byte) |
| 14 | + 10 -> SmartHome Tapparella 3 - Tapparella_tempo_max (long 2nd byte) |
| 15 | + 11 -> SmartHome Tapparella 3 - Tapparella_tempo_max (long 1st byte) |
| 16 | + 12 -> SmartHome Tapparella 4 - Tapparella_tempo_max (long 4th byte) |
| 17 | + 13 -> SmartHome Tapparella 4 - Tapparella_tempo_max (long 3th byte) |
| 18 | + 14 -> SmartHome Tapparella 4 - Tapparella_tempo_max (long 2nd byte) |
| 19 | + 15 -> SmartHome Tapparella 4 - Tapparella_tempo_max (long 1st byte) |
| 20 | + 16 -> SmartHome Tapparella 5 - Tapparella_tempo_max (long 4th byte) |
| 21 | + 17 -> SmartHome Tapparella 5 - Tapparella_tempo_max (long 3th byte) |
| 22 | + 18 -> SmartHome Tapparella 5 - Tapparella_tempo_max (long 2nd byte) |
| 23 | + 19 -> SmartHome Tapparella 5 - Tapparella_tempo_max (long 1st byte) |
| 24 | +
|
| 25 | + 40 -> SmartHome Tapparella 1 - 1=lock 0=unlock (int 2nd byte) |
| 26 | + 41 -> SmartHome Tapparella 1 - 1=lock 0=unlock (int 1st byte) |
| 27 | + 42 -> SmartHome Tapparella 2 - 1=lock 0=unlock (int 2nd byte) |
| 28 | + 43 -> SmartHome Tapparella 2 - 1=lock 0=unlock (int 1st byte) |
| 29 | + 44 -> SmartHome Tapparella 3 - 1=lock 0=unlock (int 2nd byte) |
| 30 | + 45 -> SmartHome Tapparella 3 - 1=lock 0=unlock (int 1st byte) |
| 31 | + 46 -> SmartHome Tapparella 4 - 1=lock 0=unlock (int 2nd byte) |
| 32 | + 47 -> SmartHome Tapparella 4 - 1=lock 0=unlock (int 1st byte) |
| 33 | + 48 -> SmartHome Tapparella 5 - 1=lock 0=unlock (int 2nd byte) |
| 34 | + 49 -> SmartHome Tapparella 5 - 1=lock 0=unlock (int 1st byte) |
| 35 | +
|
| 36 | + 100 -> SmartHome Termostato 1 - AUTO 1=AUTO 0=MAN (int 2nd byte) |
| 37 | + 101 -> SmartHome Termostato 1 - AUTO 1=AUTO 0=MAN (int 1st byte) |
| 38 | + 102 -> SmartHome Termostato 2 - AUTO 1=AUTO 0=MAN (int 2nd byte) |
| 39 | + 103 -> SmartHome Termostato 2 - AUTO 1=AUTO 0=MAN (int 1st byte) |
| 40 | + 104 -> SmartHome Termostato 1 - TERMOSTATO (float 4th byte) |
| 41 | + 105 -> SmartHome Termostato 1 - TERMOSTATO (float 3th byte) |
| 42 | + 106 -> SmartHome Termostato 1 - TERMOSTATO (float 2nd byte) |
| 43 | + 107 -> SmartHome Termostato 1 - TERMOSTATO (float 1st byte) |
| 44 | + 108 -> SmartHome Termostato 2 - TERMOSTATO (float 4th byte) |
| 45 | + 109 -> SmartHome Termostato 2 - TERMOSTATO (float 3th byte) |
| 46 | + 110 -> SmartHome Termostato 2 - TERMOSTATO (float 2nd byte) |
| 47 | + 111 -> SmartHome Termostato 2 - TERMOSTATO (float 1st byte) |
| 48 | +
|
| 49 | + 200 -> SmartHome RELE Interruttore 1 (int 2nd byte) |
| 50 | + 201 -> SmartHome RELE Interruttore 1 (int 1st byte) |
| 51 | + 202 -> SmartHome RELE Interruttore 2 (int 2nd byte) |
| 52 | + 203 -> SmartHome RELE Interruttore 2 (int 1st byte) |
| 53 | + 204 -> SmartHome RELE Interruttore 3 (int 2nd byte) |
| 54 | + 205 -> SmartHome RELE Interruttore 3 (int 1st byte) |
| 55 | + 206 -> SmartHome RELE Interruttore 4 (int 2nd byte) |
| 56 | + 207 -> SmartHome RELE Interruttore 4 (int 1st byte) |
| 57 | + 208 -> SmartHome RELE Interruttore 5 (int 2nd byte) |
| 58 | + 209 -> SmartHome RELE Interruttore 5 (int 1st byte) |
| 59 | + 210 -> SmartHome RELE Interruttore 6 (int 2nd byte) |
| 60 | + 211 -> SmartHome RELE Interruttore 6 (int 1st byte) |
| 61 | + 212 -> SmartHome RELE Interruttore 7 (int 2nd byte) |
| 62 | + 213 -> SmartHome RELE Interruttore 7 (int 1st byte) |
| 63 | + 214 -> SmartHome RELE Interruttore 8 (int 2nd byte) |
| 64 | + 215 -> SmartHome RELE Interruttore 8 (int 1st byte) |
| 65 | + 216 -> SmartHome RELE Interruttore 9 (int 2nd byte) |
| 66 | + 217 -> SmartHome RELE Interruttore 9 (int 1st byte) |
| 67 | + 218 -> SmartHome RELE Interruttore 10 (int 2nd byte) |
| 68 | + 219 -> SmartHome RELE Interruttore 10 (int 1st byte) |
| 69 | +
|
| 70 | + 250 -> SmartHome valore Dimmer 1 (int 2nd byte) |
| 71 | + 251 -> SmartHome valore Dimmer 1 (int 1st byte) |
| 72 | + 252 -> SmartHome valore Dimmer 2 (int 2nd byte) |
| 73 | + 253 -> SmartHome valore Dimmer 2 (int 1st byte) |
| 74 | + 254 -> SmartHome valore Dimmer 3 (int 2nd byte) |
| 75 | + 255 -> SmartHome valore Dimmer 3 (int 1st byte) |
| 76 | + 256 -> SmartHome valore Dimmer 4 (int 2nd byte) |
| 77 | + 257 -> SmartHome valore Dimmer 4 (int 1st byte) |
| 78 | + 258 -> SmartHome valore Dimmer 5 (int 2nd byte) |
| 79 | + 259 -> SmartHome valore Dimmer 5 (int 1st byte) |
| 80 | + 260 -> SmartHome valore Dimmer 6 (int 2nd byte) |
| 81 | + 261 -> SmartHome valore Dimmer 6 (int 1st byte) |
| 82 | + 262 -> SmartHome valore Dimmer 7 (int 2nd byte) |
| 83 | + 263 -> SmartHome valore Dimmer 7 (int 1st byte) |
| 84 | + 264 -> SmartHome valore Dimmer 8 (int 2nd byte) |
| 85 | + 265 -> SmartHome valore Dimmer 8 (int 1st byte) |
| 86 | + 266 -> SmartHome valore Dimmer 9 (int 2nd byte) |
| 87 | + 267 -> SmartHome valore Dimmer 9 (int 1st byte) |
| 88 | + 268 -> SmartHome valore Dimmer 10 (int 2nd byte) |
| 89 | + 269 -> SmartHome valore Dimmer 10 (int 1st byte) |
| 90 | +
|
| 91 | + 300 -> SmartHome Temporizzatore 1 - Temporizzatore_tempo (long 4th byte) |
| 92 | + 301 -> SmartHome Temporizzatore 1 - Temporizzatore_tempo (long 3th byte) |
| 93 | + 302 -> SmartHome Temporizzatore 1 - Temporizzatore_tempo (long 2nd byte) |
| 94 | + 303 -> SmartHome Temporizzatore 1 - Temporizzatore_tempo (long 1st byte) |
| 95 | + 304 -> SmartHome Temporizzatore 2 - Temporizzatore_tempo (long 4th byte) |
| 96 | + 305 -> SmartHome Temporizzatore 2 - Temporizzatore_tempo (long 3th byte) |
| 97 | + 306 -> SmartHome Temporizzatore 2 - Temporizzatore_tempo (long 2nd byte) |
| 98 | + 307 -> SmartHome Temporizzatore 2 - Temporizzatore_tempo (long 1st byte) |
| 99 | + 308 -> SmartHome Temporizzatore 3 - Temporizzatore_tempo (long 4th byte) |
| 100 | + 309 -> SmartHome Temporizzatore 3 - Temporizzatore_tempo (long 3th byte) |
| 101 | + 310 -> SmartHome Temporizzatore 3 - Temporizzatore_tempo (long 2nd byte) |
| 102 | + 311 -> SmartHome Temporizzatore 3 - Temporizzatore_tempo (long 1st byte) |
| 103 | + 312 -> SmartHome Temporizzatore 4 - Temporizzatore_tempo (long 4th byte) |
| 104 | + 313 -> SmartHome Temporizzatore 4 - Temporizzatore_tempo (long 3th byte) |
| 105 | + 314 -> SmartHome Temporizzatore 4 - Temporizzatore_tempo (long 2nd byte) |
| 106 | + 315 -> SmartHome Temporizzatore 4 - Temporizzatore_tempo (long 1st byte) |
| 107 | + 316 -> SmartHome Temporizzatore 5 - Temporizzatore_tempo (long 4th byte) |
| 108 | + 317 -> SmartHome Temporizzatore 5 - Temporizzatore_tempo (long 3th byte) |
| 109 | + 318 -> SmartHome Temporizzatore 5 - Temporizzatore_tempo (long 2nd byte) |
| 110 | + 319 -> SmartHome Temporizzatore 5 - Temporizzatore_tempo (long 1st byte) |
| 111 | +
|
| 112 | + 350 -> SmartHome Display 1 riga 1 |
| 113 | + 370 -> SmartHome Display 1 riga 2 |
| 114 | + 390 -> SmartHome Display 1 riga 3 |
| 115 | +
|
| 116 | + |
| 117 | + 400 -> NFC UID (4 byte) |
| 118 | + ... |
| 119 | + 500 -> |
| 120 | +*/ |
| 121 | + |
| 122 | +#include <EEPROM.h> |
| 123 | + |
| 124 | +void setup_EEPROM() { |
| 125 | + // Inizializza EEPROM |
| 126 | + Debug_MSG_LN("EEPROM initializing"); |
| 127 | + Debug_MSG_LN(""); |
| 128 | + EEPROM.begin(512); |
| 129 | + delay(100); |
| 130 | +} |
| 131 | + |
| 132 | +void EEPROM_clear_reset() { // Pulisce la EEPROM e resetta l'ESP |
| 133 | + EEPROM.begin(512); |
| 134 | + // write a 0 to all 512 bytes of the EEPROM |
| 135 | + Debug_MSG("EEPROM clear:"); |
| 136 | + for (int i = 0; i < 512; i++) { |
| 137 | + EEPROM.write(i, 0); |
| 138 | + Debug_MSG("."); |
| 139 | + } |
| 140 | + Debug_MSG_LN(""); |
| 141 | + Debug_MSG_LN("EEPROM CLEARED!"); |
| 142 | + EEPROM.end(); |
| 143 | + Debug_MSG_LN("RESET!"); |
| 144 | + delay(500); |
| 145 | + ESP.restart(); |
| 146 | +} |
| 147 | + |
| 148 | +//This function will write a 4 byte (32bit) long to the eeprom at |
| 149 | +//the specified address to address + 3. |
| 150 | +void EEPROMWritelong(int address, long value) { |
| 151 | + //Decomposition from a long to 4 bytes by using bitshift. |
| 152 | + //One = Most significant -> Four = Least significant byte |
| 153 | + byte four = (value & 0xFF); |
| 154 | + byte three = ((value >> 8) & 0xFF); |
| 155 | + byte two = ((value >> 16) & 0xFF); |
| 156 | + byte one = ((value >> 24) & 0xFF); |
| 157 | + //Write the 4 bytes into the eeprom memory. |
| 158 | + EEPROM.write(address, four); |
| 159 | + EEPROM.write(address + 1, three); |
| 160 | + EEPROM.write(address + 2, two); |
| 161 | + EEPROM.write(address + 3, one); |
| 162 | + EEPROM.commit(); |
| 163 | +} |
| 164 | + |
| 165 | +//This function will return a 4 byte (32bit) long from the eeprom |
| 166 | +//at the specified address to address + 3. |
| 167 | +long EEPROMReadlong(long address) { |
| 168 | + //Read the 4 bytes from the eeprom memory. |
| 169 | + long four = EEPROM.read(address); |
| 170 | + long three = EEPROM.read(address + 1); |
| 171 | + long two = EEPROM.read(address + 2); |
| 172 | + long one = EEPROM.read(address + 3); |
| 173 | + //Return the recomposed long by using bitshift. |
| 174 | + return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF); |
| 175 | +} |
| 176 | + |
| 177 | +int eepromReadInt(int address) { |
| 178 | + int value = 0x0000; |
| 179 | + value = value | (EEPROM.read(address) << 8); |
| 180 | + value = value | EEPROM.read(address + 1); |
| 181 | + return value; |
| 182 | +} |
| 183 | + |
| 184 | +void eepromWriteInt(int address, int value) { |
| 185 | + EEPROM.write(address, (value >> 8) & 0xFF ); |
| 186 | + EEPROM.write(address + 1, value & 0xFF); |
| 187 | + EEPROM.commit(); |
| 188 | +} |
| 189 | + |
| 190 | +float eepromReadFloat(int address) { |
| 191 | + union u_tag { |
| 192 | + byte b[4]; |
| 193 | + float fval; |
| 194 | + } u; |
| 195 | + u.b[0] = EEPROM.read(address); |
| 196 | + u.b[1] = EEPROM.read(address + 1); |
| 197 | + u.b[2] = EEPROM.read(address + 2); |
| 198 | + u.b[3] = EEPROM.read(address + 3); |
| 199 | + return u.fval; |
| 200 | +} |
| 201 | + |
| 202 | +void eepromWriteFloat(int address, float value) { |
| 203 | + union u_tag { |
| 204 | + byte b[4]; |
| 205 | + float fval; |
| 206 | + } u; |
| 207 | + u.fval = value; |
| 208 | + EEPROM.write(address , u.b[0]); |
| 209 | + EEPROM.write(address + 1, u.b[1]); |
| 210 | + EEPROM.write(address + 2, u.b[2]); |
| 211 | + EEPROM.write(address + 3, u.b[3]); |
| 212 | +} |
0 commit comments