1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- module.exports = {
- // buffer 转16进制
- buf2hex:function (buffer) {
- // create a byte array (Uint8Array) that we can use to read the array buffer
- const byteArray = new Uint8Array(buffer);
- // for each element, we want to get its two-digit hexadecimal representation
- const hexParts = [];
- for(let i = 0; i < byteArray.length; i++) {
- // convert value to hexadecimal
- const hex = byteArray[i].toString(16);
- // pad with zeros to length 2
- const paddedHex = ('00' + hex).slice(-2);
- // push to array
- hexParts.push(paddedHex);
- }
- // join all the hex values of the elements into a single string
- return hexParts.join('');
- },
- // 足压数据补齐点位为60*60 并进行点扩散
- setPressureData:function (data) {
- let dataAll = []
- // 补到之前 60*60 个点位
- for (let j =0;j<60;j++) {
- dataAll[j] = []
- for (let k =0;k<60;k++) {
- if(typeof (data[j]) == 'undefined') {
- dataAll[j][k] = 0
- } else {
- if(typeof (data[j][k]) == 'undefined') {
- dataAll[j][k] = 0
- } else {
- dataAll[j][k] = data[j][k]
- }
- }
- }
- }
- return pressureDataProcess(dataAll,1,4)
- },
- }
- function pressureDataProcess(a,scale,size) {
- var height = 60;
- var width = 60;
- var newHeight = 60*scale;
- var newWidth = 60*scale;
- var u =0.0;
- var v = 0.0;
- var x = 0.0;
- var y = 0.0;
- var m = 0;
- var n = 0;
- let temp = new Array()
- let rearr = []
- for(let i = 0;i<newHeight;++i) {
- temp[i] = new Array()
- for(let j=0;j<newWidth;++j) {
- y = i/scale;
- x = j/scale;
- m = parseInt(y);
- n = parseInt(x);
- v = y-m;
- u = x-n;
- let tt = {}
- if(m<height-1 &&n<width-1){
- temp[i][j] = parseInt((1.0-v)*((1.0-u)*a[m][n]+u*a[m][n+1])
- + v*((1.0-u)*a[m+1][n] + u*a[m+1][n+1])
- )
- } else {
- temp[i][j] = a[m][n]
- }
- tt.x = i*size
- tt.y = j*size
- if(temp[i][j]>0) {
- tt.value = temp[i][j]
- rearr.push(tt)
- }
- }
- }
- return rearr
- }
|