Skip to content

Commit

Permalink
Important fixes to 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NaitLee committed May 7, 2022
1 parent 367c901 commit 39e29de
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ build-android/dist
*.apk
*.apk.*
cat-printer*.zip
*-sha256.txt
cat-printer-sha256-*.txt
# bleak, the bare pip package as a folder
build-common/bleak
# python embeddable package, with bleak_winrt inside
Expand Down
4 changes: 2 additions & 2 deletions 1-build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
# For ultimate laziness!
rm -rf cat-printer-*.zip cat-printer-*.apk* cat-printer-*-sha256.txt
rm -rf cat-printer-*.zip cat-printer-*.apk* cat-printer-sha256-*.txt
echo -n 'Version tag: '
read version
echo -n $version > version
Expand All @@ -16,5 +16,5 @@ echo 'Signing apk with keyfile...'
./4-sign.sh $signkey
cd ../
echo 'SHA256 Hash...'
sha256sum cat-printer-* > cat-printer-$version-sha256.txt
sha256sum cat-printer-* > cat-printer-sha256-$version.txt
echo 'Complete!'
27 changes: 17 additions & 10 deletions printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class PrinterError(Exception):
def __init__(self, *args):
super().__init__(*args)
self.message = args[0]
self.message_localized = i18n(args)
self.message_localized = i18n(*args)

class PrinterData():
''' The image data to be used by `PrinterDriver`.
Expand Down Expand Up @@ -277,6 +277,7 @@ class PrinterDriver(Commander):
rtl: bool = False

energy: int = None
quality: int = 24

mtu: int = 200

Expand Down Expand Up @@ -427,20 +428,23 @@ def send(self, data):

def _prepare(self):
self.get_device_state()
self.set_dpi_as_200()
self.use_energy_control(True)
if self.energy is not None:
self.set_energy(self.energy * 0xff)
if self.model.is_new_kind:
self.start_printing_new()
else:
self.start_printing()
self.set_speed(8) # already fine if above 4. maybe just enough
self.get_device_state()
self.set_dpi_as_200()
if self.quality: # well, slower makes stable heating
self.set_speed(self.quality)
if self.energy is not None:
self.set_energy(self.energy * 0xff)
self.apply_energy()
self.update_device()
self.flush()
self.start_lattice()

def _finish(self):
self.end_lattice()
self.set_speed(8)
self.feed_paper(128)
self.get_device_state()
self.flush()
Expand All @@ -450,7 +454,6 @@ def _print_bitmap(self, data: PrinterData):
flip(data.data, data.width, data.height, self.flip_h, self.flip_v, overwrite=True)
self._prepare()
# TODO: consider compression on new devices
self.start_lattice()
for chunk in data.read(paper_width // 8):
if self.dry_run:
chunk = b'\x00' * len(chunk)
Expand Down Expand Up @@ -615,8 +618,10 @@ def _main():
help=i18n('image-printing-options'))
parser.add_argument('-t', '--text', metavar='Size[,FontFamily][,pf2][,nowrap][,rtl]', type=str,
default='', help=i18n('text-printing-mode-with-options'))
parser.add_argument('-e', '--energy', metavar='<0.0-1.0>', type=float, default=None,
parser.add_argument('-e', '--energy', metavar='0.0-1.0', type=float, default=None,
help=i18n('control-printer-thermal-strength'))
parser.add_argument('-q', '--quality', metavar='1-4', type=int, default=3,
help=i18n('print-quality'))
parser.add_argument('-d', '--dry', action='store_true',
help=i18n('dry-run-test-print-process-only'))
parser.add_argument('-f', '--fake', metavar='XY01', type=str, default='',
Expand All @@ -638,7 +643,9 @@ def _main():
printer.scan_timeout = float(scan_param[0])
identifier = ','.join(scan_param[1:])
if args.energy is not None:
printer.energy = args.energy * 0xff
printer.energy = int(args.energy * 0xff)
if args.quality is not None:
printer.quality = 4 * (args.quality + 5)

image_param = args.image.split(',')
if 'flip' in image_param:
Expand Down
8 changes: 3 additions & 5 deletions printer_lib/commander.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@ def start_printing_new(self):
'Start printing on newer printers'
self.send( bytearray([0x12, 0x51, 0x78, 0xa3, 0x00, 0x01, 0x00, 0x00, 0x00, 0xff]) )

def use_energy_control(self, enable: bool):
''' Whether enable energy control (with set_energy) or not
Note: I remember I can't disable it, when I (incorrectly)
thought it was "image/text mode"
def apply_energy(self):
''' Apply previously set energy to printer
'''
self.send( self.make_command(0xbe, int_to_bytes(0x01 if enable else 0x00)) )
self.send( self.make_command(0xbe, int_to_bytes(0x01)) )

