8000 decimal RC code support by tjanson · Pull Request #2 · ni-c/duino · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

decimal RC code support #2

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

Merged
merged 1 commit into from
Jul 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/rc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var rc = new arduino.RC({

board.on('ready', function(){
setTimeout(function() {
// alternative: rc.decimal("123456")
rc.triState("0FFF0FFFFF0F");
}, 1000);
setTimeout(function() {
Expand Down
11 changes: 11 additions & 0 deletions lib/rc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,15 @@ RC.prototype.triState = function (val) {
this.board.write(msg);
}

/*
* Send decimal code
* val must be 12 chars or less
*/
RC.prototype.decimal = function (val) {
// at most twelve, null-term if shorter
var terminatedval = (val + '\0').slice(0,12)
var msg = '94' + this.pin + terminatedval;
this.board.write(msg);
}

module.exports = RC;
40 changes: 27 additions & 13 deletions src/duino/duino.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <Servo.h>

#include <RCSwitch.h>
#include <IRremote.h>

Expand Down Expand Up @@ -55,7 +54,7 @@ void process() {
val[8] = '\0';
strncpy(addr, messageBuffer + 14, 4);
addr[4] = '\0';
} else if (cmdid == 96) {
} else if (cmdid == 96 || cmdid == 94) {
strncpy(val, messageBuffer + 4, 12);
val[12] = '\0';
} else if (cmdid > 96) {
Expand All @@ -76,17 +75,18 @@ void process() {
// Serial.println(aux);

switch(cmdid) {
case 0: sm(pin,val); break;
case 1: dw(pin,val); break;
case 2: dr(pin,val); break;
case 3: aw(pin,val); break;
case 4: ar(pin,val); break;
case 95: handleIRsend(type, val, addr); break;
case 96: handleRCTriState(pin, val); break;
case 97: handlePing(pin,val,aux); break;
case 98: handleServo(pin,val,aux); break;
case 99: toggleDebug(val); break;
default: break;
case 0: sm(pin,val); break;
case 1: dw(pin,val); break;
case 2: dr(pin,val); break;
case 3: aw(pin,val); break;
case 4: ar(pin,val); break;
case 94: handleRCDecimal(pin, val); break;
case 95: handleIRsend(type, val, addr); break;
case 96: handleRCTriState(pin, val); break;
case 97: handlePing(pin,val,aux); break;
case 98: handleServo(pin,val,aux); break;
case 99: toggleDebug(val); break;
default: break;
}
}

Expand Down Expand Up @@ -277,6 +277,20 @@ void handleRCTriState(char *pin, char *val) {
rc.sendTriState(val);
}

/*
* Handle RC commands via decimal code
* For those sockets that don't use tri-state.
* handleRCDecimal("10", "5522351")
*/
void handleRCDecimal(char *pin, char *val) {
int p = getPin(pin);
if (p == -1) { if (debug) Serial.println("badpin"); return; }
if (debug) Serial.println("RCdec" + atol(val));
RCSwitch rc = RCSwitch();
rc.enableTransmit(p);
rc.send(atol(val), 24);
}

/*
* Handle IR commands
*/
Expand Down
0