mirror of
https://github.com/NaitLee/Cat-Printer.git
synced 2025-05-15 23:00:15 -07:00
a bit code review
This commit is contained in:
parent
49b2a9a008
commit
4fa145459b
10
printer.py
10
printer.py
@ -315,7 +315,10 @@ class PrinterDriver(Commander):
|
||||
|
||||
def loop(self, *futures):
|
||||
''' Run coroutines in order in current event loop until complete,
|
||||
return its result directly, or their result as tuple
|
||||
return its result directly, or their result as tuple.
|
||||
|
||||
This 1) ensures exiting gracefully (futures always get completed before exiting),
|
||||
and 2) avoids function colors (use of "await", especially outside this script)
|
||||
'''
|
||||
results = []
|
||||
for future in futures:
|
||||
@ -344,9 +347,9 @@ class PrinterDriver(Commander):
|
||||
self.model = Models[name]
|
||||
self.device = BleakClient(address)
|
||||
def notify(_char, data):
|
||||
if data == b'\x51\x78\xae\x01\x01\x00\x10\x70\xff':
|
||||
if data == self.data_flow_pause:
|
||||
self._paused = True
|
||||
elif data == b'\x51\x78\xae\x01\x01\x00\x00\x00\xff':
|
||||
elif data == self.data_flow_resume:
|
||||
self._paused = False
|
||||
self.loop(
|
||||
self.device.connect(timeout=self.connection_timeout),
|
||||
@ -371,6 +374,7 @@ class PrinterDriver(Commander):
|
||||
name, address = identifier.split(',')
|
||||
if name not in Models:
|
||||
error('model-0-is-not-supported-yet', name, exception=PrinterError)
|
||||
# TODO: is this logic correct?
|
||||
if address[2::3] != ':::::' and len(address.replace('-', '')) != 32:
|
||||
error('invalid-address-0', address, exception=PrinterError)
|
||||
if use_result:
|
||||
|
@ -1,5 +1,5 @@
|
||||
'''
|
||||
Cat-Printer Commander, way to communicate with cat printers via bluetooth
|
||||
Cat-Printer Commander(s), binary interface(s) to communicate with cat printers
|
||||
|
||||
No rights reserved.
|
||||
License CC0-1.0-only: https://directory.fsf.org/wiki/License:CC0
|
||||
@ -65,10 +65,17 @@ def int_to_bytes(i: int, big_endian=False):
|
||||
return result
|
||||
|
||||
class Commander(metaclass=ABCMeta):
|
||||
'Semi-abstract class, to be inherited by `PrinterDriver`'
|
||||
''' Semi-abstract class, to be inherited by `PrinterDriver`
|
||||
Contains binary data communication interface for individual functions
|
||||
"Commander" of kind of printers like GB0X, GT01
|
||||
Class structure is not guaranteed to be stable
|
||||
'''
|
||||
|
||||
dry_run: bool = False
|
||||
|
||||
data_flow_pause = b'\x51\x78\xae\x01\x01\x00\x10\x70\xff'
|
||||
data_flow_resume = b'\x51\x78\xae\x01\x01\x00\x00\x00\xff'
|
||||
|
||||
def make_command(self, command_bit, payload: bytearray, *,
|
||||
prefix=bytearray(), suffix=bytearray()):
|
||||
'Make bytes that to be used to control printer'
|
||||
|
@ -45,7 +45,7 @@
|
||||
<span data-i18n="brightness-">Brightness:</span>
|
||||
<input type="range" min="0" max="256" value="86" step="16" name="threshold" data-key data-default />
|
||||
</label>
|
||||
<!-- "Strength", so-called "darkness", or internally "energy" -->
|
||||
<!-- Thermal "Strength", so-called "darkness", or internally "energy" -->
|
||||
<label class="label-span-input" data-hide-as="print">
|
||||
<span data-i18n="strength-">Strength:</span>
|
||||
<input type="range" min="0" max="256" value="64" step="16" name="energy" data-key data-default />
|
||||
@ -147,7 +147,7 @@
|
||||
</div>
|
||||
</main>
|
||||
<div id="hidden" class="hard-hidden">
|
||||
<!-- Hidden area for putting elements -->
|
||||
<!-- Hidden area for putting dynamic elements -->
|
||||
<input type="file" id="file" />
|
||||
<img src="" id="img" alt="hidden-image" />
|
||||
<div id="accessibility">
|
||||
|
@ -822,7 +822,7 @@ class Main {
|
||||
|
||||
if (this.settings['is_android']) {
|
||||
document.body.classList.add('android');
|
||||
// select[multiple] doesn't work well with Android
|
||||
// select[multiple] doesn't work well with Android WebView
|
||||
let div = document.createElement('div');
|
||||
let select = document.getElementById('select-language');
|
||||
Array.from(select.children).forEach(e => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user