def get_device_state(self):
'(unknown). seems it could refresh device state & apply config'
Expand Down
1 change: 1 addition & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def update_printer(self):
self.printer.fake = self.settings.fake
self.printer.dump = self.settings.dump
self.printer.energy = self.settings.energy
self.printer.quality = self.settings.quality
self.printer.flip_h = self.settings.flip_h or self.settings.flip
self.printer.flip_v = self.settings.flip_v or self.settings.flip
self.printer.rtl = self.settings.force_rtl
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.0
0.5.1
32 changes: 19 additions & 13 deletions www/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,25 @@ <h1 data-i18n="cat-printer">Cat Printer</h1>
<a target="_blank" href="https://github.com/NaitLee/Cat-Printer">GitHub</a>
</p>
<h2 data-i18n="contributors">Contributors</h2>
<dl>
<dt>
<a target="_blank" href="https://github.com/NaitLee">NaitLee</a>
</dt>
<dd data-i18n="developer">Developer</dd>
<dt>
<a target="_blank" href="https://github.com/frankenstein91">frankenstein91</a>
</dt>
<dd data-i18n="developer">Developer</dd>
<dd data-i18n="translator">Translator</dd>
<dt data-i18n="all-testers-and-users">All testers & users</dt>
<dd data-i18n="everyone-is-awesome">Everyone is awesome!</dd>
</dl>
<div class="contributors">
<dl>
<dt>
<a target="_blank" href="https://github.com/NaitLee">NaitLee</a>
</dt>
<dd data-i18n="developer">Developer</dd>
</dl>
<dl>
<dt>
<a target="_blank" href="https://github.com/frankenstein91">frankenstein91</a>
</dt>
<dd data-i18n="developer">Developer</dd>
<dd data-i18n="translator">Translator</dd>
</dl>
<dl>
<dt data-i18n="all-testers-and-users">All testers & users</dt>
<dd data-i18n="everyone-is-awesome">Everyone is awesome!</dd>
</dl>
</div>
<h2 data-i18n="copyright-and-license">Copyright</h2>
<p>
<span>Copyright &copy; 2021-2022 NaitLee Soft.</span>
Expand Down
49 changes: 30 additions & 19 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,38 @@ <h1 id="title" data-i18n="cat-printer">Cat Printer</h1>
</select>
<button id="device-refresh" data-i18n="refresh" data-key>Refresh</button>
<hr />
<label data-i18n="process-as-">Process as:</label>
<label>
<input type="radio" name="algo" value="algo-direct" data-key />
<span data-i18n="text">Text</span>
</label>
<label>
<input type="radio" name="algo" value="algo-steinberg" data-key checked />
<span data-i18n="picture">Picture</span>
</label>
<!-- <label>
<input type="radio" name="algo" value="algo-halftone" data-key />
<span data-i18n="pattern">Pattern</span>
</label> --><br />
<dl>
<dt><label data-i18n="process-as-">Process as:</label></dt>
<dd>
<label>
<input type="radio" name="algo" value="algo-direct" data-key />
<span data-i18n="text">Text</span>
</label>
<label>
<input type="radio" name="algo" value="algo-steinberg" data-key checked />
<span data-i18n="picture">Picture</span>
</label>
</dd>
<!-- <label>
<input type="radio" name="algo" value="algo-halftone" data-key />
<span data-i18n="pattern">Pattern</span>
</label> -->
</dl>
<!-- "brightness" is historically "threshold" -->
<label for="threshold" data-i18n="brightness-">Brightness:</label>
<input type="range" min="0" max="256" value="86" step="16" id="threshold" data-key data-default />
<br />
<dl>
<dt><label for="threshold" data-i18n="brightness-">Brightness:</label></dt>
<dd><input type="range" min="0" max="256" value="86" step="16" id="threshold" data-key data-default /></dd>
</dl>
<!-- "Strength", so-called "darkness", or internally "energy" -->
<label for="energy" data-i18n="strength-">Strength:</label>
<input type="range" min="0" max="256" value="64" step="16" id="energy" data-key data-default />
<br />
<dl>
<dt><label for="energy" data-i18n="strength-">Strength:</label></dt>
<dd><input type="range" min="0" max="256" value="64" step="16" id="energy" data-key data-default /></dd>
</dl>
<!-- "Quality", just speed of paper feeding, but slower makes better heating -->
<dl>
<dt><label for="quality" data-i18n="quality-">Quality:</label></dt>
<dd><input type="range" min="24" max="36" value="32" step="4" id="quality" data-key data-default /></dd>
</dl>
<input type="checkbox" name="transparent-as-white" id="transparent-as-white" data-key checked />
<label for="transparent-as-white" data-i18n="transparent-as-white">Transparent as White</label>
</div>
Expand Down
4 changes: 3 additions & 1 deletion www/lang/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,7 @@
"strength-": "Strength:",
"or-drag-file-to-below": "Or drag file to below",
"reset": "Reset",
"cat-face-toward": "Cat Face Toward"
"cat-face-toward": "Cat Face Toward",
"quality-": "Quality:",
"print-quality": "Print quality"
}
4 changes: 3 additions & 1 deletion www/lang/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,7 @@
"strength-": "力度:",
"or-drag-file-to-below": "或拖拽文件至下方",
"reset": "重置",
"cat-face-toward": "猫脸朝上"
"cat-face-toward": "猫脸朝上",
"quality-": "质量:",
"print-quality": "打印质量"
}
12 changes: 9 additions & 3 deletions www/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ p {
height: calc(var(--panel-height) - var(--compact-menu-height));
padding: var(--span-double) var(--span);
box-sizing: border-box;
/* overflow-y: scroll; */
overflow-y: scroll;
}
.panel.sub.active {
height: calc(var(--panel-height) / 2);
Expand Down Expand Up @@ -284,8 +284,14 @@ dl {
margin: var(--span) 0;
display: block;
}
dd { display: inline; }
dd+dd { margin-left: var(--font-size); }
dt { display: inline-block; min-width: 6em; text-align: end; }
dd { display: inline-block; margin: 0 calc(var(--font-size) / 4); }
.contributors dt {
min-width: 12em;
text-align: center;
padding: 0 calc(var(--font-size) / 4);
border-right: var(--border) solid var(--fore-color);
}
hr {
border: none;
border-top: var(--border) solid var(--fore-color);
Expand Down
3 changes: 2 additions & 1 deletion www/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class CanvasController {
this.algorithm = name;
this.threshold = CanvasController.defaultThreshold;
this._thresholdRange.dispatchEvent(new Event('change'));
this.energy = name == 'algo-direct' ? 72 : 48;
this.energy = name == 'algo-direct' ? 96 : 64;
this._energyRange.dispatchEvent(new Event('change'));
this.activatePreview();
}
Expand Down Expand Up @@ -590,6 +590,7 @@ class Main {
);
this.attachSetter('#threshold', 'change', 'threshold');
this.attachSetter('#energy', 'change', 'energy');
this.attachSetter('#quality', 'change', 'quality');
this.attachSetter('#flip', 'change', 'flip');
// this.attachSetter('#flip-h', 'change', 'flip_h');
// this.attachSetter('#flip-v', 'change', 'flip_v');
Expand Down

0 comments on commit 39e29de

Please sign in to comment.