Skip to content

Commit

Permalink
更新註解
Browse files Browse the repository at this point in the history
  • Loading branch information
TMineCola committed Jun 12, 2018
1 parent c37b043 commit 84769dd
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions modules/doorControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,90 @@ module.exports = function (rpio, config) {
var module = {};

var log = new logSystem(config.main.logDirectory, doorControl);
// 電源狀態
var powerState = false;

function _doorAttach() {
// connect relay and default power open and door close
// 預設啟動電源上鎖, 不開啟
rpio.open(config.lock.powerPIN, rpio.OUTPUT, rpio.HIGH);
rpio.open(config.lock.openPIN, rpio.OUTPUT, rpio.LOW);
// let module allow be use
// 紀錄電源狀態
powerState = true;
}

function _doorDetach() {
// disconnect rpio
// 關閉GPIO, 避免訊號異常導致開門
rpio.close(config.lock.powerPIN, rpio.PIN_RESET);
rpio.close(config.lock.openPIN, rpio.PIN_RESET);
// let module disabled
// 更新店員狀態
powerState = false;
}

// event functions
/* 事件函式(訊息管理) */

// 電源狀態通知
function _doorPowerPush() {
if(powerState == false) {

} else {

}
// push Line API
// logging
}

function _doorStatePush(state, message) {
// 門鎖狀態通知
function _doorStatePush(state) {
if(state == 0) {

} else {

}
// push Line API
// logging
}

// 啟動時連接GPIO
module.doorInit = function () {
_doorAttach();
}

// control functions
/* 控制函式 */

// 電源切換
module.doorPowerSwitch = function () {
powerState == false ? _doorAttach() : _doorDetach();
// 更新電源狀態
_doorPowerPush();

return powerState;
}

// 門鎖切換
module.doorOpenSwitch = function (message) {
// 電源啟動情況下才執行開關門鎖
if(powerState == true) {
// 切換繼電器訊號
rpio.read(config.lock.openPIN) == 0 ? rpio.write(config.lock.openPIN, rpio.HIGH) : rpio.write(config.lock.openPIN, rpio.LOW);
// 讀取繼電器狀態
let currentState = rpio.read(config.lock.openPIN);
_doorStatePush(currentState, message);
// 更新門鎖狀態
_doorStatePush(currentState;

// 記錄資訊與回傳狀態
log.record();
return currentState;
} else {
// log failed record
// 紀錄失敗訊息
log.record();
}
}

module.doorPowerState = function () {
// 回傳電源繼電器狀態
return rpio.read(config.lock.powerPIN);
}

module.doorOpenState = function () {
// 回傳門鎖繼電器狀態
return rpio.read(config.lock.openPIN);
}

Expand Down

0 comments on commit 84769dd

Please sign in to comment.