From d39ae30d05c9c614d524c4fcd9f1b1b0447074cb Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Tue, 14 Mar 2023 08:52:40 -0700 Subject: [PATCH] refactored files (#663) --- src/NeoPixelBus.h | 13 +- src/internal/Layouts.h | 426 ------------------ src/internal/NeoTopologies.h | 39 ++ .../topologies/ColumnMajorAlternatingLayout.h | 144 ++++++ src/internal/topologies/ColumnMajorLayout.h | 104 +++++ src/internal/{ => topologies}/NeoMosaic.h | 11 +- .../{ => topologies}/NeoRingTopology.h | 22 +- src/internal/{ => topologies}/NeoTiles.h | 9 +- src/internal/{ => topologies}/NeoTopology.h | 11 +- .../topologies/RowMajorAlternatingLayout.h | 144 ++++++ src/internal/topologies/RowMajorLayout.h | 103 +++++ 11 files changed, 582 insertions(+), 444 deletions(-) delete mode 100644 src/internal/Layouts.h create mode 100644 src/internal/NeoTopologies.h create mode 100644 src/internal/topologies/ColumnMajorAlternatingLayout.h create mode 100644 src/internal/topologies/ColumnMajorLayout.h rename src/internal/{ => topologies}/NeoMosaic.h (95%) rename src/internal/{ => topologies}/NeoRingTopology.h (84%) rename src/internal/{ => topologies}/NeoTiles.h (96%) rename src/internal/{ => topologies}/NeoTopology.h (92%) create mode 100644 src/internal/topologies/RowMajorAlternatingLayout.h create mode 100644 src/internal/topologies/RowMajorLayout.h diff --git a/src/NeoPixelBus.h b/src/NeoPixelBus.h index 9eb964c..c13c053 100644 --- a/src/NeoPixelBus.h +++ b/src/NeoPixelBus.h @@ -27,20 +27,17 @@ License along with NeoPixel. If not, see #include -// '_state' flags for internal state -#define NEO_DIRTY 0x80 // a change was made to pixel data that requires a show +// standard neo definitions +// +const uint8_t NEO_DIRTY = 0x80; // a change was made to pixel data that requires a show +const uint16_t PixelIndex_OutOfBounds = 0xffff; #include "internal/NeoUtil.h" #include "internal/NeoEase.h" #include "internal/NeoSettings.h" #include "internal/NeoColors.h" #include "internal/NeoColorFeatures.h" - -#include "internal/Layouts.h" -#include "internal/NeoTopology.h" -#include "internal/NeoRingTopology.h" -#include "internal/NeoTiles.h" -#include "internal/NeoMosaic.h" +#include "internal/NeoTopologies.h" #include "internal/NeoBufferContext.h" #include "internal/NeoBufferMethods.h" diff --git a/src/internal/Layouts.h b/src/internal/Layouts.h deleted file mode 100644 index 5b1016e..0000000 --- a/src/internal/Layouts.h +++ /dev/null @@ -1,426 +0,0 @@ -#pragma once -/*------------------------------------------------------------------------- -Layout provides a collection of class objects that are used with NeoTopology -object. -They define the specific layout of pixels and do the math to change the 2d -cordinate space to 1d cordinate space - -Written by Michael C. Miller. - -I invest time and resources providing this open source code, -please support me by dontating (see https://github.com/Makuna/NeoPixelBus) - -------------------------------------------------------------------------- -This file is part of the Makuna/NeoPixelBus library. - -NeoPixelBus is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as -published by the Free Software Foundation, either version 3 of -the License, or (at your option) any later version. - -NeoPixelBus 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 Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with NeoPixel. If not, see -. --------------------------------------------------------------------------*/ - -const uint16_t PixelIndex_OutOfBounds = 0xffff; - -//----------------------------------------------------------------------------- -// RowMajor -//----------------------------------------------------------------------------- - -class RowMajorLayout; -class RowMajor90Layout; -class RowMajor180Layout; -class RowMajor270Layout; - -class RowMajorTilePreference -{ -public: - typedef RowMajorLayout EvenRowEvenColumnLayout; - typedef RowMajor270Layout EvenRowOddColumnLayout; - typedef RowMajor90Layout OddRowEvenColumnLayout; - typedef RowMajor180Layout OddRowOddColumnLayout; -}; - -// layout example of 4x4 -// 00 01 02 03 -// 04 05 06 07 -// 08 09 10 11 -// 12 13 14 15 -// -class RowMajorLayout : public RowMajorTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) - { - return x + y * width; - } -}; - -// layout example of 4x4 -// 12 08 04 00 -// 13 09 05 01 -// 14 10 06 02 -// 15 11 07 03 -// -class RowMajor90Layout : public RowMajorTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - return (width - 1 - x) * height + y; - } -}; - -// layout example of 4x4 -// 15 14 13 12 -// 11 10 09 08 -// 07 06 05 04 -// 03 02 01 00 -// -class RowMajor180Layout : public RowMajorTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - return (width - 1 - x) + (height - 1 - y) * width; - } -}; - -// layout example of 4x4 -// 03 07 11 15 -// 02 06 10 14 -// 01 05 09 13 -// 00 04 08 12 -// -class RowMajor270Layout : public RowMajorTilePreference -{ -public: - static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) - { - return x * height + (height - 1 - y); - } -}; - - -//----------------------------------------------------------------------------- -// ColumnMajor -//----------------------------------------------------------------------------- - -class ColumnMajorLayout; -class ColumnMajor90Layout; -class ColumnMajor180Layout; -class ColumnMajor270Layout; - -class ColumnMajorTilePreference -{ -public: - typedef ColumnMajorLayout EvenRowEvenColumnLayout; - typedef ColumnMajor270Layout EvenRowOddColumnLayout; - typedef ColumnMajor90Layout OddRowEvenColumnLayout; - typedef ColumnMajor180Layout OddRowOddColumnLayout; -}; - -// layout example of 4x4 -// 00 04 08 12 -// 01 05 09 13 -// 02 06 10 14 -// 03 07 11 15 -// -class ColumnMajorLayout : public ColumnMajorTilePreference -{ -public: - static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) - { - return x * height + y; - } -}; - -// layout example of 4x4 -// 03 02 01 00 -// 07 06 05 04 -// 11 10 09 08 -// 15 14 13 12 -// -class ColumnMajor90Layout : public ColumnMajorTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) - { - return (width - 1 - x) + y * width; - } -}; - -// layout example of 4x4 -// 15 11 07 03 -// 14 10 06 02 -// 13 09 05 01 -// 12 08 04 00 -// -class ColumnMajor180Layout : public ColumnMajorTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - return (width - 1 - x) * height + (height - 1 - y); - } -}; - -// layout example of 4x4 -// 12 13 14 15 -// 08 09 10 11 -// 04 05 06 07 -// 00 01 02 03 -// -class ColumnMajor270Layout : public ColumnMajorTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - return x + (height - 1 - y) * width; - } -}; - - -//----------------------------------------------------------------------------- -// RowMajorAlternating -//----------------------------------------------------------------------------- - -class RowMajorAlternating270Layout; -class RowMajorAlternating90Layout; - -class RowMajorAlternatingTilePreference -{ -public: - typedef RowMajorAlternating270Layout EvenRowEvenColumnLayout; - typedef RowMajorAlternating270Layout EvenRowOddColumnLayout; - typedef RowMajorAlternating90Layout OddRowEvenColumnLayout; - typedef RowMajorAlternating90Layout OddRowOddColumnLayout; -}; - -// layout example of 4x4 -// 00 01 02 03 -// 07 06 05 04 -// 08 09 10 11 -// 15 14 13 12 -// -class RowMajorAlternatingLayout : public RowMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) - { - uint16_t index = y * width; - - if (y & 0x0001) - { - index += ((width - 1) - x); - } - else - { - index += x; - } - return index; - } -}; - -// layout example of 4x4 -// 15 08 07 00 -// 14 09 06 01 -// 13 10 05 02 -// 12 11 04 03 -// -class RowMajorAlternating90Layout : public RowMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - uint16_t mx = ((width - 1) - x); - uint16_t index = mx * height; - - if (mx & 0x0001) - { - index += ((height - 1) - y); - } - else - { - index += y; - } - return index; - } -}; - -// layout example of 4x4 -// 12 13 14 15 -// 11 10 09 08 -// 04 05 06 07 -// 03 02 01 00 -// -class RowMajorAlternating180Layout : public RowMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - uint16_t my = ((height - 1) - y); - uint16_t index = my * width; - - if (my & 0x0001) - { - index += x; - } - else - { - index += ((width - 1) - x); - } - return index; - } -}; - -// layout example of 4x4 -// 03 04 11 12 -// 02 05 10 13 -// 01 06 09 14 -// 00 07 08 15 -// -class RowMajorAlternating270Layout : public RowMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) - { - uint16_t index = x * height; - - if (x & 0x0001) - { - index += y; - } - else - { - index += ((height - 1) - y); - } - return index; - } -}; - - -//----------------------------------------------------------------------------- -// ColumnMajorAlternating -//----------------------------------------------------------------------------- - -class ColumnMajorAlternatingLayout; -class ColumnMajorAlternating180Layout; - -class ColumnMajorAlternatingTilePreference -{ -public: - typedef ColumnMajorAlternatingLayout EvenRowEvenColumnLayout; - typedef ColumnMajorAlternatingLayout EvenRowOddColumnLayout; - typedef ColumnMajorAlternating180Layout OddRowEvenColumnLayout; - typedef ColumnMajorAlternating180Layout OddRowOddColumnLayout; -}; - -// layout example of 4x4 -// 00 07 08 15 -// 01 06 09 14 -// 02 05 10 13 -// 03 04 11 12 -// -class ColumnMajorAlternatingLayout : public ColumnMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) - { - uint16_t index = x * height; - - if (x & 0x0001) - { - index += ((height - 1) - y); - } - else - { - index += y; - } - return index; - } -}; - -// layout example of 4x4 -// 03 02 01 00 -// 04 05 06 07 -// 11 10 09 08 -// 12 13 14 15 -// -class ColumnMajorAlternating90Layout : public ColumnMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) - { - uint16_t index = y * width; - - if (y & 0x0001) - { - index += x; - } - else - { - index += ((width - 1) - x); - } - return index; - } -}; - -// layout example of 4x4 -// 12 11 04 03 -// 13 10 05 02 -// 14 09 06 01 -// 15 08 07 00 -// -class ColumnMajorAlternating180Layout : public ColumnMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - uint16_t mx = ((width - 1) - x); - uint16_t index = mx * height; - - if (mx & 0x0001) - { - index += y; - } - else - { - index += ((height - 1) - y); - } - return index; - } -}; - -// layout example of 4x4 -// 15 14 13 12 -// 08 09 10 11 -// 07 06 05 04 -// 00 01 02 03 -// -class ColumnMajorAlternating270Layout : public ColumnMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - uint16_t my = ((height - 1) - y); - uint16_t index = my * width; - - if (my & 0x0001) - { - index += ((width - 1) - x); - } - else - { - index += x; - } - return index; - } -}; diff --git a/src/internal/NeoTopologies.h b/src/internal/NeoTopologies.h new file mode 100644 index 0000000..ce41f3e --- /dev/null +++ b/src/internal/NeoTopologies.h @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- +NeoTopologies includes all the classes that describe pixel cordinate mapping +from 2d spaces to 1d strips that NeoPixelBus uses. + +Written by Michael C. Miller. + +I invest time and resources providing this open source code, +please support me by dontating (see https://github.com/Makuna/NeoPixelBus) + +------------------------------------------------------------------------- +This file is part of the Makuna/NeoPixelBus library. + +NeoPixelBus is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +NeoPixelBus 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with NeoPixel. If not, see +. +-------------------------------------------------------------------------*/ +#pragma once + +#include "topologies/ColumnMajorAlternatingLayout.h" +#include "topologies/ColumnMajorLayout.h" +#include "topologies/RowMajorAlternatingLayout.h" +#include "topologies/RowMajorLayout.h" + +#include "topologies/NeoTopology.h" +#include "topologies/NeoRingTopology.h" +#include "topologies/NeoTiles.h" +#include "topologies/NeoMosaic.h" + + diff --git a/src/internal/topologies/ColumnMajorAlternatingLayout.h b/src/internal/topologies/ColumnMajorAlternatingLayout.h new file mode 100644 index 0000000..ef2da56 --- /dev/null +++ b/src/internal/topologies/ColumnMajorAlternatingLayout.h @@ -0,0 +1,144 @@ +/*------------------------------------------------------------------------- +ColumnMajorAlternatingLayout provides a collection of class objects that are used with NeoTopology +object. +They define the specific layout of pixels and do the math to change the 2d +cordinate space to 1d cordinate space + +Written by Michael C. Miller. + +I invest time and resources providing this open source code, +please support me by dontating (see https://github.com/Makuna/NeoPixelBus) + +------------------------------------------------------------------------- +This file is part of the Makuna/NeoPixelBus library. + +NeoPixelBus is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +NeoPixelBus 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with NeoPixel. If not, see +. +-------------------------------------------------------------------------*/ +#pragma once + + +class ColumnMajorAlternatingLayout; +class ColumnMajorAlternating180Layout; + +class ColumnMajorAlternatingTilePreference +{ +public: + typedef ColumnMajorAlternatingLayout EvenRowEvenColumnLayout; + typedef ColumnMajorAlternatingLayout EvenRowOddColumnLayout; + typedef ColumnMajorAlternating180Layout OddRowEvenColumnLayout; + typedef ColumnMajorAlternating180Layout OddRowOddColumnLayout; +}; + +// layout example of 4x4 +// 00 07 08 15 +// 01 06 09 14 +// 02 05 10 13 +// 03 04 11 12 +// +class ColumnMajorAlternatingLayout : public ColumnMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) + { + uint16_t index = x * height; + + if (x & 0x0001) + { + index += ((height - 1) - y); + } + else + { + index += y; + } + return index; + } +}; + +// layout example of 4x4 +// 03 02 01 00 +// 04 05 06 07 +// 11 10 09 08 +// 12 13 14 15 +// +class ColumnMajorAlternating90Layout : public ColumnMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) + { + uint16_t index = y * width; + + if (y & 0x0001) + { + index += x; + } + else + { + index += ((width - 1) - x); + } + return index; + } +}; + +// layout example of 4x4 +// 12 11 04 03 +// 13 10 05 02 +// 14 09 06 01 +// 15 08 07 00 +// +class ColumnMajorAlternating180Layout : public ColumnMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + uint16_t mx = ((width - 1) - x); + uint16_t index = mx * height; + + if (mx & 0x0001) + { + index += y; + } + else + { + index += ((height - 1) - y); + } + return index; + } +}; + +// layout example of 4x4 +// 15 14 13 12 +// 08 09 10 11 +// 07 06 05 04 +// 00 01 02 03 +// +class ColumnMajorAlternating270Layout : public ColumnMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + uint16_t my = ((height - 1) - y); + uint16_t index = my * width; + + if (my & 0x0001) + { + index += ((width - 1) - x); + } + else + { + index += x; + } + return index; + } +}; diff --git a/src/internal/topologies/ColumnMajorLayout.h b/src/internal/topologies/ColumnMajorLayout.h new file mode 100644 index 0000000..242fd00 --- /dev/null +++ b/src/internal/topologies/ColumnMajorLayout.h @@ -0,0 +1,104 @@ +/*------------------------------------------------------------------------- +ColumnMajorLayout provides a collection of class objects that are used with NeoTopology +object. +They define the specific layout of pixels and do the math to change the 2d +cordinate space to 1d cordinate space + +Written by Michael C. Miller. + +I invest time and resources providing this open source code, +please support me by dontating (see https://github.com/Makuna/NeoPixelBus) + +------------------------------------------------------------------------- +This file is part of the Makuna/NeoPixelBus library. + +NeoPixelBus is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +NeoPixelBus 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with NeoPixel. If not, see +. +-------------------------------------------------------------------------*/ +#pragma once + + +class ColumnMajorLayout; +class ColumnMajor90Layout; +class ColumnMajor180Layout; +class ColumnMajor270Layout; + +class ColumnMajorTilePreference +{ +public: + typedef ColumnMajorLayout EvenRowEvenColumnLayout; + typedef ColumnMajor270Layout EvenRowOddColumnLayout; + typedef ColumnMajor90Layout OddRowEvenColumnLayout; + typedef ColumnMajor180Layout OddRowOddColumnLayout; +}; + +// layout example of 4x4 +// 00 04 08 12 +// 01 05 09 13 +// 02 06 10 14 +// 03 07 11 15 +// +class ColumnMajorLayout : public ColumnMajorTilePreference +{ +public: + static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) + { + return x * height + y; + } +}; + +// layout example of 4x4 +// 03 02 01 00 +// 07 06 05 04 +// 11 10 09 08 +// 15 14 13 12 +// +class ColumnMajor90Layout : public ColumnMajorTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) + { + return (width - 1 - x) + y * width; + } +}; + +// layout example of 4x4 +// 15 11 07 03 +// 14 10 06 02 +// 13 09 05 01 +// 12 08 04 00 +// +class ColumnMajor180Layout : public ColumnMajorTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + return (width - 1 - x) * height + (height - 1 - y); + } +}; + +// layout example of 4x4 +// 12 13 14 15 +// 08 09 10 11 +// 04 05 06 07 +// 00 01 02 03 +// +class ColumnMajor270Layout : public ColumnMajorTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + return x + (height - 1 - y) * width; + } +}; diff --git a/src/internal/NeoMosaic.h b/src/internal/topologies/NeoMosaic.h similarity index 95% rename from src/internal/NeoMosaic.h rename to src/internal/topologies/NeoMosaic.h index 08c82f1..c42ba0d 100644 --- a/src/internal/NeoMosaic.h +++ b/src/internal/topologies/NeoMosaic.h @@ -1,7 +1,5 @@ -#pragma once - /*------------------------------------------------------------------------- -Mosiac provides a mapping feature of a 2d cordinate to linear 1d cordinate +NeoMosaic provides a mapping feature of a 2d cordinate to linear 1d cordinate It is used to map tiles of matricies of NeoPixels to a index on the NeoPixelBus where the the matricies use a set of prefered topology and the tiles of those matricies use the RowMajorAlternating layout @@ -28,6 +26,7 @@ You should have received a copy of the GNU Lesser General Public License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ +#pragma once //----------------------------------------------------------------------------- @@ -36,6 +35,12 @@ License along with NeoPixel. If not, see // the tiles by using different rotations of the layout at specific locations // // T_LAYOUT = the layout used for matrix panel (rotation is ignored) +// One of the following classes and their rotated variants +// RowMajorLayout +// ColumnMajorLayout +// RowMajorAlternatingLayout +// ColumnMajorAlternatingLayout +// // // NOTE: The tiles in the mosaic are always laid out using RowMajorAlternating // diff --git a/src/internal/NeoRingTopology.h b/src/internal/topologies/NeoRingTopology.h similarity index 84% rename from src/internal/NeoRingTopology.h rename to src/internal/topologies/NeoRingTopology.h index 7255a97..970de02 100644 --- a/src/internal/NeoRingTopology.h +++ b/src/internal/topologies/NeoRingTopology.h @@ -1,5 +1,3 @@ -#pragma once - /*------------------------------------------------------------------------- NeoRingTopology provides a mapping feature of a 2d polar cordinate to a linear 1d cordinate. @@ -28,6 +26,26 @@ You should have received a copy of the GNU Lesser General Public License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ +#pragma once + +// NeoRingTopology - +// +// T_LAYOUT - a user provided class that contains the following members with +// the Rings[] initialized with the starting index of each ring and +// one extra entry for the total count (example below). +// Other methods and members can exist to intialize a dynamic layout as needed. +// +// class RingsLayout +// { +// protected: +// const uint16_t Rings[] = { 0, 1, 7, 19, 35, 59, PixelCount }; +// +// uint8_t _ringCount() const +// { +// return sizeof(Rings) / sizeof(Rings[0]); +// } +// }; +// template class NeoRingTopology : public T_LAYOUT { diff --git a/src/internal/NeoTiles.h b/src/internal/topologies/NeoTiles.h similarity index 96% rename from src/internal/NeoTiles.h rename to src/internal/topologies/NeoTiles.h index 896df1f..d614e4a 100644 --- a/src/internal/NeoTiles.h +++ b/src/internal/topologies/NeoTiles.h @@ -1,5 +1,3 @@ -#pragma once - /*------------------------------------------------------------------------- NeoTiles provides a mapping feature of a 2d cordinate to linear 1d cordinate It is used to map tiles of matricies of NeoPixels to a index on the NeoPixelBus @@ -28,13 +26,18 @@ You should have received a copy of the GNU Lesser General Public License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ +#pragma once //----------------------------------------------------------------------------- // class NeoTiles // Simple template Tile layout class // T_MATRIX_LAYOUT = the layout used on the pixel matrix panel (a tile) // T_TILE_LAYOUT = the layout used for the tiles. -// +// one of the following classes and their rotated variants +// RowMajorLayout +// ColumnMajorLayout +// RowMajorAlternatingLayout +// ColumnMajorAlternatingLayout //----------------------------------------------------------------------------- template class NeoTiles { diff --git a/src/internal/NeoTopology.h b/src/internal/topologies/NeoTopology.h similarity index 92% rename from src/internal/NeoTopology.h rename to src/internal/topologies/NeoTopology.h index 42cc289..0909764 100644 --- a/src/internal/NeoTopology.h +++ b/src/internal/topologies/NeoTopology.h @@ -1,5 +1,3 @@ -#pragma once - /*------------------------------------------------------------------------- NeoTopology provides a mapping feature of a 2d cordinate to linear 1d cordinate It is used to map a matrix of NeoPixels to a index on the NeoPixelBus @@ -26,6 +24,7 @@ You should have received a copy of the GNU Lesser General Public License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ +#pragma once enum NeoTopologyHint { @@ -35,6 +34,14 @@ enum NeoTopologyHint NeoTopologyHint_OutOfBounds }; +// NeoTopology - +// +// T_LAYOUT - the following classes and their rotated variants +// RowMajorLayout +// ColumnMajorLayout +// RowMajorAlternatingLayout +// ColumnMajorAlternatingLayout +// template class NeoTopology { public: diff --git a/src/internal/topologies/RowMajorAlternatingLayout.h b/src/internal/topologies/RowMajorAlternatingLayout.h new file mode 100644 index 0000000..09a23c7 --- /dev/null +++ b/src/internal/topologies/RowMajorAlternatingLayout.h @@ -0,0 +1,144 @@ +/*------------------------------------------------------------------------- +RowMajorAlternatingLayout provides a collection of class objects that are used with NeoTopology +object. +They define the specific layout of pixels and do the math to change the 2d +cordinate space to 1d cordinate space + +Written by Michael C. Miller. + +I invest time and resources providing this open source code, +please support me by dontating (see https://github.com/Makuna/NeoPixelBus) + +------------------------------------------------------------------------- +This file is part of the Makuna/NeoPixelBus library. + +NeoPixelBus is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +NeoPixelBus 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with NeoPixel. If not, see +. +-------------------------------------------------------------------------*/ +#pragma once + + +class RowMajorAlternating270Layout; +class RowMajorAlternating90Layout; + +class RowMajorAlternatingTilePreference +{ +public: + typedef RowMajorAlternating270Layout EvenRowEvenColumnLayout; + typedef RowMajorAlternating270Layout EvenRowOddColumnLayout; + typedef RowMajorAlternating90Layout OddRowEvenColumnLayout; + typedef RowMajorAlternating90Layout OddRowOddColumnLayout; +}; + +// layout example of 4x4 +// 00 01 02 03 +// 07 06 05 04 +// 08 09 10 11 +// 15 14 13 12 +// +class RowMajorAlternatingLayout : public RowMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) + { + uint16_t index = y * width; + + if (y & 0x0001) + { + index += ((width - 1) - x); + } + else + { + index += x; + } + return index; + } +}; + +// layout example of 4x4 +// 15 08 07 00 +// 14 09 06 01 +// 13 10 05 02 +// 12 11 04 03 +// +class RowMajorAlternating90Layout : public RowMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + uint16_t mx = ((width - 1) - x); + uint16_t index = mx * height; + + if (mx & 0x0001) + { + index += ((height - 1) - y); + } + else + { + index += y; + } + return index; + } +}; + +// layout example of 4x4 +// 12 13 14 15 +// 11 10 09 08 +// 04 05 06 07 +// 03 02 01 00 +// +class RowMajorAlternating180Layout : public RowMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + uint16_t my = ((height - 1) - y); + uint16_t index = my * width; + + if (my & 0x0001) + { + index += x; + } + else + { + index += ((width - 1) - x); + } + return index; + } +}; + +// layout example of 4x4 +// 03 04 11 12 +// 02 05 10 13 +// 01 06 09 14 +// 00 07 08 15 +// +class RowMajorAlternating270Layout : public RowMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) + { + uint16_t index = x * height; + + if (x & 0x0001) + { + index += y; + } + else + { + index += ((height - 1) - y); + } + return index; + } +}; diff --git a/src/internal/topologies/RowMajorLayout.h b/src/internal/topologies/RowMajorLayout.h new file mode 100644 index 0000000..90a6f65 --- /dev/null +++ b/src/internal/topologies/RowMajorLayout.h @@ -0,0 +1,103 @@ +/*------------------------------------------------------------------------- +RowMajorLayout provides a collection of class objects that are used with NeoTopology +object. +They define the specific layout of pixels and do the math to change the 2d +cordinate space to 1d cordinate space + +Written by Michael C. Miller. + +I invest time and resources providing this open source code, +please support me by dontating (see https://github.com/Makuna/NeoPixelBus) + +------------------------------------------------------------------------- +This file is part of the Makuna/NeoPixelBus library. + +NeoPixelBus is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +NeoPixelBus 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with NeoPixel. If not, see +. +-------------------------------------------------------------------------*/ +#pragma once + +class RowMajorLayout; +class RowMajor90Layout; +class RowMajor180Layout; +class RowMajor270Layout; + +class RowMajorTilePreference +{ +public: + typedef RowMajorLayout EvenRowEvenColumnLayout; + typedef RowMajor270Layout EvenRowOddColumnLayout; + typedef RowMajor90Layout OddRowEvenColumnLayout; + typedef RowMajor180Layout OddRowOddColumnLayout; +}; + +// layout example of 4x4 +// 00 01 02 03 +// 04 05 06 07 +// 08 09 10 11 +// 12 13 14 15 +// +class RowMajorLayout : public RowMajorTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) + { + return x + y * width; + } +}; + +// layout example of 4x4 +// 12 08 04 00 +// 13 09 05 01 +// 14 10 06 02 +// 15 11 07 03 +// +class RowMajor90Layout : public RowMajorTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + return (width - 1 - x) * height + y; + } +}; + +// layout example of 4x4 +// 15 14 13 12 +// 11 10 09 08 +// 07 06 05 04 +// 03 02 01 00 +// +class RowMajor180Layout : public RowMajorTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + return (width - 1 - x) + (height - 1 - y) * width; + } +}; + +// layout example of 4x4 +// 03 07 11 15 +// 02 06 10 14 +// 01 05 09 13 +// 00 04 08 12 +// +class RowMajor270Layout : public RowMajorTilePreference +{ +public: + static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) + { + return x * height + (height - 1 - y); + } +};