daniel1111 / BigClockSnake

Arduino library for Snake & bigclocks
BSD 3-Clause "New" or "Revised" License
1 stars 2 forks source link

update BigClock.h with easier 2D array addressing #2

Open alifeee opened 1 month ago

alifeee commented 1 month ago

I'm not fully sure why this is needed, as I adopted the library with the patch already applied.

I think it is something to do with making the screen addressable as a 2D array, rather than two arrays.

The new library is here: https://github.com/sheffieldhackspace/train-signs/blob/main/lib/BigClock/BigClock.cpp

The old library (in this repository) is here: https://github.com/daniel1111/BigClockSnake/blob/master/libraries/BigClock/BigClock.cpp

The diff is:

diff --git a/clockold.txt b/clocknew.txt
index 85abb61..aa05534 100644
--- a/clockold.txt
+++ b/clocknew.txt
@@ -123,6 +123,7 @@ void BigClock::flush_sbit()
   }
 }

+#define FB_SEQUENTIAL

 bool BigClock::get_bit(byte *fb, int x, int y)
 /* x = 0-95
@@ -134,8 +135,12 @@ bool BigClock::get_bit(byte *fb, int x, int y)
     x = 95 - x;  
     y = 12 - y;
   }
-  
+#ifdef FB_SEQUENTIAL
+  y = 25 - y;
+  return *(fb+(y*MAX_X)+(x/8)) >> (7-(x%8)) & 1;
+#else
   return fb[((x/8)*MAX_Y) + y]  & (1 << (x%8));
+#endif
 }

 void BigClock::output_segment(int board, byte *framebuf, bool odd_lines, int segment, int row_start, bool tst) // output 6x13 segment (0-7)
daniel1111 commented 3 weeks ago

heh not something I've touched in years, good to know there's still people out there playing with these displays :)

And thanks, not quite sure what's going on there, I assume it's to adapt it to a different graphics library? Can't hurt to have the option i guess

alifeee commented 3 weeks ago

I'm not fully sure. I think it is that

without FB_SEQUENTIAL, when you sent a pixel, it was not addressable as a rectangle in X and Y, but some strange shape (two rectangles, one per half of the display?)

with FB_SEQUENTIAL, points are increasing from the top left pixel by 1 for each "real" pixel

not having tested it, I can't really say...

it would also just be enough for me to leave a link to https://github.com/sheffieldhackspace/train-signs/blob/main/lib/BigClock/BigClock.cpp here in this issue, and leave the issue open, for anyone to discover in future.