0

RGB LED Matrix - Clock
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

RGB LED Matrix - Clock

by bizzaro on Mon Apr 16, 2018 7:23 am

I have a 32x64 matrix and I want to run the clock example with the date on one line, the day of the week on the second, and the time on the third. I thought I could use %n in the time code to do this, but it just prints it as a character. Is there a way to do multiple lines?

I also want to change the defaults so I don’t have to type them every time:
—led-rows=32
—led-cols=64
—led-slowdown-gpio=2
What do I have to edit to accomplish this?

Edit: The code I’m referring to is here: https://github.com/hzeller/rpi-rgb-led-matrix

bizzaro
 
Posts: 2
Joined: Sun Feb 02, 2014 1:54 pm

Re: RGB LED Matrix - Clock

by ShelM on Mon Apr 16, 2018 10:40 pm

When you say "%n" is that really what you have? I suspect you mean "\n" as that is the code that causes a new line.

ShelM
 
Posts: 9
Joined: Sun Mar 11, 2018 1:45 am

Re: RGB LED Matrix - Clock

by bizzaro on Wed Apr 18, 2018 5:38 pm

ShelM wrote:When you say "%n" is that really what you have? I suspect you mean "\n" as that is the code that causes a new line.

At line 33 in https://github.com/hzeller/rpi-rgb-led- ... e/clock.cc for the time-format it says to look at strftime(). That's where I get %n stands for a new line. Upon further inspection of the code, it's not going to be that simple.

At line 152:
Code: Select all | TOGGLE FULL SIZE
char text_buffer[256];
  struct timespec next_time;
  next_time.tv_sec = time(NULL);
  next_time.tv_nsec = 0;
  struct tm tm;

  signal(SIGTERM, InterruptHandler);
  signal(SIGINT, InterruptHandler);

  while (!interrupt_received) {
      localtime_r(&next_time.tv_sec, &tm);
      strftime(text_buffer, sizeof(text_buffer), time_format, &tm);
      offscreen->Fill(bg_color.r, bg_color.g, bg_color.b);
      if (outline_font) {
          rgb_matrix::DrawText(offscreen, *outline_font,
                               x - 1, y + font.baseline(),
                               outline_color, NULL, text_buffer,
                               letter_spacing - 2);
      }
      rgb_matrix::DrawText(offscreen, font, x, y + font.baseline(),
                           color, NULL, text_buffer,
                           letter_spacing);

      // Wait until we're ready to show it.
      clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &next_time, NULL);

      // Atomic swap with double buffer
      offscreen = matrix->SwapOnVSync(offscreen);

      next_time.tv_sec += 1;
}


It looks like I'll have to modify this part to look for each instance of %n in the time-format, break that into separate strings, convert it with strftime(), and depending what line I want to write it to I'd have to change lines 167 and 171 to something like: ...y + n * font.baseline()... where n would be 1 for the first line, 2 for the second, etc.

Problem is I have zero experience with C++, so I'm not exactly sure how to do this.

bizzaro
 
Posts: 2
Joined: Sun Feb 02, 2014 1:54 pm

Please be positive and constructive with your questions and comments.