59 lines
1.1 KiB
C
59 lines
1.1 KiB
C
/*
|
|
* Stairs lighting
|
|
* Copyright 2017 (c) Mark van Renswoude
|
|
*
|
|
* https://git.x2software.net/pub/Stairs
|
|
*/
|
|
#include "global.h"
|
|
#include <avr/eeprom.h>
|
|
|
|
|
|
// EEPROM
|
|
// First byte is 0xAA to recognize uninitialised EEPROM
|
|
#define EEPROMHeader 0xAA
|
|
|
|
// Second byte is a version indicator
|
|
#define EEPROMCurrentVersion 1
|
|
|
|
// Version 1 fields
|
|
// index: 2
|
|
uint8_t moduleIndex = ModuleIndexUndefined;
|
|
|
|
|
|
void global_init(void)
|
|
{
|
|
uint8_t address = 0;
|
|
if (eeprom_read_byte(&address) != EEPROMHeader)
|
|
{
|
|
eeprom_write_byte(&address, EEPROMHeader); address++;
|
|
eeprom_write_byte(&address, EEPROMCurrentVersion); address++;
|
|
eeprom_write_byte(&address, moduleIndex); address++;
|
|
}
|
|
else
|
|
{
|
|
address++;
|
|
uint8_t version = eeprom_read_byte(&address); address++;
|
|
if (version >= 1)
|
|
{
|
|
moduleIndex = eeprom_read_byte(&address); address++;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
uint8_t global_getModuleIndex(void)
|
|
{
|
|
return moduleIndex;
|
|
}
|
|
|
|
|
|
void global_setModuleIndex(uint8_t index)
|
|
{
|
|
if (index == moduleIndex)
|
|
return;
|
|
|
|
moduleIndex = index;
|
|
|
|
uint8_t address = 2;
|
|
eeprom_write_byte(&address, moduleIndex);
|
|
} |