From 4bc0eb5d11306ffa96f0cbdee2decdd541ae47d8 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Mon, 15 Oct 2018 23:33:15 +0200 Subject: [PATCH] Further source-code rearrangement Merged `EEPROM-Settings-Focus` into `EEPROM-Settings` itself: there's no reason they should be separate. Also moved the CRC headers to `kaleidoscope/plugin/EEPROM-Settings/` to not pollute the plugin namespace. Signed-off-by: Gergely Nagy --- src/Kaleidoscope-EEPROM-Settings.h | 1 - .../plugin/EEPROM-Settings-Focus.cpp | 124 ------------------ .../plugin/EEPROM-Settings-Focus.h | 44 ------- src/kaleidoscope/plugin/EEPROM-Settings.cpp | 99 +++++++++++++- src/kaleidoscope/plugin/EEPROM-Settings.h | 16 +++ .../plugin/{ => EEPROM-Settings}/crc.cpp | 0 .../plugin/{ => EEPROM-Settings}/crc.h | 0 7 files changed, 114 insertions(+), 170 deletions(-) delete mode 100644 src/kaleidoscope/plugin/EEPROM-Settings-Focus.cpp delete mode 100644 src/kaleidoscope/plugin/EEPROM-Settings-Focus.h rename src/kaleidoscope/plugin/{ => EEPROM-Settings}/crc.cpp (100%) rename src/kaleidoscope/plugin/{ => EEPROM-Settings}/crc.h (100%) diff --git a/src/Kaleidoscope-EEPROM-Settings.h b/src/Kaleidoscope-EEPROM-Settings.h index a36d235e..ed93eec9 100644 --- a/src/Kaleidoscope-EEPROM-Settings.h +++ b/src/Kaleidoscope-EEPROM-Settings.h @@ -18,4 +18,3 @@ #pragma once #include -#include diff --git a/src/kaleidoscope/plugin/EEPROM-Settings-Focus.cpp b/src/kaleidoscope/plugin/EEPROM-Settings-Focus.cpp deleted file mode 100644 index 1f669f3b..00000000 --- a/src/kaleidoscope/plugin/EEPROM-Settings-Focus.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* -*- mode: c++ -*- - * Kaleidoscope-EEPROM-Settings -- Basic EEPROM settings plugin for Kaleidoscope. - * Copyright (C) 2017-2018 Keyboard.io, Inc - * - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -#include -#include -#include "crc.h" - -namespace kaleidoscope { -namespace plugin { -namespace eeprom { - -EventHandlerResult FocusSettingsCommand::onFocusEvent(const char *command) { - enum { - DEFAULT_LAYER, - IS_VALID, - GET_VERSION, - CRC, - } sub_command; - - if (::Focus.handleHelp(command, PSTR("settings.defaultLayer\nsettings.valid?\nsettings.version\nsettings.crc"))) - return EventHandlerResult::OK; - - if (strncmp_P(command, PSTR("settings."), 9) != 0) - return EventHandlerResult::OK; - - if (strcmp_P(command + 9, PSTR("defaultLayer")) == 0) - sub_command = DEFAULT_LAYER; - else if (strcmp_P(command + 9, PSTR("valid?")) == 0) - sub_command = IS_VALID; - else if (strcmp_P(command + 9, PSTR("version")) == 0) - sub_command = GET_VERSION; - else if (strcmp_P(command + 9, PSTR("crc")) == 0) - sub_command = CRC; - else - return EventHandlerResult::OK; - - switch (sub_command) { - case DEFAULT_LAYER: { - if (Serial.peek() == '\n') { - Serial.println(::EEPROMSettings.default_layer()); - } else { - ::EEPROMSettings.default_layer(Serial.parseInt()); - } - break; - } - case IS_VALID: - ::Focus.printBool(::EEPROMSettings.isValid()); - Serial.println(); - break; - case GET_VERSION: - Serial.println(::EEPROMSettings.version()); - break; - case CRC: - Serial.print(::CRC.crc, HEX); - Serial.print(F("/")); - Serial.println(::EEPROMSettings.crc(), HEX); - break; - } - - return EventHandlerResult::EVENT_CONSUMED; -} - -EventHandlerResult FocusEEPROMCommand::onFocusEvent(const char *command) { - enum { - CONTENTS, - FREE, - } sub_command; - - if (::Focus.handleHelp(command, PSTR("eeprom.contents\neeprom.free"))) - return EventHandlerResult::OK; - - if (strcmp_P(command, PSTR("eeprom.contents")) == 0) - sub_command = CONTENTS; - else if (strcmp_P(command, PSTR("eeprom.free")) == 0) - sub_command = FREE; - else - return EventHandlerResult::OK; - - switch (sub_command) { - 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); - } - } - - break; - } - case FREE: - Serial.println(EEPROM.length() - ::EEPROMSettings.used()); - break; - } - - return EventHandlerResult::EVENT_CONSUMED; -} - -} -} -} - -kaleidoscope::plugin::eeprom::FocusSettingsCommand FocusSettingsCommand; -kaleidoscope::plugin::eeprom::FocusEEPROMCommand FocusEEPROMCommand; diff --git a/src/kaleidoscope/plugin/EEPROM-Settings-Focus.h b/src/kaleidoscope/plugin/EEPROM-Settings-Focus.h deleted file mode 100644 index 469e8db2..00000000 --- a/src/kaleidoscope/plugin/EEPROM-Settings-Focus.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -*- mode: c++ -*- - * Kaleidoscope-EEPROM-Settings -- Basic EEPROM settings plugin for Kaleidoscope. - * Copyright (C) 2017, 2018 Keyboard.io, Inc - * - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -#pragma once - -#include - -namespace kaleidoscope { -namespace plugin { -namespace eeprom { -class FocusSettingsCommand : public kaleidoscope::Plugin { - public: - FocusSettingsCommand() {} - - EventHandlerResult onFocusEvent(const char *command); -}; - -class FocusEEPROMCommand : public kaleidoscope::Plugin { - public: - FocusEEPROMCommand() {} - - EventHandlerResult onFocusEvent(const char *command); -}; - -} -} -} - -extern kaleidoscope::plugin::eeprom::FocusSettingsCommand FocusSettingsCommand; -extern kaleidoscope::plugin::eeprom::FocusEEPROMCommand FocusEEPROMCommand; diff --git a/src/kaleidoscope/plugin/EEPROM-Settings.cpp b/src/kaleidoscope/plugin/EEPROM-Settings.cpp index 76058754..9e0e4d72 100644 --- a/src/kaleidoscope/plugin/EEPROM-Settings.cpp +++ b/src/kaleidoscope/plugin/EEPROM-Settings.cpp @@ -16,7 +16,8 @@ */ #include -#include "crc.h" +#include +#include "kaleidoscope/plugin/EEPROM-Settings/crc.h" namespace kaleidoscope { namespace plugin { @@ -114,7 +115,103 @@ void EEPROMSettings::version(uint8_t ver) { update(); } +/** Focus **/ +EventHandlerResult FocusSettingsCommand::onFocusEvent(const char *command) { + enum { + DEFAULT_LAYER, + IS_VALID, + GET_VERSION, + CRC, + } sub_command; + + if (::Focus.handleHelp(command, PSTR("settings.defaultLayer\nsettings.valid?\nsettings.version\nsettings.crc"))) + return EventHandlerResult::OK; + + if (strncmp_P(command, PSTR("settings."), 9) != 0) + return EventHandlerResult::OK; + + if (strcmp_P(command + 9, PSTR("defaultLayer")) == 0) + sub_command = DEFAULT_LAYER; + else if (strcmp_P(command + 9, PSTR("valid?")) == 0) + sub_command = IS_VALID; + else if (strcmp_P(command + 9, PSTR("version")) == 0) + sub_command = GET_VERSION; + else if (strcmp_P(command + 9, PSTR("crc")) == 0) + sub_command = CRC; + else + return EventHandlerResult::OK; + + switch (sub_command) { + case DEFAULT_LAYER: { + if (Serial.peek() == '\n') { + Serial.println(::EEPROMSettings.default_layer()); + } else { + ::EEPROMSettings.default_layer(Serial.parseInt()); + } + break; + } + case IS_VALID: + ::Focus.printBool(::EEPROMSettings.isValid()); + Serial.println(); + break; + case GET_VERSION: + Serial.println(::EEPROMSettings.version()); + break; + case CRC: + Serial.print(::CRC.crc, HEX); + Serial.print(F("/")); + Serial.println(::EEPROMSettings.crc(), HEX); + break; + } + + return EventHandlerResult::EVENT_CONSUMED; +} + +EventHandlerResult FocusEEPROMCommand::onFocusEvent(const char *command) { + enum { + CONTENTS, + FREE, + } sub_command; + + if (::Focus.handleHelp(command, PSTR("eeprom.contents\neeprom.free"))) + return EventHandlerResult::OK; + + if (strcmp_P(command, PSTR("eeprom.contents")) == 0) + sub_command = CONTENTS; + else if (strcmp_P(command, PSTR("eeprom.free")) == 0) + sub_command = FREE; + else + return EventHandlerResult::OK; + + switch (sub_command) { + 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); + } + } + + break; + } + case FREE: + Serial.println(EEPROM.length() - ::EEPROMSettings.used()); + break; + } + + return EventHandlerResult::EVENT_CONSUMED; +} + } } kaleidoscope::plugin::EEPROMSettings EEPROMSettings; +kaleidoscope::plugin::FocusSettingsCommand FocusSettingsCommand; +kaleidoscope::plugin::FocusEEPROMCommand FocusEEPROMCommand; diff --git a/src/kaleidoscope/plugin/EEPROM-Settings.h b/src/kaleidoscope/plugin/EEPROM-Settings.h index 0264ab3e..34c0bcda 100644 --- a/src/kaleidoscope/plugin/EEPROM-Settings.h +++ b/src/kaleidoscope/plugin/EEPROM-Settings.h @@ -53,7 +53,23 @@ class EEPROMSettings : public kaleidoscope::Plugin { uint16_t crc; } settings_; }; + +class FocusSettingsCommand : public kaleidoscope::Plugin { + public: + FocusSettingsCommand() {} + + EventHandlerResult onFocusEvent(const char *command); +}; + +class FocusEEPROMCommand : public kaleidoscope::Plugin { + public: + FocusEEPROMCommand() {} + + EventHandlerResult onFocusEvent(const char *command); +}; } } extern kaleidoscope::plugin::EEPROMSettings EEPROMSettings; +extern kaleidoscope::plugin::FocusSettingsCommand FocusSettingsCommand; +extern kaleidoscope::plugin::FocusEEPROMCommand FocusEEPROMCommand; diff --git a/src/kaleidoscope/plugin/crc.cpp b/src/kaleidoscope/plugin/EEPROM-Settings/crc.cpp similarity index 100% rename from src/kaleidoscope/plugin/crc.cpp rename to src/kaleidoscope/plugin/EEPROM-Settings/crc.cpp diff --git a/src/kaleidoscope/plugin/crc.h b/src/kaleidoscope/plugin/EEPROM-Settings/crc.h similarity index 100% rename from src/kaleidoscope/plugin/crc.h rename to src/kaleidoscope/plugin/EEPROM-Settings/crc.h