make astyle

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

@ -20,41 +20,41 @@
#include <Kaleidoscope-EEPROM-Settings.h>
const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED
(
Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey,
Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab,
Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G,
Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
Key_skip,
Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip,
Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals,
Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_skip
),
[0] = KEYMAP_STACKED
(
Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey,
Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab,
Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G,
Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
Key_skip,
Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip,
Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals,
Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_skip
),
};
void setup () {
Serial.begin (9600);
Serial.begin (9600);
Kaleidoscope.setup ();
Kaleidoscope.setup ();
USE_PLUGINS (&EEPROMSettings);
USE_PLUGINS (&EEPROMSettings);
while (!Serial) {
}
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 ();
Kaleidoscope.loop ();
}

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

@ -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, \

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

@ -22,7 +22,7 @@
#include <EEPROM.h>
namespace KaleidoscopePlugins {
class EEPROMSettings : public KaleidoscopePlugin {
class EEPROMSettings : public KaleidoscopePlugin {
public:
EEPROMSettings (void);
@ -45,11 +45,11 @@ namespace KaleidoscopePlugins {
static bool sealed;
static struct settings {
char magic[2];
uint8_t version;
uint16_t crc;
char magic[2];
uint8_t version;
uint16_t crc;
} settings;
};
};
};
extern KaleidoscopePlugins::EEPROMSettings EEPROMSettings;

@ -31,41 +31,40 @@
void
CRC_::reflect (uint8_t len) {
uint8_t i;
uint16_t newCRC;
uint8_t i;
uint16_t newCRC;
newCRC = crc & 0x01;
for (i = 1; i < len; i++) {
crc >>= 1;
newCRC = (newCRC << 1) | (crc & 0x01);
}
newCRC = crc & 0x01;
for (i = 1; i < len; i++) {
crc >>= 1;
newCRC = (newCRC << 1) | (crc & 0x01);
}
crc = newCRC;
crc = newCRC;
}
void
CRC_::update (const void *data, uint8_t len)
{
const uint8_t *d = (const uint8_t *)data;
uint8_t i;
bool bit;
uint8_t c;
CRC_::update (const void *data, uint8_t len) {
const uint8_t *d = (const uint8_t *)data;
uint8_t i;
bool bit;
uint8_t c;
while (len--) {
c = *d++;
for (i = 0x01; i & 0xff; i <<= 1) {
bit = crc & 0x8000;
if (c & i) {
bit = !bit;
}
crc <<= 1;
if (bit) {
crc ^= 0x8005;
}
while (len--) {
c = *d++;
for (i = 0x01; i & 0xff; i <<= 1) {
bit = crc & 0x8000;
if (c & i) {
bit = !bit;
}
crc <<= 1;
if (bit) {
crc ^= 0x8005;
}
}
crc &= 0xffff;
}
crc &= 0xffff;
}
crc &= 0xffff;
}
CRC_ CRC;

@ -32,14 +32,16 @@
#include <Arduino.h>
class CRC_ {
public:
uint16_t crc = 0;
public:
uint16_t crc = 0;
CRC_ (void) {};
CRC_ (void) {};
void update (const void *data, uint8_t len);
void finalize (void) { reflect (16); };
void reflect (uint8_t len);
void update (const void *data, uint8_t len);
void finalize (void) {
reflect (16);
};
void reflect (uint8_t len);
};
extern CRC_ CRC;

Loading…
Cancel
Save