diff --git a/README.md b/README.md
index d8f72be..8ccb4fe 100644
--- a/README.md
+++ b/README.md
@@ -103,13 +103,13 @@ For all supported platforms,
You can also use "pure" edition once you have [Python 3](https://www.python.org/) installed,
or "bare" edition if you also managed to install `bleak` via `pip`.
-If you like command-line, install [ImageMagick](https://imagemagick.org/) and [Ghostscript](https://ghostscript.com/) and enjoy the integraton.
+If you like command-line, installing [ImageMagick](https://imagemagick.org/) and [Ghostscript](https://ghostscript.com/) could be very helpful.
See the [releases](https://github.com/NaitLee/Cat-Printer/releases) now!
## Problems?
-Please talk in Discussion if there's something in your mind!
+Please use Issue or Discussion if there's something in your mind!
Of course Pull Requests are welcome if you can handle them!
diff --git a/printer.py b/printer.py
index 2a95e5d..57f92ac 100644
--- a/printer.py
+++ b/printer.py
@@ -264,7 +264,7 @@ class PrinterDriver(Commander):
model: Model = None
'The printer model'
- scan_timeout: float = 5.0
+ scan_timeout: float = 4.0
connection_timeout : float = 5.0
@@ -523,7 +523,7 @@ class PrinterDriver(Commander):
self.device.stop_notify(self.rx_characteristic),
self.device.disconnect()
)
- except BleakError:
+ except (BleakError, EOFError):
self.device = None
if self._traffic_dump is not None:
self._traffic_dump.close()
@@ -694,14 +694,19 @@ def main():
'Run the `_main` routine while catching exceptions'
try:
_main()
- except BleakError as e:
+ except (BleakError, AttributeError) as e:
error_message = str(e)
if (
- 'not turned on' in error_message or
- (isinstance(e, BleakDBusError) and
+ ('not turned on' in error_message) or # windows or android
+ (isinstance(e, BleakDBusError) and # linux/dbus/bluetoothctl
getattr(e, 'dbus_error') == 'org.bluez.Error.NotReady')
):
fatal(I18n['please-enable-bluetooth'], code=ExitCodes.GeneralError)
+ elif (
+ (isinstance(e, AttributeError) and # macos, possibly?
+ 'CentralManagerDelegate' in error_message)
+ ):
+ fatal(I18n['please-enable-bluetooth-or-try-to-reboot'], code=ExitCodes.GeneralError)
else:
raise
except PrinterError as e:
diff --git a/readme.i18n/README.zh_CN.md b/readme.i18n/README.zh_CN.md
index 4b8ab69..9131b9a 100644
--- a/readme.i18n/README.zh_CN.md
+++ b/readme.i18n/README.zh_CN.md
@@ -105,7 +105,7 @@ python3 server.py
## 有问题?
-有想法?去 Discussion 讨论!
+有想法?用 Issue 或去 Discussion 讨论!
如果能行,Pull Request 也可以!
diff --git a/server.py b/server.py
index ac6416f..5bc5863 100644
--- a/server.py
+++ b/server.py
@@ -58,7 +58,7 @@ class PrinterServerHandler(BaseHTTPRequestHandler):
'version': 2,
'first_run': True,
'is_android': False,
- 'scan_timeout': 5.0,
+ 'scan_timeout': 4.0,
'dry_run': False
})
_settings_blacklist = (
diff --git a/www/image.js b/www/image.js
index fa10d4e..f9f0a24 100644
--- a/www/image.js
+++ b/www/image.js
@@ -8,9 +8,10 @@
* The result data will be here, as a 8-bit grayscale image data.
* @param {number} w width of image
* @param {number} h height of image
+ * @param {number} t brightness, historically "threshold"
* @param {boolean} transparencyAsWhite whether render opacity as white rather than black
*/
-function monoGrayscale(image_data, mono_data, w, h, transparencyAsWhite) {
+function monoGrayscale(image_data, mono_data, w, h, t, transparencyAsWhite) {
let p, q, r, g, b, a, m;
for (let j = 0; j < h; j++) {
for (let i = 0; i < w; i++) {
@@ -26,6 +27,7 @@ function monoGrayscale(image_data, mono_data, w, h, transparencyAsWhite) {
}
else { r *= a; g *= a; b *= a; }
m = Math.floor(r * 0.2125 + g * 0.7154 + b * 0.0721);
+ m += (t - 128) * (1 - m / 255) * (m / 255) * 2;
mono_data[p] = m;
}
}
@@ -36,14 +38,13 @@ function monoGrayscale(image_data, mono_data, w, h, transparencyAsWhite) {
* @param {Uint8ClampedArray} data the grayscale data, mentioned in `monoGrayscale`. **will be modified in-place**
* @param {number} w width of image
* @param {number} h height of image
- * @param {number} t threshold
*/
-function monoDirect(data, w, h, t) {
- let p;
- for (let j = 0; j < h; j++) {
- for (let i = 0; i < w; i++) {
+function monoDirect(data, w, h) {
+ let p, i, j;
+ for (j = 0; j < h; j++) {
+ for (i = 0; i < w; i++) {
p = j * w + i;
- data[p] = data[p] > t ? 255 : 0;
+ data[p] = data[p] > 128 ? 255 : 0;
}
}
}
@@ -53,10 +54,9 @@ function monoDirect(data, w, h, t) {
* @param {Uint8ClampedArray} data the grayscale data, mentioned in `monoGrayscale`. **will be modified in-place**
* @param {number} w width of image
* @param {number} h height of image
- * @param {number} t threshold
*/
-function monoSteinberg(data, w, h, t) {
- let p, m, n, o;
+function monoSteinberg(data, w, h) {
+ let p, m, n, o, i, j;
function adjust(x, y, delta) {
if (
x < 0 || x >= w ||
@@ -65,12 +65,12 @@ function monoSteinberg(data, w, h, t) {
p = y * w + x;
data[p] += delta;
}
- for (let j = 0; j < h; j++) {
- for (let i = 0; i < w; i++) {
+ for (j = 0; j < h; j++) {
+ for (i = 0; i < w; i++) {
p = j * w + i;
m = data[p];
n = m > 128 ? 255 : 0;
- o = m - n + t;
+ o = m - n;
data[p] = n;
adjust(i + 1, j , o * 7 / 16);
adjust(i - 1, j + 1, o * 3 / 16);
@@ -95,12 +95,12 @@ function monoHalftone(data, w, h, t) {}
*/
function mono2pbm(data, w, h) {
let result = new Uint8ClampedArray(data.length / 8);
- let slice, p;
- for (let i = 0; i < result.length; i++) {
+ let slice, p, i;
+ for (i = 0; i < result.length; i++) {
p = i * 8;
slice = data.slice(p, p + 8);
// Merge 8 bytes to 1 byte, and negate the bits
- // expecting in the data there's only 255 (0b11111111) or 0 (0b00000000)
+ // assuming there's only 255 (0b11111111) or 0 (0b00000000) in the data
result[i] = (
slice[0] & 0b10000000 |
slice[1] & 0b01000000 |
diff --git a/www/index.html b/www/index.html
index 2e10f6d..1d81dcf 100644
--- a/www/index.html
+++ b/www/index.html
@@ -44,8 +44,9 @@
Pattern
-->
-
-
+
+
+
@@ -62,7 +63,7 @@