From f26f29d84e0a68831a6af14dab3eec5500496d2e Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期三, 28 五月 2025 16:48:52 +0800
Subject: [PATCH] 初始化项目

---
 util/ble/esc.js |  355 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 355 insertions(+), 0 deletions(-)

diff --git a/util/ble/esc.js b/util/ble/esc.js
new file mode 100644
index 0000000..ce26aaa
--- /dev/null
+++ b/util/ble/esc.js
@@ -0,0 +1,355 @@
+var encode = require("./encoding.js")
+var app = getApp();
+var jpPrinter = {銆�銆�銆�銆�
+  createNew: function() {銆�銆�銆�銆�銆�銆�
+    var jpPrinter = {};
+    var data = [];
+
+    var bar = ["UPC-A", "UPC-E", "EAN13", "EAN8", "CODE39", "ITF", "CODABAR", "CODE93", "CODE128"];
+
+    jpPrinter.name = "钃濈墮鎵撳嵃鏈�";
+
+    jpPrinter.init = function() { //鍒濆鍖栨墦鍗版満
+      data.push(27)
+      data.push(64)
+    };
+
+    jpPrinter.setText = function(content) { //璁剧疆鏂囨湰鍐呭
+      var code = new encode.TextEncoder(
+        'gb18030', {
+          NONSTANDARD_allowLegacyEncoding: true
+        }).encode(content)
+      for (var i = 0; i < code.length; ++i) {
+        data.push(code[i])
+      }
+    }
+
+    jpPrinter.setFontSize=function(n){//璁剧疆瀛椾綋澶у皬
+      data.push(29)
+      data.push(33)
+      data.push(n)
+    }
+
+    jpPrinter.bold = function (n) {//鍔犵矖
+      data.push(27)
+      data.push(69)
+      data.push(n)
+    }
+
+    
+    jpPrinter.setUnderline=function(n){//璁剧疆涓嬪垝绾�
+      data.push(27)
+      data.push(45)
+      data.push(n)
+    }
+
+    jpPrinter.setUnderline2 = function (n) {//璁剧疆涓嬪垝绾�
+      data.push(28)
+      data.push(45)
+      data.push(n)
+    }
+
+    // jpPrinter.setBarcodeWidth = function(width) { //璁剧疆鏉$爜瀹藉害
+    //   data.push(29)
+    //   data.push(119)
+    //   if (width > 6) {
+    //     width = 6;
+    //   }
+    //   if (width < 2) {
+    //     width = 1;
+    //   }
+    //   data.push(width)
+    // }
+
+    // jpPrinter.setBarcodeHeight = function(height) { //璁剧疆鏉$爜楂樺害
+    //   data.push(29)
+    //   data.push(104)
+    //   data.push(height)
+    // }
+
+    // jpPrinter.setBarcodeContent = function(t,content) {
+    //   var ty = 73;
+    //   data.push(29)
+    //   data.push(107)
+    //   switch (t) {
+    //     case bar[0]:
+    //       ty = 65;
+    //       break;
+    //     case bar[1]:
+    //       ty = 66;
+    //       break;
+    //     case bar[2]:
+    //       ty = 67;
+    //       break;
+    //     case bar[3]:
+    //       ty = 68;
+    //       break;
+    //     case bar[4]:
+    //       ty = 69;
+    //       break;
+    //     case bar[5]:
+    //       ty = 70;
+    //       break;
+    //     case bar[6]:
+    //       ty = 71;
+    //       break;
+    //     case bar[7]:
+    //       ty = 72;
+    //       break;
+    //     case bar[8]:
+    //       ty = 73;
+    //       break;
+    //   }
+    //   data.push(ty)
+    // }
+
+    jpPrinter.setSelectSizeOfModuleForQRCode = function(n) { //璁剧疆浜岀淮鐮佸ぇ灏�
+      data.push(29)
+      data.push(40)
+      data.push(107)
+      data.push(3)
+      data.push(0)
+      data.push(49)
+      data.push(67)
+      if (n > 15) {
+        n = 15
+      }
+      if (n < 1) {
+        n = 1
+      }
+      data.push(n)
+    }
+
+    jpPrinter.setSelectErrorCorrectionLevelForQRCode = function(n) { //璁剧疆绾犻敊绛夌骇
+      /*
+      n      鍔熻兘      绾犻敊鑳藉姏
+      48 閫夋嫨绾犻敊绛夌骇 L 7
+      49 閫夋嫨绾犻敊绛夌骇 M 15
+      50 閫夋嫨绾犻敊绛夌骇 Q 25
+      51 閫夋嫨绾犻敊绛夌骇 H 30
+      */
+      data.push(29)
+      data.push(40)
+      data.push(107)
+      data.push(3)
+      data.push(0)
+      data.push(49)
+      data.push(69)
+      data.push(n)
+    }
+
+    jpPrinter.setStoreQRCodeData = function(content) { //璁剧疆浜岀淮鐮佸唴瀹�
+      var code = new encode.TextEncoder(
+        'gb18030', {
+          NONSTANDARD_allowLegacyEncoding: true
+        }).encode(content)
+      data.push(29)
+      data.push(40)
+      data.push(107)
+      data.push(parseInt((code.length + 3) % 256))
+      data.push(parseInt((code.length + 3) / 256))
+      data.push(49)
+      data.push(80)
+      data.push(48)
+
+      for (var i = 0; i < code.length; ++i) {
+        data.push(code[i])
+      }
+    }
+
+    jpPrinter.setPrintQRCode = function() { //鎵撳嵃浜岀淮鐮�
+      data.push(29)
+      data.push(40)
+      data.push(107)
+      data.push(3)
+      data.push(0)
+      data.push(49)
+      data.push(81)
+      data.push(48)
+    }
+
+    jpPrinter.setHorTab = function() { //绉诲姩鎵撳嵃浣嶇疆鍒颁笅涓�涓按骞冲畾浣嶇偣鐨勪綅缃�
+      data.push(9)
+    }
+
+    jpPrinter.setAbsolutePrintPosition = function(where) { //璁剧疆缁濆鎵撳嵃浣嶇疆
+      data.push(27)
+      data.push(36)
+      data.push(parseInt(where % 256))
+      data.push(parseInt(where / 256))
+    }
+
+    jpPrinter.setRelativePrintPositon = function(where) { //璁剧疆鐩稿妯悜鎵撳嵃浣嶇疆
+      data.push(27)
+      data.push(92)
+      data.push(parseInt(where % 256))
+      data.push(parseInt(where / 256))
+    }
+
+    jpPrinter.setSelectJustification = function(which) { //瀵归綈鏂瑰紡
+      /*
+      0, 48 宸﹀榻�
+      1, 49 涓棿瀵归綈
+      2, 50 鍙冲榻�
+      */
+      data.push(27)
+      data.push(97)
+      data.push(which)
+    }
+
+    jpPrinter.space = function (n) { //璁剧疆妯悜璺虫牸浣嶇疆
+      data.push(27)
+      data.push(68)
+      data.push(n)
+    }
+
+
+    jpPrinter.setLeftMargin = function(n) { //璁剧疆宸﹁竟璺�
+      data.push(29)
+      data.push(76)
+      data.push(parseInt(n % 256))
+      data.push(parseInt(n / 256))
+    }
+
+    jpPrinter.textMarginRight = function (n) { //璁剧疆瀛楃鍙抽棿璺�
+      data.push(27)
+      data.push(32)
+      data.push(n)
+    }
+
+    jpPrinter.rowSpace = function (n) { //璁剧疆琛岄棿璺�
+      data.push(27)
+      data.push(51)
+      data.push(n)
+    }
+
+    jpPrinter.setPrintingAreaWidth = function(width) { //璁剧疆鎵撳嵃鍖哄煙瀹藉害
+      data.push(29)
+      data.push(87)
+      data.push(parseInt(width % 256))
+      data.push(parseInt(width / 256))
+    }
+
+    jpPrinter.setSound = function(n, t) { //璁剧疆铚傞福鍣�
+      data.push(27)
+      data.push(66)
+      if (n < 0) {
+        n = 1;
+      } else if (n > 9) {
+        n = 9;
+      }
+
+      if (t < 0) {
+        t = 1;
+      } else if (t > 9) {
+        t = 9;
+      }
+      data.push(n)
+      data.push(t)
+    }
+
+    jpPrinter.setBitmap = function(res) { //鍙傛暟锛岀敾甯冪殑鍙傛暟
+      console.log(res)
+      var width = parseInt((res.width + 7) / 8 * 8 / 8)
+      var height = res.height;
+      var time = 1;
+      var temp = res.data.length - width * 32;
+      var point_list = []
+      console.log(width + "--" + height)
+      data.push(29)
+      data.push(118)
+      data.push(48)
+      data.push(0)
+      data.push((parseInt((res.width + 7) / 8) * 8) / 8)
+      data.push(0)
+      data.push(parseInt(res.height % 256))
+      data.push(parseInt(res.height / 256))
+      console.log(res.data.length)
+      console.log("temp=" + temp)
+      for (var i = 0; i < height; ++i) {
+        for (var j = 0; j < width; ++j) {
+          for (var k = 0; k < 32; k += 4) {
+            var po = {}
+            if (res.data[temp] == 0 && res.data[temp + 1] == 0 && res.data[temp + 2] == 0 && res.data[temp + 3] == 0) {
+              po.point = 0;
+            } else {
+              po.point = 1;
+            }
+            point_list.push(po)
+            temp += 4
+          }
+        }
+        time++
+        temp = res.data.length - width * 32 * time
+      }
+      for (var i = 0; i < point_list.length; i += 8) {
+        var p = point_list[i].point * 128 + point_list[i + 1].point * 64 + point_list[i + 2].point * 32 + point_list[i + 3].point * 16 + point_list[i + 4].point * 8 + point_list[i + 5].point * 4 + point_list[i + 6].point * 2 + point_list[i + 7].point
+        data.push(p)
+      }
+    }
+
+    jpPrinter.setPrint = function() { //鎵撳嵃骞舵崲琛�
+      data.push(10)
+    }
+
+    jpPrinter.setPrintAndFeed = function(feed) { //鎵撳嵃骞惰蛋绾竑eed涓崟浣�
+      data.push(27)
+      data.push(74)
+      data.push(feed)
+    }
+
+    jpPrinter.setPrintAndFeedRow = function(row) { //鎵撳嵃骞惰蛋绾竢ow琛�
+      data.push(27)
+      data.push(100)
+      data.push(row)
+    }
+
+    jpPrinter.getData = function() { //鑾峰彇鎵撳嵃鏁版嵁
+      return data;
+    };
+
+    銆�銆�
+    return jpPrinter;銆�
+  },
+
+  Query: function() {
+    var queryStatus = {};
+    var buf;
+    var dateView;
+    queryStatus.getRealtimeStatusTransmission = function(n) { //鏌ヨ鎵撳嵃鏈哄疄鏃剁姸鎬�
+      /*
+      n = 1锛氫紶閫佹墦鍗版満鐘舵��
+      n = 2锛氫紶閫佽劚鏈虹姸鎬�
+      n = 3锛氫紶閫侀敊璇姸鎬�
+      n = 4锛氫紶閫佺焊浼犳劅鍣ㄧ姸鎬�
+      */
+      buf = new ArrayBuffer(3)
+      dateView = new DataView(buf)
+      dateView.setUint8(0, 16)
+      dateView.setUint8(1, 4)
+      dateView.setUint8(2, n)
+      queryStatus.query(buf)
+    }
+
+    queryStatus.query = function(buf) {
+      wx.writeBLECharacteristicValue({
+        deviceId: app.BLEInformation.deviceId,
+        serviceId: app.BLEInformation.writeServiceId,
+        characteristicId: app.BLEInformation.writeCharaterId,
+        value: buf,
+        success: function(res) {
+
+        },
+        complete: function(res) {
+          console.log(res)
+          buf = null
+          dateView = null;
+        }
+      })
+    }
+    return queryStatus;
+  }
+
+};
+
+module.exports.jpPrinter = jpPrinter;
\ No newline at end of file

--
Gitblit v1.9.3