Kaleidoscope Style Guide conformance

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/365/head
Gergely Nagy 8 years ago
parent 49887a2805
commit 202860575b

@ -115,7 +115,7 @@ The plugin provides the `EEPROMSettings` object, which has the following methods
> >
> Should only be used after calling `seal()`. > Should only be used after calling `seal()`.
## Focus Hooks ## Focus commands
The plugin provides two [Focus][focus] hooks: `FOCUS_HOOK_SETTINGS`, and The plugin provides two [Focus][focus] hooks: `FOCUS_HOOK_SETTINGS`, and
`FOCUS_HOOK_EEPROM`, that register commands that allow one to work with the `FOCUS_HOOK_EEPROM`, that register commands that allow one to work with the
@ -123,6 +123,33 @@ settings, and with the contents of the `EEPROM` through Focus.
[focus]: https://github.com/keyboardio/Kaleidoscope-Focus [focus]: https://github.com/keyboardio/Kaleidoscope-Focus
These provide the following `Focus` commands:
### `settings.crc`
> Returns the actual, and the expected checksum of the settings.
### `settings.valid?`
> Returns either `true` or `false`, depending on whether the sealed settings are
> to be considered valid or not.
### `settings.version`
> Returns the (user-set) version of the settings.
### `eeprom.contents`
> Without argument, displays the full contents of the `EEPROM`, including the
> settings header.
>
> With arguments, the command updates as much of the `EEPROM` as arguments are
> provided. It will discard any unnecessary arguments.
### `eeprom.free`
> Returns the amount of free bytes in `EEPROM`.
## Dependencies ## Dependencies
* [Kaleidoscope-Focus][focus] * [Kaleidoscope-Focus][focus]

@ -19,92 +19,84 @@
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#include "crc.h" #include "crc.h"
namespace KaleidoscopePlugins { namespace kaleidoscope {
struct EEPROMSettings::settings EEPROMSettings::settings;
bool EEPROMSettings::_isValid; struct EEPROMSettings::settings EEPROMSettings::settings_;
bool EEPROMSettings::sealed; bool EEPROMSettings::is_valid_;
uint16_t EEPROMSettings::nextStart = sizeof(EEPROMSettings::settings); bool EEPROMSettings::sealed_;
uint16_t EEPROMSettings::next_start_ = sizeof(EEPROMSettings::settings);
EEPROMSettings::EEPROMSettings(void) { EEPROMSettings::EEPROMSettings(void) {
} }
void void EEPROMSettings::begin(void) {
EEPROMSettings::begin(void) { EEPROM.get(0, settings_);
EEPROM.get(0, settings);
} }
bool bool EEPROMSettings::isValid(void) {
EEPROMSettings::isValid(void) { return is_valid_;
return _isValid;
} }
uint16_t uint16_t EEPROMSettings::crc(void) {
EEPROMSettings::crc(void) { if (sealed_)
if (sealed) return settings_.crc;
return settings.crc;
return 0; return 0;
} }
void void EEPROMSettings::seal(void) {
EEPROMSettings::seal(void) { sealed_ = true;
sealed = true;
CRC.finalize(); CRC.finalize();
if (settings.magic[0] != 'K' || settings.magic[1] != 'S') { if (settings_.magic[0] != 'K' || settings_.magic[1] != 'S') {
settings.magic[0] = 'K'; settings_.magic[0] = 'K';
settings.magic[1] = 'S'; settings_.magic[1] = 'S';
settings.version = 0; settings_.version = 0;
settings.crc = CRC.crc; settings_.crc = CRC.crc;
return update(); return update();
} }
if (settings.crc != CRC.crc) if (settings_.crc != CRC.crc)
_isValid = false; is_valid_ = false;
} }
uint16_t uint16_t EEPROMSettings::requestSlice(uint16_t size) {
EEPROMSettings::requestSlice(uint16_t size) { if (sealed_)
if (sealed)
return 0; return 0;
uint16_t start = nextStart; uint16_t start = next_start_;
nextStart += size; next_start_ += size;
CRC.update((const void *)&size, sizeof(size)); CRC.update((const void *)&size, sizeof(size));
return start; return start;
} }
void void EEPROMSettings::invalidate(void) {
EEPROMSettings::invalidate(void) { is_valid_ = false;
_isValid = false;
} }
uint16_t uint16_t EEPROMSettings::used(void) {
EEPROMSettings::used(void) { return next_start_;
return nextStart;
} }
void void EEPROMSettings::update(void) {
EEPROMSettings::update(void) { settings_.crc = CRC.crc;
settings.crc = CRC.crc;
EEPROM.put(0, settings); EEPROM.put(0, settings_);
_isValid = true; is_valid_ = true;
} }
uint8_t uint8_t EEPROMSettings::version(void) {
EEPROMSettings::version(void) { return settings_.version;
return settings.version;
} }
void void EEPROMSettings::version(uint8_t ver) {
EEPROMSettings::version(uint8_t ver) { settings_.version = ver;
settings.version = ver;
update(); update();
} }
};
KaleidoscopePlugins::EEPROMSettings EEPROMSettings; }
kaleidoscope::EEPROMSettings EEPROMSettings;

@ -21,7 +21,7 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <EEPROM.h> #include <EEPROM.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
class EEPROMSettings : public KaleidoscopePlugin { class EEPROMSettings : public KaleidoscopePlugin {
public: public:
EEPROMSettings(void); EEPROMSettings(void);
@ -40,16 +40,16 @@ class EEPROMSettings : public KaleidoscopePlugin {
static uint16_t used(void); static uint16_t used(void);
private: private:
static uint16_t nextStart; static uint16_t next_start_;
static bool _isValid; static bool is_valid_;
static bool sealed; static bool sealed_;
static struct settings { static struct settings {
char magic[2]; char magic[2];
uint8_t version; uint8_t version;
uint16_t crc; uint16_t crc;
} settings; } settings_;
}; };
}; };
extern KaleidoscopePlugins::EEPROMSettings EEPROMSettings; extern kaleidoscope::EEPROMSettings EEPROMSettings;

Loading…
Cancel
Save