From d0e37693ce0171a47ac7174801a81836cd71e243 Mon Sep 17 00:00:00 2001 From: NosDE Date: Thu, 25 Oct 2018 22:12:28 +0200 Subject: [PATCH 1/2] added support for sdcard and papywizard style xml-file --- software/gigascan/src/config.h | 4 + software/gigascan/src/panobot.cpp | 127 +++++++++++++++++++++++++++++- 2 files changed, 130 insertions(+), 1 deletion(-) mode change 100644 => 100755 software/gigascan/src/config.h mode change 100644 => 100755 software/gigascan/src/panobot.cpp diff --git a/software/gigascan/src/config.h b/software/gigascan/src/config.h old mode 100644 new mode 100755 index a9a0ee9..cb286d9 --- a/software/gigascan/src/config.h +++ b/software/gigascan/src/config.h @@ -39,6 +39,10 @@ e-mail : robert.fach@gmx.net #define ENCODER_BTN_PIN -44 #define DISPLAY_RESET_BTN_PIN -49 //negative means active internal pull-up +//SDCard for xml files +#define SDCARDCHIP_SELECT_PIN 41 // chipselect of the sdcard interface +#define FILE_BASE_NAME "Scan" // must not be longer than 6 characters + #endif//HARDWARE_VERSION_1_1_0 const char SPLASHSCREEN[] PROGMEM = { "00000000000000000000000000001111111100001100101000000000000000000000000000000000000000000011111111111100110010100000000000000000000000000000000000000000011111111110111110000000000000000000000000000000000000000000001001111111111001111110000000000000000000000000000000000000000001011010111111101111111100000000000000000000000000000000000000000111000011111111111111111000000000000000000000000000000000000000001010011111111111111111100000000000000000000000000000000000000000001001111111111111111110000000000000000000000000000000000000000001000111111111111111100000000000000000000000000000000000000000000100000111110111111111010000000000000000000000000000000000000000000001111111011111111101000000000000000000000000000000000000000000001111111100111111111000000000000000000000000000000000000000000001111101111011111111000000000000000000000000000000000000000000000111110011101111111000000000000000000000000000000000000000000000111111010010001111110000000000000000000000000000000000000000000101111100000000011110000000000000000000000000000000000000000000000111111100000001010000000000000000000000000000000000000000000000111111100000000100000000000000000000000000000000000000000000000001110100000000000000000000000000000000000000000000000000000000000001010000000000000000000000000000000000000000000000000000000001001101000000000000000000000000000000000000000000000000000000000110110000000000000000000000000000000000000000000000000000000000000111100000000000000000000000000000000000000000000000000000000000011110000001110000000000000000000000000000000000000000000000000001110000001111110000000000000000000000000000000000000000000000000111010001111111000000000000000000000000000000000000000000000000011100000110001110000000000000000000000000000000000000000000000001011000010000011100000000000000000000000000000000000000000000000001100001000001110000000000000000000000000000000000000000000000010111000111000111100100000000000000000000000000000000000000000000011100011110001111000000000000000000000000000000000000000000000000110001111000101101000000000000000000000000000000000000000000000111000010100011110100000000000000000000000000000000000000000000001110000010000111010000000000000000000000000000000000000000000000111000001000011111000000000000000000000000000000000000000000000001110001100001011110000000000000000000000000000000000000000000000111111100000101111010100000000000000000000000000000000000000000000111100000001111101100000000000000000000000000000000000000000000001101000000111110001000000000000000000000000000000000000000000001000000000011110001000000000000000000000000000000000000000000000000000000001111100100000000000000000000000000000000000000000000000000000001011100010000000000000000000000000000000000000000000000000000001100110001000000000000000000000000000000000010000100000000000000000011111100000000000000000000000000000000001110110000000000000001011111110000000000000000000000000000000000001010000000000000000001111110000000000000000000000000000001001101111001000000000000011111111010000000000000000000000000000100010011111100000000000001111111100000000000000000000000000000010111011111110100000000101111111111000000000000000000000000000011001111111111111000000010111111111100000000000000000000000000000110001111111111100000001101111111110000000000000000000000000000001010111111111000000000110011111111000000000000000000000000000000000111111111110101100001001111111100000000000000000000000000000000111111111111110110010000111111110000000000000000000000000000011101111111111111110111100001111110000000000000000000000000000011110111111111111101011110001111110000100000000000000000000000000111111111111111110001111110111110000111110000000000000000000001011111111111111111000011111111111100011011000000000000000000000001111111111111111110011111111100100010011110000000000000000000011111111111111111110011111111110000001000011000000000000000000011101001111111111111100111111111001000110011011000000000000010000111100111111111111110011111111110100011101101100000000000000110110001011111111111111111111111111010001100110010000000000000011010000011111111111111111111111111110000001011110000000000000011101000001111111111111111111111111111100000101110000000000000011110100000011111111111111111111111111110000010110000000000000010011001100010111111111111111111111111110100011011000000000000001101101110001011111111110011111111111111001111000010000000000000110110011000100111111111001111111111111100101110000000000000000000110000100000011111111110011111111111111111110000000000000000000011110010001001111111110011111111111111111100000000000000000000000110110001111111111110000111111111111111110100000000000000000000011111000011111011111100011111111111111111000000000000000000000000001000011111100011110101111111111111011110000000000000000000000000000011111100001111011111111111111101110000000000000000000000000000011111111000010011011111111111111000000000000000000000000000000001111111100100001101011111111111000000000000000000000000000000000111111110011000000000111111111010100000000000000000000000000000011111111101100000001111111111100011000000000000000000000000000001111111111010000000111111111111100110000000000000000000000000000111111111101000000001011111110111010000000000000000000000000000001111111100000000000001111110010001000000000000000000000000000010111111110000000000000100111101100100000000000000000000000000000011111100000000000000000010100000000000000000000000000000000000011111110100000000000000011011100000000000000000000000000000000001111110000000000000000001000010000000000000000000000000000000000100011001100000000000000000000000000000000000000000000000000000010001110100000000000000000000000000000000000000000000000000000001001111100000000000000000000000000000000000000000000000000000000100011110000000000100000000000000000000000000000000000000000000100011111000000101100000000000000000000000000000000000000000000001101111100000001111000000000000000000000000000000000000000000001010111101000001111111000000000000000000000000000000000000000000000011110100001100011100000000000000000000000000000000000000000000000111110000100000111000000000000000000000000000000000000000000000010111000010000011100000000000000000000000000000000000000000000001011110001010000111000000000000000000000000000000000000000000000101101000111100011000000000000000000000000000000000000000000000000111100011110001110000000000000000000000000000000000000000000001001111000111000111010000000000000000000000000000000000000000000000011100000100001100000000000000000000000000000000000000000000000001110000010000110100000000000000000000000000000000000000000000000011100011000001110000000000000000000000000000000000000000000000000111111100010111000000000000000000000000000000000000000000000000011111100000011100000000000000000000000000000000000000000000000000011100000011110000000000000000000000000000000000000000000000000000000000001111000000000000000000000000000000000000000000000000000000000000011011000000000000000000000000000000000000000000000000000000000101100100000000000000000000000000000000000000000000000000000000010100000000000000000000000000000000000000000000000000000000000001011100000000000000000000000000000000000000000000000001000000001111111000000000000000000000000000000000000000000000010100000001111111000000000000000000000000000000000000000000000011110000000001111101000000000000000000000000000000000000000000011111100010010111111000000000000000000000000000000000000000000000111111101110011111000000000000000000000000000000000000000000000111111110111101111100000000000000000000000000000000000000000000111111111001111111100000000000000000000000000000000000000000000101111111110111111100000000000000000000000000000000000000000000010111111111011111000001000000000000000000000000000000000000000000001111111111111111000100000000000000000000000000000000000000000011111111111111111100100000000000000000000000000000000000000000001111111111111111110010100000000000000000000000000000000000000000111111111111111110000111000000000000000000000000000000000000000001111111101111111010110100000000000000000000000000000000000000000011111100111111111100100000000000000000000000000000000000000000000011111011111111110000000000000000000000000000000000000000001010011001111111111110000000000000000000000000"}; diff --git a/software/gigascan/src/panobot.cpp b/software/gigascan/src/panobot.cpp old mode 100644 new mode 100755 index f8f7c1b..7353a47 --- a/software/gigascan/src/panobot.cpp +++ b/software/gigascan/src/panobot.cpp @@ -36,6 +36,15 @@ e-mail : robert.fach@gmx.net #include #include +// SDCard +#include +const uint8_t BASE_NAME_SIZE = sizeof(FILE_BASE_NAME) - 1; +char fileName[] = FILE_BASE_NAME "00.xml"; +bool useSDCard = false; +double rollPos = 0; +File sdFile; + + using namespace Menu; //panobot logic & motor control @@ -68,6 +77,93 @@ double g_hfov = 0; double g_vfov = 0; + +void xmlWriteHeader() { + if (useSDCard) { + sdFile = SD.open(fileName, FILE_WRITE); + if (sdFile) { + sdFile.println(""); + sdFile.println(""); + sdFile.println("
"); + sdFile.println(" "); + sdFile.println(" "); + sdFile.println(" Papywizard-Format XML File"); + sdFile.println(" "); + sdFile.println(" "); + sdFile.println(" Panobot generated file."); + sdFile.println(" "); + sdFile.println(" "); + sdFile.println(" "); + sdFile.println(" "); + sdFile.println(" up"); + sdFile.println(" "); + sdFile.println(" "); + sdFile.println(" landscape"); + sdFile.println(" "); + sdFile.println(" "); + sdFile.println(" "); + //sdFile.println(" "); + sdFile.println(" "); + sdFile.println(" "); + sdFile.println(" "); + sdFile.print(" "); + sdFile.println((user_config.focal_length*user_config.crop_factor), DEC); + sdFile.println(" "); + sdFile.println(" "); + sdFile.println("
"); + sdFile.println(" "); + sdFile.close(); + } + } +} + + +void xmlWritePicture() { + if (useSDCard) { + sdFile = SD.open(fileName, FILE_WRITE); + if (sdFile) { + sdFile.print(" "); + sdFile.print(" "); + sdFile.println(" "); + sdFile.close(); + } + } +} + +void xmlWriteFooter() { + if (useSDCard) { + sdFile = SD.open(fileName, FILE_WRITE); + if (sdFile) { + sdFile.println(" "); + sdFile.println("
"); + sdFile.close(); + } + } +} + + +void sdGetNextFilename() { + if(useSDCard) { + while (SD.exists(fileName)) { + if (fileName[BASE_NAME_SIZE + 1] != '9') { + fileName[BASE_NAME_SIZE + 1]++; + } else if (fileName[BASE_NAME_SIZE] != '9') { + fileName[BASE_NAME_SIZE + 1] = '0'; + fileName[BASE_NAME_SIZE]++; + } else { + Serial.println(F("Can't create file name")); + return; + } + } + sdFile = SD.open(fileName, FILE_WRITE); + if (sdFile) { + sdFile.close(); + } + } +} + + + //callback function used by the menu to do the math when updating some values void updateScanner() { g_hfov = degrees( 2 * atan2(g_sensorFF_horizontal, user_config.crop_factor * 2 * user_config.focal_length)); @@ -163,6 +259,8 @@ long startTime = 0; void runScanCallback() { + //sdGetNextFilename(); + xmlWriteHeader(); g_runScan = true; g_scanPositionHorizontal = 0; g_scanPositionVertical = 0; @@ -172,6 +270,8 @@ void runScanCallback() void runSphereCallback() { + //sdGetNextFilename(); + xmlWriteHeader(); g_runScan = true; modePattern = SPHERICAL; g_picturesTotal = 0; @@ -272,12 +372,17 @@ void stateMachine() { printScannerStats(); digitalWrite(FOCUS_PIN, LOW); digitalWrite(SHUTTER_PIN, LOW); + + // log Picture to SD Card + xmlWritePicture(); + state = updatePosition(state,modePattern); } } if (state == FINISH) { if (tiltStepper.distanceToGo() == 0 && panStepper.distanceToGo() == 0) { state = IDLE; + xmlWriteFooter(); } } } @@ -424,6 +529,8 @@ void splashscreen() { delay(5000); } + + void setup() { loadConfig(); options = &myOptions; @@ -431,6 +538,19 @@ void setup() { Serial.begin(115200); while(!Serial); Serial.println("Panobot");Serial.flush(); + + // SDCard + delay(200); + Serial.print("Initializing SD card..."); + if (!SD.begin(SDCARDCHIP_SELECT_PIN)) { + useSDCard = false; + } else { + useSDCard = true; + sdGetNextFilename(); + Serial.println("SDCard found..."); + } + delay(500); + //initialize menu u8g2.begin(); u8g2.setFont(fontName); @@ -438,6 +558,7 @@ void setup() { encoder.begin(); //initialize bot setupPanoBot(); + Serial.println("initialization done."); splashscreen(); } @@ -451,7 +572,11 @@ void loop() { u8g2.setFontMode(1); u8g2.setDrawColor(1); u8g2.setFont(u8g2_font_ncenB12_tr); - u8g2.drawStr(0, 32, "PANOBOT"); + if (useSDCard) { + u8g2.drawStr(0, 32, fileName); + } else { + u8g2.drawStr(0, 32, "PANOBOT"); + } u8g2.setFont(fontName); drawStatus(); u8g2.sendBuffer(); From c93f7513bc108e864bdbb5dac024c1d95f1d3ee5 Mon Sep 17 00:00:00 2001 From: NosDE Date: Sat, 27 Oct 2018 10:10:52 +0200 Subject: [PATCH 2/2] Pinmapping added --- software/gigascan/.gitignore | 3 +++ software/gigascan/.vscode/extensions.json | 7 +++++++ software/gigascan/.vscode/settings.json | 6 ++++++ software/gigascan/src/panobot.cpp | 6 ++++++ 4 files changed, 22 insertions(+) create mode 100644 software/gigascan/.vscode/extensions.json create mode 100644 software/gigascan/.vscode/settings.json diff --git a/software/gigascan/.gitignore b/software/gigascan/.gitignore index 5dac9f5..c989b68 100644 --- a/software/gigascan/.gitignore +++ b/software/gigascan/.gitignore @@ -2,3 +2,6 @@ .piolibdeps .clang_complete .gcc-flags.json +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json diff --git a/software/gigascan/.vscode/extensions.json b/software/gigascan/.vscode/extensions.json new file mode 100644 index 0000000..8281e64 --- /dev/null +++ b/software/gigascan/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ] +} \ No newline at end of file diff --git a/software/gigascan/.vscode/settings.json b/software/gigascan/.vscode/settings.json new file mode 100644 index 0000000..393efc6 --- /dev/null +++ b/software/gigascan/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "terminal.integrated.env.osx": { + "PATH": "/Users/marco/.platformio/penv/bin:/Users/marco/.platformio/penv:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/CrossPack-AVR/bin", + "PLATFORMIO_CALLER": "vscode" + } +} \ No newline at end of file diff --git a/software/gigascan/src/panobot.cpp b/software/gigascan/src/panobot.cpp index 7353a47..8501ade 100755 --- a/software/gigascan/src/panobot.cpp +++ b/software/gigascan/src/panobot.cpp @@ -37,6 +37,12 @@ e-mail : robert.fach@gmx.net #include // SDCard +// -------------------------- +// on the Rev 1.1.0 Board you have connect the following Pins from J4 +// J4 Pin 1 -> D50 (AT-Mega) +// J4 Pin 2 -> J3 Pin 5 +// J4 Pin 4 -> D41 (AT-Mega) +// J4 Pin 6 -> J3 Pin 3 #include const uint8_t BASE_NAME_SIZE = sizeof(FILE_BASE_NAME) - 1; char fileName[] = FILE_BASE_NAME "00.xml";