Skip to content

Commit 92c0cdc

Browse files
authored
Merge pull request #841 from entrylabs/develop-hw
1.9.68 version up
2 parents dd95811 + 734bbf9 commit 92c0cdc

File tree

6 files changed

+147
-2
lines changed

6 files changed

+147
-2
lines changed

app/modules/robotis_RB100im_koala.png

1.15 KB
Loading

app/modules/timbo.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
const BaseModule = require('./baseModule');
2+
3+
class Timbo extends BaseModule {
4+
// 클래스 내부에서 사용될 필드들을 이곳에서 선언합니다.
5+
constructor() {
6+
super();
7+
this.digitalValue = new Array(14);
8+
this.analogValue = new Array(6);
9+
10+
this.remoteDigitalValue = new Array(14);
11+
this.readablePorts = null;
12+
this.remainValue = null;
13+
}
14+
15+
/*
16+
최초에 커넥션이 이루어진 후의 s초기 설정.
17+
handler 는 워크스페이스와 통신하 데이터를 json 화 하는 오브젝트입니다. (datahandler/json 참고)
18+
config 은 module.json 오브젝트입니다.
19+
*/
20+
init(handler, config) {
21+
this.handler = handler;
22+
this.config = config;
23+
}
24+
25+
/*
26+
연결 후 초기에 송신할 데이터가 필요한 경우 사용합니다.
27+
requestInitialData 를 사용한 경우 checkInitialData 가 필수입니다.
28+
이 두 함수가 정의되어있어야 로직이 동작합니다. 필요없으면 작성하지 않아도 됩니다.
29+
*/
30+
requestInitialData() {
31+
return true;
32+
}
33+
34+
// 연결 후 초기에 수신받아서 정상연결인지를 확인해야하는 경우 사용합니다.
35+
checkInitialData(data, config) {
36+
return true;
37+
}
38+
39+
// 주기적으로 하드웨어에서 받은 데이터의 검증이 필요한 경우 사용합니다.
40+
validateLocalData(data) {
41+
return true;
42+
}
43+
44+
/*
45+
하드웨어 기기에 전달할 데이터를 반환합니다.
46+
slave 모드인 경우 duration 속성 간격으로 지속적으로 기기에 요청을 보냅니다.
47+
*/
48+
requestLocalData() {
49+
var queryString = [];
50+
51+
var readablePorts = this.readablePorts;
52+
if (readablePorts) {
53+
for (var i in readablePorts) {
54+
var query = (5 << 5) + (readablePorts[i] << 1);
55+
queryString.push(query);
56+
}
57+
}
58+
59+
var digitalValue = this.remoteDigitalValue;
60+
for (var port = 0; port < 14; port++) {
61+
var value = digitalValue[port];
62+
if (value === 255 || value === 0) {
63+
var query = (7 << 5) + (port << 1) + (value == 255 ? 1 : 0);
64+
queryString.push(query);
65+
} else if (value > 0 && value < 255) {
66+
var query = (6 << 5) + (port << 1) + (value >> 7);
67+
queryString.push(query);
68+
query = value & 127;
69+
queryString.push(query);
70+
}
71+
}
72+
return queryString;
73+
}
74+
75+
// 하드웨어에서 온 데이터 처리
76+
handleLocalData(data) {
77+
// data: Native Buffer
78+
var pointer = 0;
79+
for (var i = 0; i < 32; i++) {
80+
var chunk;
81+
if (!this.remainValue) {
82+
chunk = data[i];
83+
} else {
84+
chunk = this.remainValue;
85+
i--;
86+
}
87+
if (chunk >> 7) {
88+
if ((chunk >> 6) & 1) {
89+
var nextChunk = data[i + 1];
90+
if (!nextChunk && nextChunk !== 0) {
91+
this.remainValue = chunk;
92+
} else {
93+
this.remainValue = null;
94+
95+
var port = (chunk >> 3) & 7;
96+
this.analogValue[port] = ((chunk & 7) << 7) + (nextChunk & 127);
97+
}
98+
i++;
99+
} else {
100+
var port = (chunk >> 2) & 15;
101+
this.digitalValue[port] = chunk & 1;
102+
}
103+
}
104+
}
105+
}
106+
107+
// 엔트리로 전달할 데이터
108+
requestRemoteData(handler) {
109+
for (var i = 0; i < this.analogValue.length; i++) {
110+
var value = this.analogValue[i];
111+
handler.write('a' + i, value);
112+
}
113+
for (var i = 0; i < this.digitalValue.length; i++) {
114+
var value = this.digitalValue[i];
115+
handler.write(i, value);
116+
}
117+
}
118+
119+
// 엔트리에서 받은 데이터에 대한 처리
120+
handleRemoteData(handler) {
121+
this.readablePorts = handler.read('readablePorts');
122+
var digitalValue = this.remoteDigitalValue;
123+
for (var port = 0; port < 14; port++) {
124+
digitalValue[port] = handler.read(port);
125+
}
126+
}
127+
}
128+
129+
module.exports = new Timbo();

app/modules/timbo.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"id": "6A0101",
3+
"name": {
4+
"en": "TimboRobot",
5+
"ko": "팀보로봇"
6+
},
7+
"module": "timbo.js",
8+
"category": "robot",
9+
"platform": ["win32", "darwin"],
10+
"icon": "timbo.png",
11+
"selectPort": true,
12+
"hardware": {
13+
"type": "serial",
14+
"control": "slave"
15+
}
16+
}

app/modules/timbo.png

15.9 KB
Loading

build/entry-hw.nsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
!define PRODUCT_NAME "Entry_HW"
1515
!define PROTOCOL_NAME "entryhw"
1616
!define APP_NAME "Entry_HW.exe"
17-
!define PRODUCT_VERSION "1.9.67"
17+
!define PRODUCT_VERSION "1.9.68"
1818
!define PRODUCT_PUBLISHER "EntryLabs"
1919
!define PRODUCT_WEB_SITE "https://www.playentry.org/"
2020

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "entry-hw",
3-
"version": "1.9.67",
3+
"version": "1.9.68",
44
"description": "엔트리 하드웨어 연결 프로그램",
55
"author": "EntryLabs",
66
"main": "./app/src/index.bundle.js",

0 commit comments

Comments
 (0)