Skip to content

Instantly share code, notes, and snippets.

@oxyii
Created September 13, 2021 20:29

Revisions

  1. oxyii created this gist Sep 13, 2021.
    44 changes: 44 additions & 0 deletions qrcode_espi.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    #include <Arduino.h>
    #include "qrencode.h"
    #include "qrcode_espi.h"


    QRcode_eSPI::QRcode_eSPI(TFT_eSPI *display) {
    this->display = display;
    }


    void QRcode_eSPI::init() {
    //display->init();
    this->screenwidth = display->width();
    this->screenheight = display->height();
    display->fillScreen(TFT_WHITE);
    int min = screenwidth;
    if (screenheight<screenwidth)
    min = screenheight;
    multiply = min/WD;
    offsetsX = (screenwidth-(WD*multiply))/2;
    offsetsY = (screenheight-(WD*multiply))/2;
    }

    void QRcode_eSPI::screenwhite() {
    display->fillScreen(TFT_WHITE);
    }

    void QRcode_eSPI::screenupdate() {
    // No hay que hacer nada
    }

    void QRcode_eSPI::drawPixel(int x, int y, int color) {
    if(color==1) {
    color = TFT_BLACK;
    } else {
    color = TFT_WHITE;
    }
    display->drawPixel(x,y,color);
    if (this->multiply>1) {
    display->drawPixel(x+1,y,color);
    display->drawPixel(x+1,y+1,color);
    display->drawPixel(x,y+1,color);
    }
    }
    26 changes: 26 additions & 0 deletions qrcode_espi.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #ifndef ESPQRST7735_H
    #define ESPQRST7735_H
    /* ESP_QRcode. tft version for ST7735
    * include this .h if you have a TFT display
    */

    #define TFTDISPLAY

    #include <TFT_eSPI.h>
    #include <SPI.h>
    #include "qrcode.h"

    class QRcode_eSPI : public QRcodeDisplay
    {
    private:
    TFT_eSPI *display;
    void drawPixel(int x, int y, int color);
    public:

    QRcode_eSPI(TFT_eSPI *display);

    void init();
    void screenwhite();
    void screenupdate();
    };
    #endif