From acc33bfacb6686cb39fa7d04ee7b5d3333fc19d0 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Tue, 25 May 2021 12:23:29 +0200 Subject: [PATCH] Do not indent namespaces --- .clang-format | 2 +- src/modules/leds.h | 147 +++++++++++++++++---------------------------- 2 files changed, 55 insertions(+), 94 deletions(-) diff --git a/.clang-format b/.clang-format index a2d537b..65fa90c 100644 --- a/.clang-format +++ b/.clang-format @@ -84,7 +84,7 @@ KeepEmptyLinesAtTheStartOfBlocks: true MacroBlockBegin: '' MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 -NamespaceIndentation: Inner +NamespaceIndentation: None ObjCBinPackProtocolList: Auto ObjCBlockIndentWidth: 4 ObjCSpaceAfterProperty: true diff --git a/src/modules/leds.h b/src/modules/leds.h index d3168b4..057113e 100644 --- a/src/modules/leds.h +++ b/src/modules/leds.h @@ -8,112 +8,73 @@ /// A typical scenario in the past was visualization of error states. /// The combination of colors with blinking frequency had a specific meaning. /// -/// We'd like to drive each pair? separately, which includes: -/// - blinking (none/slow/fast) -/// - what shall blink (red/green/both-at-once/both-interlaced) -/// /// The physical connection is not important on this level (i.e. how and what shall be sent into the shift registers) namespace modules { namespace leds { - /// Mode of LED - /// blink0 and blink1 allow for interlaced blinking of LEDs (one is on and the other off) - enum Mode { - off, - on, - blink0, ///< start blinking at even periods - blink1 ///< start blinking at odd periods +/// Mode of LED +/// blink0 and blink1 allow for interlaced blinking of LEDs (one is on and the other off) +enum Mode { + off, + on, + blink0, ///< start blinking at even periods + blink1 ///< start blinking at odd periods +}; + +/// a single LED +class LED { +public: + constexpr inline LED() = default; + void SetMode(Mode mode); + + /// @returns true if the LED shines + bool Step(bool oddPeriod); + inline bool On() const { return state.on; } + +private: + struct State { + uint8_t on : 1; + uint8_t mode : 2; + constexpr inline State() + : on(0) + , mode(Mode::off) {} }; - /// a single LED - class LED { - public: - constexpr inline LED() = default; - void SetMode(Mode mode); + State state; +}; - /// @returns true if the LED shines - bool Step(bool oddPeriod); - inline bool On() const { return state.on; } +/// main LED API +class LEDs { +public: + constexpr inline LEDs() + : ms(0) {}; - private: - struct State { - uint8_t on : 1; - uint8_t mode : 2; - constexpr inline State() - : on(0) - , mode(Mode::off) {} - }; + /// step LED automaton + /// @returns statuses of LEDs - one bit per LED and 1 = on, 0 = off + uint16_t Step(uint8_t delta_ms); - State state; - }; + inline constexpr uint8_t LedPairsCount() const { return ledPairs; } - /// main LED API - class LEDs { - public: - constexpr inline LEDs() - : ms(0) {}; + inline void SetMode(uint8_t slot, bool red, Mode mode) { + SetMode(slot * 2 + red, mode); + } + inline void SetMode(uint8_t index, Mode mode) { + leds[index].SetMode(mode); + } - /// step LED automaton - /// @returns statuses of LEDs - one bit per LED and 1 = on, 0 = off - uint16_t Step(uint8_t delta_ms); + inline bool LedOn(uint8_t index) const { + return leds[index].On(); + } + inline bool LedOn(uint8_t slot, bool red) const { + return leds[slot * 2 + red].On(); + } - inline constexpr uint8_t LedPairsCount() const { return ledPairs; } - - inline void SetMode(uint8_t slot, bool red, Mode mode) { - SetMode(slot * 2 + red, mode); - } - inline void SetMode(uint8_t index, Mode mode) { - leds[index].SetMode(mode); - } - - inline bool LedOn(uint8_t index) const { - return leds[index].On(); - } - inline bool LedOn(uint8_t slot, bool red) const { - return leds[slot * 2 + red].On(); - } - - private: - constexpr static const uint8_t ledPairs = 5; - LED leds[ledPairs * 2]; - uint16_t ms; - }; - - //// asi nechame moznost jednu blikat rychle a druhou pomalu - - //// tohle ale nevyresi, ze jedna LED ma blikat a druha svitit - - //// problem je, ze zapnuti/vypnuti led je blink none ... mozna by to chtelo blink none-on a none-off - //// jaka bude mnozina rezimu? - //// green-off green-on green-blink-slow green-blink-fast - //// red-off + + + + - //// red-on + + + + - //// red-blink-slow + + 2 x - //// red-blink-fast + + x 2 - //// - //// rezim 2 muze mit jeste varianty - blink-sync, blink-interlaced, coz v podstate znamena rezimy: - //// blink-slow1, blink-slow2, blink-fast1, blink-fast2, pricemz nemaji smysl kombinace: - //// blink-slow + blink-fast - - //// revize - //// v aktualnim FW led jen blikaji jednou rychlosti - //// takze to spis udelam jako pole LED, pricemz cervene budou na sudych a zelene na lichych indexech - //// stav ledky bude: off, on, blink0 a blink1 - //// blink0 znamena zacni pocitat blikaci interval od sude periody - //// blink1 od liche - //// tim pujde zmodelovat jak sync tak async blikani - //// Dale je otazka, jestli chceme rychle a pomale blikani... asi ne, kdyz bude report na LCD tiskarny - - //// Dale castecne souvisejici - //// Start MMU by mel reportovat progress, pricemz aktualni stav je takovy, ze nabihaji LED a kazda neco znamena - //// Tiskarna by klidne mohla posilat Q a dostavat odpoved ve stylu "starting" a progress/state code - //// - //// Mozna taky budeme potrebovat nastavovat ruzne vnitrni promenne (treba use slots 1-3 namisto 0-4), takze operace SetVar a k tomu obracena GetVar - //// Dava mi smysl modifikovat protokol V jako getvar (zamerne ne G, aby to nekolidovalo s gcodes) a S jako setvar - //// cislo je index variable a odpovi se A_hodnota, cili accepted a hodnota odpovedi - - //void SetLEDs(uint8_t slot0, uint8_t slot1, uint8_t slot2, uint8_t slot3, uint8_t slot4); +private: + constexpr static const uint8_t ledPairs = 5; + LED leds[ledPairs * 2]; + uint16_t ms; +}; } // namespace LEDs } // namespace modules