arduinoprojects

git clone https://git.tarina.org/arduinoprojects
Log | Files | Refs

GFXcanvasSerialDemo.cpp (2094B)


      1 #include "GFXcanvasSerialDemo.h"
      2 #include <Arduino.h>
      3 
      4 GFXcanvas1SerialDemo::GFXcanvas1SerialDemo(uint16_t w, uint16_t h)
      5     : GFXcanvas1(w, h) {}
      6 
      7 void GFXcanvas1SerialDemo::print(bool rotated) {
      8   char pixel_buffer[8];
      9   uint16_t width, height;
     10 
     11   if (rotated) {
     12     width = this->width();
     13     height = this->height();
     14   } else {
     15     width = this->WIDTH;
     16     height = this->HEIGHT;
     17   }
     18 
     19   for (uint16_t y = 0; y < height; y++) {
     20     for (uint16_t x = 0; x < width; x++) {
     21       bool pixel;
     22       if (rotated) {
     23         pixel = this->getPixel(x, y);
     24       } else {
     25         pixel = this->getRawPixel(x, y);
     26       }
     27       sprintf(pixel_buffer, " %d", pixel);
     28       Serial.print(pixel_buffer);
     29     }
     30     Serial.print("\n");
     31   }
     32 }
     33 
     34 GFXcanvas8SerialDemo::GFXcanvas8SerialDemo(uint16_t w, uint16_t h)
     35     : GFXcanvas8(w, h) {}
     36 
     37 void GFXcanvas8SerialDemo::print(bool rotated) {
     38   char pixel_buffer[8];
     39   uint16_t width, height;
     40 
     41   if (rotated) {
     42     width = this->width();
     43     height = this->height();
     44   } else {
     45     width = this->WIDTH;
     46     height = this->HEIGHT;
     47   }
     48 
     49   for (uint16_t y = 0; y < height; y++) {
     50     for (uint16_t x = 0; x < width; x++) {
     51       uint8_t pixel;
     52       if (rotated) {
     53         pixel = this->getPixel(x, y);
     54       } else {
     55         pixel = this->getRawPixel(x, y);
     56       }
     57       sprintf(pixel_buffer, " %02x", pixel);
     58       Serial.print(pixel_buffer);
     59     }
     60     Serial.print("\n");
     61   }
     62 }
     63 
     64 GFXcanvas16SerialDemo::GFXcanvas16SerialDemo(uint16_t w, uint16_t h)
     65     : GFXcanvas16(w, h) {}
     66 
     67 void GFXcanvas16SerialDemo::print(bool rotated) {
     68   char pixel_buffer[8];
     69   uint16_t width, height;
     70 
     71   if (rotated) {
     72     width = this->width();
     73     height = this->height();
     74   } else {
     75     width = this->WIDTH;
     76     height = this->HEIGHT;
     77   }
     78 
     79   for (uint16_t y = 0; y < height; y++) {
     80     for (uint16_t x = 0; x < width; x++) {
     81       uint16_t pixel;
     82       if (rotated) {
     83         pixel = this->getPixel(x, y);
     84       } else {
     85         pixel = this->getRawPixel(x, y);
     86       }
     87       sprintf(pixel_buffer, " %04x", pixel);
     88       Serial.print(pixel_buffer);
     89     }
     90     Serial.print("\n");
     91   }
     92 }