createBitDiagram method
Function to create a visual diagram of the bits of a byte
Implementation
String createBitDiagram(int statusByte) {
String bits = statusByte.toRadixString(2).padLeft(8, "0");
String diagram = '\n+---+---+---+---+---+---+---+---+\n';
diagram += '| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | Bit\n';
diagram += '+---+---+---+---+---+---+---+---+\n';
diagram +=
'| ${bits[0]} | ${bits[1]} | ${bits[2]} | ${bits[3]} | ${bits[4]} | ${bits[5]} | ${bits[6]} | ${bits[7]} |\n';
diagram += '+---+---+---+---+---+---+---+---+\n';
diagram +=
'| ${(statusByte & 0x80) != 0 ? "E" : " "} | ${(statusByte & 0x40) != 0 ? "F" : " "} | ${(statusByte & 0x20) != 0 ? "C" : " "} | ${(statusByte & 0x10) != 0 ? "?" : " "} | ${(statusByte & 0x08) != 0 ? "O" : " "} | ${(statusByte & 0x04) != 0 ? "D" : " "} | ${(statusByte & 0x02) != 0 ? "d" : " "} | ${(statusByte & 0x01) != 0 ? "R" : " "} |\n';
diagram += '+---+---+---+---+---+---+---+---+\n';
diagram +=
' E=Error, F=Feed, C=Cover, ?=Unknown, O=Offline, D=Drawer, d=drawer2, R=Reserved';
return diagram;
}