我是3B +树莓派(树莓派os)模型的新手,我正在尝试使用hzller库
在led矩阵上显示在UART端口接收的文本。我在led矩阵上显示文本,但是我不知道如何将给定的示例代码与串行通信代码(wiringPi)集成在一起,但是会出现一些错误。 如何将两个代码合而为一。
我已经从rpi-rgb-led-matrix库编辑了text-example.cc代码,如下所示
// -*- mode: c++; c-basic-offset: 2; indent-tabs-mode:nil; -*-
// Small example how write text.
//
// This code is public domain
// (but note, that the led-matrix library this depends on is GPL v2)
#include "led-matrix.h"
#include "graphics.h"
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include <canvas.h>
using namespace rgb_matrix;
using rgb_matrix::GPIO;
using rgb_matrix::RGBMatrix;
using rgb_matrix::Canvas;
using rgb_matrix::GPIO;
using rgb_matrix::RGBMatrix;
using rgb_matrix::Canvas;
static void DrawOnCanvas(Canvas *canvas) {
/*
* Let's create a simple animation. We use the canvas to draw
* pixels. We wait between each step to have a slower animation.
*/
canvas->Fill(0, 0, 255);
int center_x = canvas->width() / 2;
int center_y = canvas->height() / 2;
float radius_max = canvas->width() / 2;
float angle_step = 1.0 / 360;
for (float a = 0, r = 0; r < radius_max; a += angle_step, r += angle_step)
{
float dot_x = cos(a * 2 * M_PI) * r;
float dot_y = sin(a * 2 * M_PI) * r;
//canvas->SetPixel(center_x + dot_x, center_y + dot_y,255, 45, 0);
usleep(1 * 100000); // wait a little to slow down things.
}
}
int main(int argc, char *argv[]) {
/*
* Set up GPIO pins. This fails when not running as root.
*/
GPIO io;
if (!io.Init())
return 1;
/*
* Set up the RGBMatrix. It implements a 'Canvas' interface.
*/
int rows = 32; // A 32x32 display. Use 16 when this is a 16x32 display.
int chain =20; // Number of boards chained together.
int parallel = 1; // Number of chains in parallel (1..3). > 1 for plus or
Pi2
Canvas *canvas = new RGBMatrix(&io, rows, chain, parallel);
//canvas->SetPixel(6, 0,255, 255, 45);
DrawOnCanvas(canvas); // Using the canvas.
// Animation finished. Shut down the RGB matrix.
// canvas->Clear();
delete canvas;
return 0;
}
connectionPi用于读取接收到的数据的示例代码如下
/*
UART communication on Raspberry Pi using C (WiringPi Library)
http://www.electronicwings.com
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <wiringPi.h>
#include <wiringSerial.h>
int main ()
{
int serial_port ;
char dat;
if ((serial_port = serialOpen ("/dev/ttyS0", 9600)) < 0) /* open serial
port */
{
fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
return 1 ;
}
if (wiringPiSetup () == -1) /* initializes wiringPi setup
*/
{
fprintf (stdout, "Unable to start wiringPi: %s\n", strerror (errno)) ;
return 1 ;
}
while(1){
if(serialDataAvail (serial_port) )
{
dat = serialGetchar (serial_port); /* receive character serially*/
printf ("%c", dat) ;
fflush (stdout) ;
serialPutchar(serial_port, dat); /* transmit character serially on
port */
}
}
}
有什么方法可以将这两个示例代码合而为一