// STL includes #include #include #include #include #include using namespace std; ofstream& indent(ofstream& ofs, unsigned indent) { for (unsigned i=0; i createLedMapping(const LedFrame ledFrame) { std::vector leds; for (unsigned iLed=0; iLed leds = createLedMapping(myFrame); ofstream configOfs(filename.c_str()); configOfs << "// Automatically generated configuration file for 'Hyperion'" << endl; configOfs << "// Generation script: " << argv[0] << endl; configOfs << endl; configOfs << "{" << endl; // Write the device section indent(configOfs, 1) << R"("device" : )" << endl; indent(configOfs, 1) << "{" << endl; indent(configOfs, 2) << R"("name" : "MyPi",)" << endl; indent(configOfs, 2) << R"("type" : "ws2801",)" << endl; indent(configOfs, 2) << R"("output" : "/dev/spidev0.0",)" << endl; indent(configOfs, 2) << R"("interval" : 20000,)" << endl; indent(configOfs, 2) << R"("rate" : 48000)" << endl; indent(configOfs, 1) << "}," << endl; // Write the color-correction section indent(configOfs, 1) << R"("color" : )" << endl; indent(configOfs, 1) << "{" << endl; indent(configOfs, 2) << R"("red" : )" << endl; indent(configOfs, 2) << "{" << endl; indent(configOfs, 3) << R"("gamma" : 1.0,)" << endl; indent(configOfs, 3) << R"("adjust" : 1.0,)" << endl; indent(configOfs, 3) << R"("blacklevel" : 0.0)" << endl; indent(configOfs, 2) << "}," << endl; indent(configOfs, 2) << R"("green" : )" << endl; indent(configOfs, 2) << "{" << endl; indent(configOfs, 3) << R"("gamma" : 1.0,)" << endl; indent(configOfs, 3) << R"("adjust" : 1.0,)" << endl; indent(configOfs, 3) << R"("blacklevel" : 0.0)" << endl; indent(configOfs, 2) << "}," << endl; indent(configOfs, 2) << R"("blue" : )" << endl; indent(configOfs, 2) << "{" << endl; indent(configOfs, 3) << R"("gamma" : 1.0,)" << endl; indent(configOfs, 3) << R"("adjust" : 1.0,)" << endl; indent(configOfs, 3) << R"("blacklevel" : 0.0)" << endl; indent(configOfs, 2) << "}" << endl; indent(configOfs, 1) << "}," << endl; // Write the leds section indent(configOfs, 1) << R"("leds" : )" << endl; indent(configOfs, 1) << "[" << endl; for (const Led& led : leds) { // Add comments indicating the corners of the configuration if (led.minX == 0.0) { if (led.minY == 0.0) { indent(configOfs, 2) << "// TOP-LEFT Corner" << endl; } else if (led.maxY == 100.0) { indent(configOfs, 2) << "// BOTTOM-LEFT Corner" << endl; } } else if (led.maxX == 100.0) { if (led.minY == 0.0) { indent(configOfs, 2) << "// TOP-RIGHT Corner" << endl; } else if (led.maxY == 100.0) { indent(configOfs, 2) << "// BOTTOM-RIGHT Corner" << endl; } } // Write the configuration of the led indent(configOfs, 2) << "{" << endl; indent(configOfs, 3) << R"("index" : )" << led.index << "," << endl; indent(configOfs, 3) << R"("hscan" : { "minimum" : )" << led.minX << R"(, "maximum" : )" << led.maxX << R"( },)" << endl; indent(configOfs, 3) << R"("vscan" : { "minimum" : )" << led.minY << R"(, "maximum" : )" << led.maxY << R"( })" << endl; indent(configOfs, 2) << "}"; if (led.index != leds.back().index) { configOfs << ","; } configOfs << endl; } indent(configOfs, 1) << "]" << endl; configOfs << "}" << endl; }