diff --git a/lib/waveform_table.cpp b/lib/waveform_table.cpp index b3e3b1e..44ca55b 100644 --- a/lib/waveform_table.cpp +++ b/lib/waveform_table.cpp @@ -760,17 +760,9 @@ auto decode_fpl_number(const std::string& barcode) -> std::int16_t } // anonymous namespace -auto WaveformTable::discover_wbf_file() -> std::optional +auto scan_wbf_dir(const std::string& path, std::int16_t fpl_lot) -> std::optional { - auto metadata = read_metadata(); - - if (metadata.size() < 4) { - return {}; - } - - auto fpl_lot = decode_fpl_number(metadata[3]); - - for (const auto& entry : fs::directory_iterator{"/usr/share/remarkable"}) { + for (const auto& entry : fs::directory_iterator{path}) { if (entry.path().extension().native() != ".wbf") { continue; } @@ -794,8 +786,27 @@ auto WaveformTable::discover_wbf_file() -> std::optional continue; } } - return {}; } +auto WaveformTable::discover_wbf_file() -> std::optional +{ + auto metadata = read_metadata(); + + if (metadata.size() < 4) { + std::cerr << "Invalid metadata" << std::endl; + return {}; + } + + auto fpl_lot = decode_fpl_number(metadata[3]); + + std::cerr << std::to_string(fpl_lot) << std::endl; + + auto path = scan_wbf_dir("/var/lib/uboot", fpl_lot); + if (!path) { + path = scan_wbf_dir("/usr/share/remarkable", fpl_lot); + } + return path; +} + } // namespace Waved diff --git a/src/rm2fb/main.cpp b/src/rm2fb/main.cpp index 9ce27d4..ca55d9a 100644 --- a/src/rm2fb/main.cpp +++ b/src/rm2fb/main.cpp @@ -24,28 +24,31 @@ constexpr float to_float(uint16_t c) + (c & 31) * (0.07 / 31); // blue } -void do_update(Waved::Generator& generator, const swtfb::swtfb_update& s) -{ - auto mxcfb_update = s.mdata.update; - auto rect = mxcfb_update.update_region; - std::vector buffer(rect.width * rect.height); +void do_update( + Waved::Generator& generator, + std::uint32_t left, + std::uint32_t top, + std::uint32_t width, + std::uint32_t height, + Waved::ModeID mode, + bool full_update +) { + std::vector buffer(width * height); #ifdef DEBUG_DIRTY std::cerr << "HANDLING UPDATE\n"; - std::cerr << "Dirty Region: " << rect.left << " " << rect.top << " " - << rect.width << " " << rect.height << '\n'; + std::cerr << "Dirty Region: " << left << " " << top << " " + << width << " " << height << '\n'; #endif // TODO: verify that the rectangle is within SHARED_MEM's bounds, otherwise the server will crash - for (unsigned int i = 0; i < rect.height; i++) { - for (unsigned int j = 0; j < rect.width; j++) { + for (unsigned int i = 0; i < height; i++) { + for (unsigned int j = 0; j < width; j++) { // intensity is from 0 - 30, evens only - buffer[j + i*rect.width] = uint8_t(to_float(SHARED_MEM[j+rect.left + (i+rect.top)*WIDTH]) * 15) * 2; + buffer[j + i*width] = uint8_t(to_float(SHARED_MEM[j+left + (i+top)*WIDTH]) * 15) * 2; } } - Waved::ModeID mode = mxcfb_update.waveform_mode; - bool full_update = mxcfb_update.update_mode; bool immediate = false; if (mode == /* fast */ 1 && !full_update) { @@ -53,10 +56,10 @@ void do_update(Waved::Generator& generator, const swtfb::swtfb_update& s) } Waved::UpdateRegion region; - region.top = rect.top; - region.left = rect.left; - region.width = rect.width; - region.height = rect.height; + region.top = top; + region.left = left; + region.width = width; + region.height = height; generator.push_update(mode, immediate, region, buffer); } @@ -131,17 +134,32 @@ int main(int argc, const char** argv) while (true) { auto buf = MSGQ.recv(); switch (buf.mtype) { - case swtfb::ipc::UPDATE_t: - do_update(generator, buf); + case swtfb::ipc::UPDATE_t:{ + auto rect = buf.mdata.update.update_region; + do_update( + generator, + rect.left, + rect.top, + rect.width, + rect.height, + buf.mdata.update.waveform_mode, + buf.mdata.update.update_mode + ); break; - - case swtfb::ipc::XO_t: - // XO_t means that buf.xochitl_update is filled in and needs to - // be forwarded to xochitl or translated to a compatible format - // with waved server - std::cerr << "(Unhandled XO_t message)\n"; + } + case swtfb::ipc::XO_t:{ + auto xdata = buf.mdata.xochitl_update; + do_update( + generator, + xdata.x1, + xdata.y1, + xdata.x2 - xdata.x1, + xdata.y2 - xdata.y1, + xdata.waveform, + xdata.flags + ); break; - + } case swtfb::ipc::WAIT_t: std::cerr << "(Unhandled wait message)\n"; // TODO