| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603 | 
							- var encode = require("./encoding.js")
 
- var app = getApp();
 
- var dlabelPrinter = {
 
-     createNew: function () {
 
-         var dlabelPrinter = {};
 
-         var data = [];
 
-         var bar = ["UPC-A", "UPC-E", "EAN13", "EAN8", "CODE39", "ITF", "CODABAR", "CODE93", "CODE128"];
 
-         dlabelPrinter.name = "蓝牙打印机";
 
-         dlabelPrinter.init = function () {
 
-             data.push(27)
 
-             data.push(64)
 
-         };
 
-         dlabelPrinter.setPrint = function () {
 
-             data.push(10)
 
-         };
 
-         dlabelPrinter.setPrintAndFeed = function (n) {
 
-             data.push(27)
 
-             data.push(74)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setPrintAndFeedRow = function (n) {
 
-             data.push(27)
 
-             data.push(100)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setHorTab = function () {
 
-             data.push(9)
 
-         };
 
-         dlabelPrinter.setAbsolutePrintPosition = function (where) {
 
-             data.push(27)
 
-             data.push(36)
 
-             data.push(parseInt(where % 256))
 
-             data.push(parseInt(where / 256))
 
-         };
 
-         dlabelPrinter.setRelativePrintPositon = function (where) { 
 
-             data.push(27)
 
-             data.push(92)
 
-             data.push(parseInt(where % 256))
 
-             data.push(parseInt(where / 256))
 
-         };
 
-         dlabelPrinter.setSelectJustification = function (which) {
 
-             data.push(27)
 
-             data.push(97)
 
-             data.push(which)
 
-         };
 
-         dlabelPrinter.setLeftMargin = function (n) {
 
-             data.push(29)
 
-             data.push(76)
 
-             data.push(parseInt(n % 256))
 
-             data.push(parseInt(n / 256))
 
-         };
 
-         dlabelPrinter.setPrintingAreaWidth = function (width) {
 
-             data.push(29)
 
-             data.push(87)
 
-             data.push(parseInt(width % 256))
 
-             data.push(parseInt(width / 256))
 
-         };
 
-         dlabelPrinter.setHorizontalAndVertical = function (x, y) {
 
-             data.push(29)
 
-             data.push(80)
 
-             data.push(x)
 
-             data.push(y)
 
-         };
 
-         dlabelPrinter.setCashboxPulse = function (n, m, t) {
 
-             data.push(16)
 
-             data.push(20)
 
-             data.push(n)
 
-             data.push(m)
 
-             data.push(t)
 
-         };
 
-         dlabelPrinter.setPrintPageSignal = function (n) {
 
-             data.push(27)
 
-             data.push(99)
 
-             data.push(51)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setSensorToStopPrint = function (n) {
 
-             data.push(27)
 
-             data.push(99)
 
-             data.push(52)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setSelectKey = function (n) {
 
-             data.push(27)
 
-             data.push(99)
 
-             data.push(53)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setCashCashboxPulse = function (m, t1, t2) {
 
-             data.push(27)
 
-             data.push(112)
 
-             data.push(m)
 
-             data.push(t1)
 
-             data.push(t2)
 
-         };
 
-         dlabelPrinter.setSelectPrinter = function (n) {
 
-             data.push(27)
 
-             data.push(112)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setDefaultLineSpace = function () {
 
-             data.push(27)
 
-             data.push(50)
 
-         };
 
-         dlabelPrinter.setLineSpace = function (n) {
 
-             data.push(27)
 
-             data.push(51)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setCharacterRightSpace = function (n) {
 
-             data.push(27)
 
-             data.push(32)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setPrintMode = function (mode) {
 
-             data.push(27)
 
-             data.push(33)
 
-             data.push(mode)
 
-         }
 
-         dlabelPrinter.setUserDefinitionCharacter = function (n) {
 
-             data.push(27)
 
-             data.push(37)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setUnderlineMode = function (n) {
 
-             data.push(27)
 
-             data.push(45)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setCancleUserDefinitionCharacter = function (n) {
 
-             data.push(27)
 
-             data.push(63)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setBoldMode = function (n) {
 
-             data.push(27)
 
-             data.push(69)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setDoublePrintMode = function (n) {
 
-             data.push(27)
 
-             data.push(71)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setSelectFont = function (n) {
 
-             data.push(27)
 
-             data.push(77)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setInternationalCharacters = function (n) {
 
-             data.push(27)
 
-             data.push(82)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setRotate90 = function (n) {
 
-             data.push(27)
 
-             data.push(86)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setCodePage = function (n) {
 
-             data.push(27)
 
-             data.push(116)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setInvertPrintMode = function (n) {
 
-             data.push(27)
 
-             data.push(123)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setCharacterSize = function (n) {
 
-             data.push(29)
 
-             data.push(33)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setReverseMode = function (n) {
 
-             data.push(29)
 
-             data.push(66)
 
-             data.push(n)
 
-         };
 
-         function convertPartialToBitmap(w, start_y, bith, pitch, res) {
 
-             console.log('convert bitmap: ' + w + ', ' + start_y + ', ' + bith + ', ' + pitch);
 
-             var bits = new Uint8Array(bith * pitch);
 
-             data.push(29)
 
-             data.push(118)
 
-             data.push(48)
 
-             data.push(0)
 
-             data.push(parseInt(pitch % 256));
 
-             data.push(parseInt(pitch / 256));
 
-             data.push(parseInt(bith % 256));
 
-             data.push(parseInt(bith / 256));
 
-             for (var y = 0; y < bith; y++) {
 
-                 for (var x = 0; x < w; x++) {
 
-                     var color = res.data[((y + start_y) * w + x) * 4];
 
-                     if (color < 128) {
 
-                         bits[parseInt(y * pitch + x / 8)] |= (0x80 >> (x % 8));
 
-                     }
 
-                 }
 
-             }
 
-             for (var i = 0; i < bits.length; i++) {
 
-                 data.push(bits[i]);
 
-             }
 
-         }
 
-         function convertToMultiBitmap(res) {
 
-             var w = res.width;
 
-             var h = res.height;
 
-             const BLOCK_SIZE = 128;
 
-             var pitch = parseInt((w + 7) / 8);
 
-             var block = parseInt((h + BLOCK_SIZE - 1) / BLOCK_SIZE);
 
-             console.log(w + "--" + h);
 
-             for (var i = 0; i < block; i++) {
 
-                 var bith = BLOCK_SIZE;
 
-                 if (i * BLOCK_SIZE + bith > h) {
 
-                     bith = h - i * BLOCK_SIZE;
 
-                 }
 
-                 convertPartialToBitmap(w, i * BLOCK_SIZE, bith, pitch, res);
 
-             }
 
-             console.log(data);
 
-         }
 
-         function convertToSingleBitmap(res) {
 
-             console.log(res)
 
-             var w = res.width;
 
-             var h = res.height;
 
-             var bitw = parseInt((w + 7) / 8) * 8;
 
-             var bith = h;
 
-             var pitch = parseInt(bitw / 8);
 
-             var bits = new Uint8Array(bith * pitch);
 
-             console.log(w + "--" + h);
 
-             console.log("bitw=" + bitw + ", bith=" + bith + ", pitch=" + pitch);
 
-             data.push(29)
 
-             data.push(118)
 
-             data.push(48)
 
-             data.push(0)
 
-             data.push(parseInt(pitch % 256));
 
-             data.push(parseInt(pitch / 256));
 
-             data.push(parseInt(bith % 256));
 
-             data.push(parseInt(bith / 256));
 
-             console.log(res.data.length)
 
-             for (var y = 0; y < h; y++) {
 
-                 for (var x = 0; x < w; x++) {
 
-                     var color = res.data[(y * w + x) * 4];
 
-                     if (color < 128) {
 
-                         bits[parseInt(y * pitch + x / 8)] |= (0x80 >> (x % 8));
 
-                     }
 
-                 }
 
-             }
 
-             for (var i = 0; i < bits.length; i++) {
 
-                 data.push(bits[i]);
 
-             }
 
-         }
 
-         dlabelPrinter.setBitmap = function (res) {
 
-             console.log(res)
 
-             convertToSingleBitmap(res)
 
-             console.log(data);
 
-         };
 
-         dlabelPrinter.setHRIPosition = function (position) {
 
-             data.push(29)
 
-             data.push(72)
 
-             data.push(position)
 
-         };
 
-         dlabelPrinter.setHRIFont = function (font) {
 
-             data.push(29)
 
-             data.push(102)
 
-             data.push(font)
 
-         };
 
-         dlabelPrinter.setBarcodeWidth = function (width) {
 
-             data.push(29)
 
-             data.push(119)
 
-             if (width > 6) {
 
-                 width = 6;
 
-             }
 
-             if (width < 2) {
 
-                 width = 1;
 
-             }
 
-             data.push(width)
 
-         };
 
-         dlabelPrinter.setBarcodeHeight = function (height) {
 
-             data.push(29)
 
-             data.push(104)
 
-             data.push(height)
 
-         };
 
-         dlabelPrinter.setCode128 = function (content) {
 
-             data.push(29)
 
-             data.push(107)
 
-             data.push(73)
 
-             var code = new encode.TextEncoder(
 
-                 'gb18030', {
 
-                     NONSTANDARD_allowLegacyEncoding: true
 
-                 }).encode(content)
 
-             data.push(code.length)
 
-             for (var i = 0; i < code.length; ++i) {
 
-                 data.push(code[i])
 
-             }
 
-         };
 
-         dlabelPrinter.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)
 
-             data.push(content)
 
-         };
 
-         dlabelPrinter.setChineseCharacterMode = function (n) {
 
-             data.push(28)
 
-             data.push(33)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setSelectChineseCharacter = function () {
 
-             data.push(28)
 
-             data.push(38)
 
-         };
 
-         dlabelPrinter.setCancelChineseCharacter = function () {
 
-             data.push(28)
 
-             data.push(46)
 
-         };
 
-         dlabelPrinter.setCancelUnderLine = function (n) {
 
-             data.push(28)
 
-             data.push(45)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setChineseCharacterSpace = function (n1, n2) {
 
-             data.push(28)
 
-             data.push(83)
 
-             data.push(n1)
 
-             data.push(n2)
 
-         };
 
-         dlabelPrinter.setChineseCharacteHeightWidth = function (n) {
 
-             data.push(28)
 
-             data.push(87)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.setBlackMaskOffset = function (p, a, m, n) {
 
-             data.push(29)
 
-             data.push(40)
 
-             data.push(70)
 
-             data.push(p % 256)
 
-             data.push(p / 256)
 
-             data.push(a)
 
-             data.push(m)
 
-             data.push(n % 256)
 
-             data.push(n / 256)
 
-         };
 
-         dlabelPrinter.setBlackMarkStart = function () {
 
-             data.push(29)
 
-             data.push(12)
 
-         };
 
-         dlabelPrinter.setCutter = function () {
 
-             data.push(29)
 
-             data.push(86)
 
-             data.push(1)
 
-         };
 
-         dlabelPrinter.setCut = function (n) {
 
-             data.push(29)
 
-             data.push(86)
 
-             data.push(101)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.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)
 
-         };
 
-         dlabelPrinter.setOrderTip = function (m, t, n) {
 
-             data.push(27)
 
-             data.push(67)
 
-             if (m < 0) {
 
-                 m = 1;
 
-             } else if (m > 20) {
 
-                 n = 20;
 
-             }
 
-             if (t < 0) {
 
-                 t = 1;
 
-             } else if (t > 20) {
 
-                 t = 20;
 
-             }
 
-             if (n < 0) {
 
-                 n = 1;
 
-             } else if (n > 3) {
 
-                 n = 3;
 
-             }
 
-             data.push(m)
 
-             data.push(t)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.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)
 
-         };
 
-         dlabelPrinter.setSelectErrorCorrectionLevelForQRCode = function (n) {
 
-             data.push(29)
 
-             data.push(40)
 
-             data.push(107)
 
-             data.push(3)
 
-             data.push(0)
 
-             data.push(49)
 
-             data.push(69)
 
-             data.push(n)
 
-         };
 
-         dlabelPrinter.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])
 
-             }
 
-         };
 
-         dlabelPrinter.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)
 
-         };
 
-         dlabelPrinter.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])
 
-             }
 
-         };
 
-         dlabelPrinter.setUserCommand = function (content) {
 
-             data.push(content)
 
-         };
 
-         dlabelPrinter.getData = function () {
 
-             return data;
 
-         };
 
-         dlabelPrinter.clearData = function () {
 
-             if (data.length > 0) {
 
-                 data.clearData
 
-             }
 
-         };
 
-         return dlabelPrinter;
 
-     },
 
-     Query: function () {
 
-         var queryStatus = {};
 
-         var buf;
 
-         var dateView;
 
-         queryStatus.getRealtimeStatusTransmission = function (n) {
 
-             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.dlabelPrinter = dlabelPrinter;
 
 
  |