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 32484ff
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 77 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
73 changes: 38 additions & 35 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,10 +17,9 @@
* 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"
#include "dwin_defines.h"

#if HAS_GCODE_PREVIEW
Expand Down Expand Up @@ -86,13 +85,14 @@ void Get_Value(char *buf, const char * const key, float &value) {
if (!ISEOL(c) && (c != 0)) {
if ((c > 47 && c < 58) || (c == '.')) num[i++] = c;
posptr++;
} else {
}
else {
num[i] = '\0';
value = atof(num);
return;
}
}
}
}
}

bool Has_Preview() {
Expand Down Expand Up @@ -129,7 +129,8 @@ bool Has_Preview() {
posptr = strstr(buf, tbstart);
if (posptr != NULL) {
fileprop.thumbstart = indx + (posptr - &buf[0]);
} else {
}
else {
indx += _MAX(10, nbyte - (signed)strlen(tbstart));
card.setIndex(indx);
}
Expand All @@ -148,10 +149,11 @@ bool Has_Preview() {
char c = card.get();
if (!ISEOL(c)) {
buf[i] = c;
} else {
}
else {
buf[i] = 0;
break;
}
}
}
fileprop.thumbsize = atoi(buf);

Expand Down Expand Up @@ -185,33 +187,34 @@ bool Has_Preview() {

void Preview_DrawFromSD() {
if (Has_Preview()) {
char buf[46];
char str_1[6] = "";
char str_2[6] = "";
char str_3[6] = "";
DWIN_Draw_Rectangle(1, HMI_data.Background_Color, 0, 0, DWIN_WIDTH, STATUS_Y - 1);
if (fileprop.time) {
sprintf_P(buf, PSTR("Estimated time: %i:%02i"), (uint16_t)fileprop.time / 3600, ((uint16_t)fileprop.time % 3600) / 60);
DWINUI::Draw_String(20, 10, buf);
}
if (fileprop.filament) {
sprintf_P(buf, PSTR("Filament used: %s m"), dtostrf(fileprop.filament, 1, 2, str_1));
DWINUI::Draw_String(20, 30, buf);
}
if (fileprop.layer) {
sprintf_P(buf, PSTR("Layer height: %s mm"), dtostrf(fileprop.layer, 1, 2, str_1));
DWINUI::Draw_String(20, 50, buf);
}
if (fileprop.width) {
sprintf_P(buf, PSTR("Volume: %sx%sx%s mm"), dtostrf(fileprop.width, 1, 1, str_1), dtostrf(fileprop.length, 1, 1, str_2), dtostrf(fileprop.height, 1, 1, str_3));
DWINUI::Draw_String(20, 70, buf);
char buf[46];
char str_1[6] = "";
char str_2[6] = "";
char str_3[6] = "";
DWIN_Draw_Rectangle(1, HMI_data.Background_Color, 0, 0, DWIN_WIDTH, STATUS_Y - 1);
if (fileprop.time) {
sprintf_P(buf, PSTR("Estimated time: %i:%02i"), (uint16_t)fileprop.time / 3600, ((uint16_t)fileprop.time % 3600) / 60);
DWINUI::Draw_String(20, 10, buf);
}
if (fileprop.filament) {
sprintf_P(buf, PSTR("Filament used: %s m"), dtostrf(fileprop.filament, 1, 2, str_1));
DWINUI::Draw_String(20, 30, buf);
}
if (fileprop.layer) {
sprintf_P(buf, PSTR("Layer height: %s mm"), dtostrf(fileprop.layer, 1, 2, str_1));
DWINUI::Draw_String(20, 50, buf);
}
if (fileprop.width) {
sprintf_P(buf, PSTR("Volume: %sx%sx%s mm"), dtostrf(fileprop.width, 1, 1, str_1), dtostrf(fileprop.length, 1, 1, str_2), dtostrf(fileprop.height, 1, 1, str_3));
DWINUI::Draw_String(20, 70, buf);
}
DWINUI::Draw_Button(BTN_Print, 26, 290);
DWINUI::Draw_Button(BTN_Cancel, 146, 290);
DWIN_ICON_Show(0, 0, 1, 21, 90, 0x00);
Draw_Select_Highlight(true, 290);
DWIN_UpdateLCD();
}
DWINUI::Draw_Button(BTN_Print, 26, 290);
DWINUI::Draw_Button(BTN_Cancel, 146, 290);
DWIN_ICON_Show(0, 0, 1, 21, 90, 0x00);
Draw_Select_Highlight(true, 290);
DWIN_UpdateLCD();
} else {
else {
HMI_flag.select_flag = 1;
wait_for_user = false;
}
Expand All @@ -225,4 +228,4 @@ void Preview_Reset() {
fileprop.thumbsize = 0;
}

#endif //HAS_GCODE_PREVIEW
#endif // HAS_GCODE_PREVIEW
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 32484ff

Please sign in to comment.