Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create mhz19.js #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Create mhz19.js #54

wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Oct 2, 2017

var mhz19 = require('@amperka/mhz19.js').connect({ rx: P0, tx: P1, speed: 9600, port: Serial3 });
console.log( mhz19.read() );

var mhz19 = require('@amperka/mhz19.js').connect({ rx: P0, tx: P1, speed: 9600, port: Serial3 });
console.log( mhz19.read() );
@igrztv
Copy link
Contributor

igrztv commented Oct 2, 2017

Привет!

В целом всё норм, но есть комментарии.
Ещё у нас есть код-стайл в репозитории. Должно быть 0 ошибок по линтеру.
Установить линтер:
https://www.npmjs.com/package/eslint
Использовать файл .eslintrc:
`{
"extends": "eslint:recommended",

"rules": {
"array-bracket-spacing": [2, "never"],
"block-scoped-var": 2,
"brace-style": [2, "1tbs"],
"camelcase": 1,
"computed-property-spacing": [2, "never"],
"consistent-this": [2, "self"],
"curly": 2,
"eol-last": 2,
"eqeqeq": [2, "smart"],
"id-match": [2, "^(?[a-zA-Z]+([a-zA-Z0-9]+)*)|([A-Z0-9]+)$", {"properties": true}],
"indent": [2, 2, {"SwitchCase": 1}],
"key-spacing": [2, {"beforeColon": false, "afterColon": true}],
"linebreak-style": [2, "unix"],
"max-depth": [1, 3],
"max-len": [1, 80],
"max-nested-callbacks": [2, 3],
"max-statements": [1, 25],
"new-cap": 1,
"no-extend-native": 2,
"no-extra-semi": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multi-spaces": 2,
"no-multiple-empty-lines": [2, {"max": 2}],
"no-spaced-func": 2,
"no-trailing-spaces": 2,
"no-undef": 2,
"no-undef-init": 2,
"no-unused-vars": 1,
"no-use-before-define": [2, "nofunc"],
"object-curly-spacing": [2, "never"],
"quotes": [2, "single", "avoid-escape"],
"semi": [2, "always"],
"semi-spacing": [2, {"before": false, "after": true}],
"keyword-spacing": [2, {"before": true, "after": true, "overrides": {}}],
"space-before-function-paren": [2, "never"],
"space-in-parens": [2, "never"],
"space-unary-ops": [1, {"words": true, "nonwords": false}],
"spaced-comment": [2, "always"],
"yoda": [2, "never"]
},

"globals": {
"A0": false,
"A1": false,
"A2": false,
"A3": false,
"A4": false,
"A5": false,
"E": false,
"P1": false,
"P0": false,
"P10": false,
"P11": false,
"P12": false,
"P13": false,
"P2": false,
"P3": false,
"P4": false,
"P5": false,
"P6": false,
"P7": false,
"P8": false,
"P9": false,
"B15": false,
"B14": false,
"B13": false,
"SCL": false,
"SDA": false,
"SPI2": false,
"analogRead": false,
"analogWrite": false,
"changeInterval": false,
"clearInterval": false,
"clearTimeout": false,
"clearWatch": false,
"digitalPulse": false,
"digitalRead": false,
"digitalWrite": false,
"exports": true,
"getTime": false,
"setInterval": false,
"setTimeout": false,
"setWatch": false,
"require": false,
"print": false
}
}`

MHZ19.prototype.abc_on = function() { this._serial.write("\xFF\x01\x79\xA0\x00\x00\x00\x00\xE6"); }
MHZ19.prototype.abc_off = function() { this._serial.write("\xFF\x01\x79\x00\x00\x00\x00\x00\x86"); }
MHZ19.prototype.read = function() { this._serial.write("\xFF\x01\x86\x00\x00\x00\x00\x00\x79");
var data = this._serial.read(9);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше использовать хендлеры для обработки сообщений UART
ser.on("data", function(d) {

});

var mhz19  = require('@amperka/mhz19.js').connect({tx: P1, rx: P0, port: Serial3, speed: 9600});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant