From 940c4f37f36604eb6b9a82491143be88926d3461 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 16 Aug 2018 11:18:20 -0700 Subject: [PATCH] Ring Shift and Rotate (#220) --- keywords.txt | 2 ++ src/internal/NeoRingTopology.h | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/keywords.txt b/keywords.txt index 89144fd..33587b5 100644 --- a/keywords.txt +++ b/keywords.txt @@ -150,6 +150,8 @@ Map KEYWORD2 MapProbe KEYWORD2 getWidth KEYWORD2 getHeight KEYWORD2 +RingPixelShift KEYWORD2 +RingPixelRotate KEYWORD2 getCountOfRings KEYWORD2 getPixelCountAtRing KEYWORD2 getPixelCount KEYWORD2 diff --git a/src/internal/NeoRingTopology.h b/src/internal/NeoRingTopology.h index 8e152f8..e598fa4 100644 --- a/src/internal/NeoRingTopology.h +++ b/src/internal/NeoRingTopology.h @@ -56,6 +56,33 @@ public: return _map(ring, pixel); } + uint16_t RingPixelShift(uint8_t ring, uint16_t pixel, int16_t shift) + { + int32_t ringPixel = pixel; + ringPixel += shift; + + if (ringPixel < 0) + { + ringPixel = 0; + } + else + { + uint16_t count = getPixelCountAtRing(ring); + if (ringPixel >= count) + { + ringPixel = count - 1; + } + } + return ringPixel; + } + + uint16_t RingPixelRotate(uint8_t ring, uint16_t pixel, int16_t rotate) + { + int32_t ringPixel = pixel; + ringPixel += rotate; + return ringPixel % getPixelCountAtRing(ring); + } + uint8_t getCountOfRings() const { return _ringCount() - 1; // minus one as the Rings includes the extra value