Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Get xochitl working through rm2fb-client #17

Open
wants to merge 1 commit into
base: immediate
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions lib/waveform_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,17 +760,9 @@ auto decode_fpl_number(const std::string& barcode) -> std::int16_t

} // anonymous namespace

auto WaveformTable::discover_wbf_file() -> std::optional<std::string>
auto scan_wbf_dir(const std::string& path, std::int16_t fpl_lot) -> std::optional<std::string>
{
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;
}
Expand All @@ -794,8 +786,27 @@ auto WaveformTable::discover_wbf_file() -> std::optional<std::string>
continue;
}
}

return {};
}

auto WaveformTable::discover_wbf_file() -> std::optional<std::string>
{
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
68 changes: 43 additions & 25 deletions src/rm2fb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,42 @@ 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<Waved::Intensity> 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<Waved::Intensity> 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) {
immediate = true;
}

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);
}
Expand Down Expand Up @@ -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
Expand Down