From ecf84eced87f22c9629a2b825db6e1a645ca8e3b Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Mon, 6 Jul 2015 18:59:35 +0200 Subject: [PATCH] [ES] Finished 6.1 but explode functionality MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-óff-by: Jim Martens --- es/blatt6/uebung6-1/uebung6-1.ino | 35 ++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/es/blatt6/uebung6-1/uebung6-1.ino b/es/blatt6/uebung6-1/uebung6-1.ino index e9024d4..517dbd3 100644 --- a/es/blatt6/uebung6-1/uebung6-1.ino +++ b/es/blatt6/uebung6-1/uebung6-1.ino @@ -361,6 +361,7 @@ const char* readString(File file) } else { result[i] = '\0'; + break; // allows for multiple calls of the method for iterative reading } } @@ -374,6 +375,21 @@ const char* readString(File file) } } +/** + * Explodes the string into an integer array. + * + * @param const int* input + * @param int length + */ +const int* explodeString(const char* input, int length) +{ + int result[length] = {}; + + // TODO do some magic + + return result; +} + /** * Handles the command. * @@ -428,7 +444,24 @@ void showFile(String fileName) printString(0, 0, text, readStringLength); } else { - // TODO handle image file + const char* dimensions = readString(file); + int dimensionsLength = readStringLength; + const char* pixels = readString(file); + int pixelsLength = readStringLength; + + // parse dimensions and pixels + // TODO is there some kind of explode? - that is exactly what we need + const int* dimensionsInt = explodeString(dimensions, dimensionsLength); + const int* pixelsInt = explodeString(pixels, pixelsLength); + // calculate x and y start positions + int rows = dimensionsInt[0]; + int cols = dimensionsInt[1]; + int x = (48 - rows) / 2; + int y = (84 - cols) / 2; + + printImage(x, y, rows, cols, pixelsInt); } + + // TODO Closing the file? } }