astyle with current project style guidelines

pull/365/head
Jesse Vincent 8 years ago
parent e3dc58f384
commit a0b2d400db
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -40,21 +40,21 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
),
};
void setup () {
Serial.begin (9600);
void setup() {
Serial.begin(9600);
Kaleidoscope.setup ();
Kaleidoscope.setup();
USE_PLUGINS (&EEPROMSettings);
USE_PLUGINS(&EEPROMSettings);
while (!Serial) {
}
Serial.println (EEPROMSettings.isValid () ? F("valid EEPROM settings") : F("invalid EEPROM settings"));
Serial.println (EEPROMSettings.crc (), HEX);
Serial.println (EEPROMSettings.version ());
Serial.println(EEPROMSettings.isValid() ? F("valid EEPROM settings") : F("invalid EEPROM settings"));
Serial.println(EEPROMSettings.crc(), HEX);
Serial.println(EEPROMSettings.version());
}
void loop () {
Kaleidoscope.loop ();
void loop() {
Kaleidoscope.loop();
}

@ -21,76 +21,76 @@
#include "crc.h"
namespace FocusHooks {
bool settings (const char *command) {
bool settings(const char *command) {
enum {
ISVALID,
GETVERSION,
CRC,
} subCommand;
if (strncmp_P (command, PSTR ("settings."), 9) != 0)
if (strncmp_P(command, PSTR("settings."), 9) != 0)
return false;
if (strcmp_P (command + 9, PSTR ("valid?")) == 0)
if (strcmp_P(command + 9, PSTR("valid?")) == 0)
subCommand = ISVALID;
else if (strcmp_P (command + 9, PSTR ("version")) == 0)
else if (strcmp_P(command + 9, PSTR("version")) == 0)
subCommand = GETVERSION;
else if (strcmp_P (command + 9, PSTR ("crc")) == 0)
else if (strcmp_P(command + 9, PSTR("crc")) == 0)
subCommand = CRC;
else
return false;
switch (subCommand) {
case ISVALID:
Focus.printBool (EEPROMSettings.isValid ());
Serial.println ();
Focus.printBool(EEPROMSettings.isValid());
Serial.println();
break;
case GETVERSION:
Serial.println (EEPROMSettings.version ());
Serial.println(EEPROMSettings.version());
break;
case CRC:
Serial.print (::CRC.crc, HEX);
Serial.print (F("/"));
Serial.println (EEPROMSettings.crc (), HEX);
Serial.print(::CRC.crc, HEX);
Serial.print(F("/"));
Serial.println(EEPROMSettings.crc(), HEX);
break;
}
return true;
}
bool eeprom (const char *command) {
bool eeprom(const char *command) {
enum {
CONTENTS,
FREE,
} subCommand;
if (strcmp_P (command, PSTR ("eeprom.contents")) == 0)
if (strcmp_P(command, PSTR("eeprom.contents")) == 0)
subCommand = CONTENTS;
else if (strcmp_P (command, PSTR ("eeprom.free")) == 0)
else if (strcmp_P(command, PSTR("eeprom.free")) == 0)
subCommand = FREE;
else
return false;
switch (subCommand) {
case CONTENTS: {
if (Serial.peek () == '\n') {
for (uint16_t i = 0; i < EEPROM.length (); i++) {
if (Serial.peek() == '\n') {
for (uint16_t i = 0; i < EEPROM.length(); i++) {
uint8_t d = EEPROM[i];
Focus.printNumber (d);
Focus.printSpace ();
Focus.printNumber(d);
Focus.printSpace();
}
Serial.println ();
Serial.println();
} else {
for (uint16_t i = 0; i < EEPROM.length () && Serial.peek () != '\n'; i++) {
uint8_t d = Serial.parseInt ();
EEPROM.update (i, d);
for (uint16_t i = 0; i < EEPROM.length() && Serial.peek() != '\n'; i++) {
uint8_t d = Serial.parseInt();
EEPROM.update(i, d);
}
}
break;
}
case FREE:
Serial.println (EEPROM.length () - EEPROMSettings.used ());
Serial.println(EEPROM.length() - EEPROMSettings.used());
break;
}

@ -21,8 +21,8 @@
#include <Kaleidoscope.h>
namespace FocusHooks {
bool settings (const char *command);
bool eeprom (const char *command);
bool settings(const char *command);
bool eeprom(const char *command);
};
#define FOCUS_HOOK_SETTINGS FOCUS_HOOK(FocusHooks::settings, \

@ -23,33 +23,33 @@ namespace KaleidoscopePlugins {
struct EEPROMSettings::settings EEPROMSettings::settings;
bool EEPROMSettings::_isValid;
bool EEPROMSettings::sealed;
uint16_t EEPROMSettings::nextStart = sizeof (EEPROMSettings::settings);
uint16_t EEPROMSettings::nextStart = sizeof(EEPROMSettings::settings);
EEPROMSettings::EEPROMSettings (void) {
EEPROMSettings::EEPROMSettings(void) {
}
void
EEPROMSettings::begin (void) {
EEPROM.get (0, settings);
EEPROMSettings::begin(void) {
EEPROM.get(0, settings);
}
bool
EEPROMSettings::isValid (void) {
EEPROMSettings::isValid(void) {
return _isValid;
}
uint16_t
EEPROMSettings::crc (void) {
EEPROMSettings::crc(void) {
if (sealed)
return settings.crc;
return 0;
}
void
EEPROMSettings::seal (void) {
EEPROMSettings::seal(void) {
sealed = true;
CRC.finalize ();
CRC.finalize();
if (settings.magic[0] != 'K' || settings.magic[1] != 'S') {
settings.magic[0] = 'K';
@ -57,7 +57,7 @@ EEPROMSettings::seal (void) {
settings.version = 0;
settings.crc = CRC.crc;
return update ();
return update();
}
if (settings.crc != CRC.crc)
@ -65,45 +65,45 @@ EEPROMSettings::seal (void) {
}
uint16_t
EEPROMSettings::requestSlice (uint16_t size) {
EEPROMSettings::requestSlice(uint16_t size) {
if (sealed)
return 0;
uint16_t start = nextStart;
nextStart += size;
CRC.update ((const void *)&size, sizeof (size));
CRC.update((const void *)&size, sizeof(size));
return start;
}
void
EEPROMSettings::invalidate (void) {
EEPROMSettings::invalidate(void) {
_isValid = false;
}
uint16_t
EEPROMSettings::used (void) {
EEPROMSettings::used(void) {
return nextStart;
}
void
EEPROMSettings::update (void) {
EEPROMSettings::update(void) {
settings.crc = CRC.crc;
EEPROM.put (0, settings);
EEPROM.put(0, settings);
_isValid = true;
}
uint8_t
EEPROMSettings::version (void) {
EEPROMSettings::version(void) {
return settings.version;
}
void
EEPROMSettings::version (uint8_t ver) {
EEPROMSettings::version(uint8_t ver) {
settings.version = ver;
update ();
update();
}
};

@ -24,20 +24,20 @@
namespace KaleidoscopePlugins {
class EEPROMSettings : public KaleidoscopePlugin {
public:
EEPROMSettings (void);
EEPROMSettings(void);
virtual void begin (void) final;
virtual void begin(void) final;
static void update (void);
static bool isValid (void);
static void invalidate (void);
static uint8_t version (void);
static void version (uint8_t ver);
static void update(void);
static bool isValid(void);
static void invalidate(void);
static uint8_t version(void);
static void version(uint8_t ver);
static uint16_t requestSlice (uint16_t size);
static void seal (void);
static uint16_t crc (void);
static uint16_t used (void);
static uint16_t requestSlice(uint16_t size);
static void seal(void);
static uint16_t crc(void);
static uint16_t used(void);
private:
static uint16_t nextStart;

@ -30,7 +30,7 @@
#include "crc.h"
void
CRC_::reflect (uint8_t len) {
CRC_::reflect(uint8_t len) {
uint8_t i;
uint16_t newCRC;
@ -44,7 +44,7 @@ CRC_::reflect (uint8_t len) {
}
void
CRC_::update (const void *data, uint8_t len) {
CRC_::update(const void *data, uint8_t len) {
const uint8_t *d = (const uint8_t *)data;
uint8_t i;
bool bit;

@ -35,13 +35,13 @@ class CRC_ {
public:
uint16_t crc = 0;
CRC_ (void) {};
CRC_(void) {};
void update (const void *data, uint8_t len);
void finalize (void) {
reflect (16);
void update(const void *data, uint8_t len);
void finalize(void) {
reflect(16);
};
void reflect (uint8_t len);
void reflect(uint8_t len);
};
extern CRC_ CRC;

Loading…
Cancel
Save