123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- #define FRAME_BUFFER_SIZE 64
- const unsigned char sd_error_fb[] = {
- 0x00, 0x00, 0x00, 0x00,
- 0x77, 0x3b, 0x9c, 0x00,
- 0x44, 0xa2, 0x52, 0x00,
- 0x74, 0xbb, 0x9c, 0x00,
- 0x14, 0xa2, 0x52, 0x00,
- 0x77, 0x3a, 0x52, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00
- };
- unsigned char frame_buffer[] = {
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x22, 0x00, 0x00, 0x44,
- 0x44, 0x00, 0x00, 0x22,
- 0x89, 0x80, 0x01, 0x91,
- 0x92, 0x40, 0x02, 0x49,
- 0x82, 0x40, 0x02, 0x41,
- 0x81, 0x80, 0x01, 0x81,
- 0x80, 0x04, 0x40, 0x01,
- 0x80, 0x09, 0x20, 0x01,
- 0x87, 0x89, 0x21, 0xe1,
- 0x40, 0x06, 0xc0, 0x02,
- 0x27, 0x80, 0x01, 0xe4,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00
- };
- void loadFrameAndRender(String filepath) {
- readFrameToFrameBuffer(filepath);
- renderFrame();
- }
- void loadSDErrorToFrameBuffer(){
-
- size_t bufferSize = sizeof(sd_error_fb) / sizeof(sd_error_fb[0]);
- for (size_t i = 0; i < bufferSize; i++) {
- frame_buffer[i] = sd_error_fb[i];
- }
- }
- int readFrameToFrameBuffer(String filepath) {
- File file = SD.open(filepath, FILE_READ);
- if (!file) {
- Serial.println("Failed to open file for reading");
- return 1;
- }
-
- size_t bytesRead = 0;
- while (file.available() && bytesRead < FRAME_BUFFER_SIZE) {
- frame_buffer[bytesRead] = file.read();
- bytesRead++;
- }
-
- file.close();
- return 0;
- }
- void renderFrame() {
-
- int fsize = sizeof(frame_buffer);
- for (int i = 0; i < fsize / 2; i += 4) {
- for (int d = 0; d <= 3; d++) {
-
- byte rowData = frame_buffer[i + d];
- mx.setRow(d, d, 7 - int(i / 4), fByte(rowData));
- }
- }
-
- for (int i = fsize / 2; i < fsize; i += 4) {
- for (int d = 4; d <= 7; d++) {
-
- byte rowData = frame_buffer[i + (d - 4)];
- mx.setRow(d, d, 7 - (int(i / 4) - 8), fByte(rowData));
- }
- }
- }
- void clearFrame() {
-
- setAnimationCode('z');
- }
- void setDisplayBrightness(byte brightness) {
- for (int i = 0; i < MAX_DEVICES; i++) {
- mx.control(i, MD_MAX72XX::INTENSITY, brightness);
- }
- }
- byte fByte(byte c) {
- char r = 0;
- for (byte i = 0; i < 8; i++) {
- r <<= 1;
- r |= c & 1;
- c >>= 1;
- }
- return r;
- }
|