Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jun 4, 2022
1 parent 703cfce commit 1a195e5
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 46 deletions.
70 changes: 35 additions & 35 deletions Marlin/src/lcd/e3v2/proui/base64.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Base64 encoder/decoder for arduino repo
* Uses common web conventions - '+' for 62, '/' for 63, '=' for padding.
* Note that invalid base64 characters are interpreted as padding.
* Note that invalid base64 characters are interpreted as padding.
* Author: Densaugeo
* Maintainer: Densaugeo
* Version: 1.2.1.1
* Changed unsigned int to uint16_t for use in the professional Ender 3V2/S1 firmware
* Changed unsigned int to uint16_t for use in the professional Ender 3V2/S1 firmware
* Url: https://www.arduino.cc/reference/en/libraries/base64/
*/

Expand Down Expand Up @@ -83,39 +83,39 @@ uint16_t decode_base64(unsigned char input[], uint16_t input_length, unsigned ch

unsigned char binary_to_base64(unsigned char v) {
// Capital letters - 'A' is ascii 65 and base64 0
if(v < 26) return v + 'A';
if (v < 26) return v + 'A';

// Lowercase letters - 'a' is ascii 97 and base64 26
if(v < 52) return v + 71;
if (v < 52) return v + 71;

// Digits - '0' is ascii 48 and base64 52
if(v < 62) return v - 4;
if (v < 62) return v - 4;

// '+' is ascii 43 and base64 62
if(v == 62) return '+';
if (v == 62) return '+';

// '/' is ascii 47 and base64 63
if(v == 63) return '/';
if (v == 63) return '/';

return 64;
}

unsigned char base64_to_binary(unsigned char c) {
// Capital letters - 'A' is ascii 65 and base64 0
if('A' <= c && c <= 'Z') return c - 'A';
if ('A' <= c && c <= 'Z') return c - 'A';

// Lowercase letters - 'a' is ascii 97 and base64 26
if('a' <= c && c <= 'z') return c - 71;
if ('a' <= c && c <= 'z') return c - 71;

// Digits - '0' is ascii 48 and base64 52
if('0' <= c && c <= '9') return c + 4;
if ('0' <= c && c <= '9') return c + 4;

// '+' is ascii 43 and base64 62
if(c == '+') return 62;
if (c == '+') return 62;

// '/' is ascii 47 and base64 63
if(c == '/') return 63;
if (c == '/') return 63;

return 255;
}

Expand All @@ -129,29 +129,29 @@ uint16_t decode_base64_length(unsigned char input[]) {

uint16_t decode_base64_length(unsigned char input[], uint16_t input_length) {
unsigned char *start = input;
while(base64_to_binary(input[0]) < 64 && (unsigned char)(input - start) < input_length) {

while (base64_to_binary(input[0]) < 64 && (unsigned char)(input - start) < input_length) {
++input;
}

input_length = input - start;
return input_length/4*3 + (input_length % 4 ? input_length % 4 - 1 : 0);
}

uint16_t encode_base64(unsigned char input[], uint16_t input_length, unsigned char output[]) {
uint16_t full_sets = input_length/3;

// While there are still full sets of 24 bits...
for(uint16_t i = 0; i < full_sets; ++i) {
for (uint16_t i = 0; i < full_sets; ++i) {
output[0] = binary_to_base64( input[0] >> 2);
output[1] = binary_to_base64((input[0] & 0x03) << 4 | input[1] >> 4);
output[2] = binary_to_base64((input[1] & 0x0F) << 2 | input[2] >> 6);
output[3] = binary_to_base64( input[2] & 0x3F);

input += 3;
output += 4;
}

switch(input_length % 3) {
case 0:
output[0] = '\0';
Expand All @@ -171,7 +171,7 @@ uint16_t encode_base64(unsigned char input[], uint16_t input_length, unsigned ch
output[4] = '\0';
break;
}

return encode_base64_length(input_length);
}

Expand All @@ -181,17 +181,17 @@ uint16_t decode_base64(unsigned char input[], unsigned char output[]) {

uint16_t decode_base64(unsigned char input[], uint16_t input_length, unsigned char output[]) {
uint16_t output_length = decode_base64_length(input, input_length);

// While there are still full sets of 24 bits...
for(uint16_t i = 2; i < output_length; i += 3) {
for (uint16_t i = 2; i < output_length; i += 3) {
output[0] = base64_to_binary(input[0]) << 2 | base64_to_binary(input[1]) >> 4;
output[1] = base64_to_binary(input[1]) << 4 | base64_to_binary(input[2]) >> 2;
output[2] = base64_to_binary(input[2]) << 6 | base64_to_binary(input[3]);

input += 4;
output += 3;
}

switch(output_length % 3) {
case 1:
output[0] = base64_to_binary(input[0]) << 2 | base64_to_binary(input[1]) >> 4;
Expand All @@ -201,7 +201,7 @@ uint16_t decode_base64(unsigned char input[], uint16_t input_length, unsigned ch
output[1] = base64_to_binary(input[1]) << 4 | base64_to_binary(input[2]) >> 2;
break;
}

return output_length;
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/e3v2/proui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ void Draw_PrintDone() {
if (sdprint && TERN0(HAS_GCODE_PREVIEW, Preview_Valid())) {
DWIN_ICON_Show(0, 0, 1, 21, 100, 0x00);
DWINUI::Draw_Button(BTN_Continue, 86, 300);
}
}
else {
Draw_Print_ProgressBar();
Draw_Print_Labels();
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/lcd/e3v2/proui/gcode_preview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Date: 2021/06/19
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
Expand All @@ -17,7 +17,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* For commercial applications additional licences can be requested
* For commercial applications additional licenses can be requested
*/

#include "../../../inc/MarlinConfigPre.h"
Expand Down Expand Up @@ -92,7 +92,7 @@ void Get_Value(char *buf, const char * const key, float &value) {
return;
}
}
}
}
}

bool Has_Preview() {
Expand Down Expand Up @@ -151,7 +151,7 @@ bool Has_Preview() {
} else {
buf[i] = 0;
break;
}
}
}
fileprop.thumbsize = atoi(buf);

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/e3v2/proui/gcode_preview.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Date: 2021/06/19
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
Expand All @@ -17,7 +17,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* For commercial applications additional licences can be requested
* For commercial applications additional licenses can be requested
*/

#pragma once
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/e3v2/proui/plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* For commercial applications additional licences can be requested
* For commercial applications additional licenses can be requested
*/

#include "../../../inc/MarlinConfigPre.h"
Expand Down Expand Up @@ -68,4 +68,4 @@ void PlotClass::Update(const float value) {
grphpoints++;
}

#endif // DWIN_LCD_PROUI
#endif // DWIN_LCD_PROUI
4 changes: 2 additions & 2 deletions Marlin/src/lcd/e3v2/proui/plot.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* For commercial applications additional licences can be requested
* For commercial applications additional licenses can be requested
*/
#pragma once

Expand All @@ -29,4 +29,4 @@ class PlotClass {
void Update(float value);
};

extern PlotClass Plot;
extern PlotClass Plot;

0 comments on commit 1a195e5

Please sign in to comment.