MajicDesigns / MD_MAX72XX

LED Matrix Library
GNU Lesser General Public License v2.1
307 stars 122 forks source link

transform with TFLR: in case of even number of devices we miss the swap on centered devices #36

Closed ABOSTM closed 3 years ago

ABOSTM commented 3 years ago

Subject of the issue

I have a setup with 4 devices. When applying TFLR transformation, both external devices are swapped (good), but both internal devices are not swapped. For example if I display "MAX!", after transformation I get "!AXM" instead of "!XAM"

Analysis

in file MD_MAX72xx_pix.cpp, in method MD_MAX72XX::transform()

    case TFLR: // Transform Flip Left to Right (use the whole field)
    // first reverse the device buffers end for end
    for (uint8_t buf = 0; buf < (endDev - startDev )/2; buf++)

The number of devices should be (endDev - startDev + 1) a nd not (endDev - startDev) ex: startDev=0 and endDev = 3, there are 4 devices. and (endDev - startDev +1) /2 = 2 swaps should be performed. Formula is still valid for odd number of devices.

Code Demonstrating the Issue

#include <MD_MAX72xx.h>

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES  4

#define CLK_PIN   13  // or SCK
#define DATA_PIN  11  // or MOSI
#define CS_PIN    10  // or SS

// SPI hardware interface
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

void setup()
{
  mx.begin();
  mx.clear();
}

void loop()
{
  mx.setChar(6, '!');
  mx.setChar(14, 'X');
  mx.setChar(22, 'A');
  mx.setChar(30, 'M');
    delay(2000);
  mx.transform(MD_MAX72XX::TFLR);

  delay(5000);
  mx.transform(MD_MAX72XX::TINV);
  delay(700);
  delay(10000);
}
MajicDesigns commented 3 years ago

Released as v3.2.4