{"action":"created","comment":{"url":"https://api.github.com/repos/jgautier/firmata/pulls/comments/35611328","id":35611328,"diff_hunk":"@@ -1411,6 +1451,148 @@ Board.prototype.stepperStep = function(deviceNum, direction, steps, speed, accel\n };\n \n /**\n+ * Asks the Arduino to configure a hardware or serial port.\n+ * @param {number} port The serial port to use (HW_SERIAL1, HW_SERIAL2, HW_SERIAL3, SW_SERIAL0,\n+ * SW_SERIAL1, SW_SERIAL2, SW_SERIAL3)\n+ * @param {number} baud The baud rate of the serial port.\n+ * @param {number} bytesToRead The number of bytes to read on each iteration of the main loop\n+ * (not yet used)\n+ * @param {number} rxPin [SoftwareSerial only] The RX pin of the SoftwareSerial instance\n+ * @param {number} txPin [SoftwareSerial only] The TX pin of the SoftwareSerial instance\n+ */\n+\n+Board.prototype.serialConfig = function(portId, baud, bytesToRead, rxPin, txPin) {\n+  var softSerialPins = {};\n+  var data = [\n+    START_SYSEX,\n+    SERIAL_MESSAGE,\n+    SERIAL_CONFIG | portId,\n+    baud & 0x007F,\n+    (baud >> 7) & 0x007F,\n+    (baud >> 14) & 0x007F,\n+    bytesToRead & 0x007F,\n+    (bytesToRead >> 7) & 0x007F\n+  ];\n+  if (rxPin) {\n+    data.push(rxPin);\n+  }\n+  if (txPin) {\n+    data.push(txPin);\n+  }\n+  data.push(END_SYSEX);\n+  this.transport.write(new Buffer(data));\n+};\n+\n+/**\n+ * Write an array of bytes to the specified serial port.\n+ * @param {number} portId The serial port to write to.\n+ * @param {array} inBytes An array of bytes to write to the serial port.\n+ */\n+\n+Board.prototype.serialWrite = function(portId, inBytes) {\n+  var data = [\n+    START_SYSEX,\n+    SERIAL_MESSAGE,\n+    SERIAL_WRITE | portId\n+  ];\n+  for (var i = 0, len = inBytes.length; i < len; i++) {\n+    data.push(inBytes[i] & 0x007F);\n+    data.push((inBytes[i] >> 7) & 0x007F);\n+  }\n+  data.push(END_SYSEX);\n+  if (data.length > 0) {\n+    this.transport.write(new Buffer(data));\n+  }\n+};\n+\n+/**\n+ * Start continuous reading of the specified serial port. The port is checked for data each\n+ * iteration of the main Arduino loop.\n+ * {number} portId The serial port to start reading continuously.\n+ */\n+\n+Board.prototype.serialStartReading = function(portId) {","path":"lib/firmata.js","position":125,"original_position":125,"commit_id":"a929b58cac6fb692b258006345b7e3537a84c96c","original_commit_id":"a929b58cac6fb692b258006345b7e3537a84c96c","user":{"login":"rwaldron","id":27985,"avatar_url":"https://avatars.githubusercontent.com/u/27985?v=3","gravatar_id":"","url":"https://api.github.com/users/rwaldron","html_url":"https://github.com/rwaldron","followers_url":"https://api.github.com/users/rwaldron/followers","following_url":"https://api.github.com/users/rwaldron/following{/other_user}","gists_url":"https://api.github.com/users/rwaldron/gists{/gist_id}","starred_url":"https://api.github.com/users/rwaldron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rwaldron/subscriptions","organizations_url":"https://api.github.com/users/rwaldron/orgs","repos_url":"https://api.github.com/users/rwaldron/repos","events_url":"https://api.github.com/users/rwaldron/events{/privacy}","received_events_url":"https://api.github.com/users/rwaldron/received_events","type":"User","site_admin":false},"body":"> `serialRead(portId, callback)` \r\n\r\nThis is actually how I imagined it would be shaped.\r\n\r\nI'm not sure about the rest, I have to think about it more and at the moment I just landed in seattle—so I'm basically useless right now ;)","created_at":"2015-07-28T03:17:05Z","updated_at":"2015-07-28T03:17:05Z","html_url":"https://github.com/jgautier/firmata/pull/97#discussion_r35611328","pull_request_url":"https://api.github.com/repos/jgautier/firmata/pulls/97","_links":{"self":{"href":"https://api.github.com/repos/jgautier/firmata/pulls/comments/35611328"},"html":{"href":"https://github.com/jgautier/firmata/pull/97#discussion_r35611328"},"pull_request":{"href":"https://api.github.com/repos/jgautier/firmata/pulls/97"}}},"pull_request":{"url":"https://api.github.com/repos/jgautier/firmata/pulls/97","id":40849191,"html_url":"https://github.com/jgautier/firmata/pull/97","diff_url":"https://github.com/jgautier/firmata/pull/97.diff","patch_url":"https://github.com/jgautier/firmata/pull/97.patch","issue_url":"https://api.github.com/repos/jgautier/firmata/issues/97","number":97,"state":"open","locked":false,"title":"initial pass a Firmata serial implementation","user":{"login":"soundanalogous","id":401539,"avatar_url":"https://avatars.githubusercontent.com/u/401539?v=3","gravatar_id":"","url":"https://api.github.com/users/soundanalogous","html_url":"https://github.com/soundanalogous","followers_url":"https://api.github.com/users/soundanalogous/followers","following_url":"https://api.github.com/users/soundanalogous/following{/other_user}","gists_url":"https://api.github.com/users/soundanalogous/gists{/gist_id}","starred_url":"https://api.github.com/users/soundanalogous/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/soundanalogous/subscriptions","organizations_url":"https://api.github.com/users/soundanalogous/orgs","repos_url":"https://api.github.com/users/soundanalogous/repos","events_url":"https://api.github.com/users/soundanalogous/events{/privacy}","received_events_url":"https://api.github.com/users/soundanalogous/received_events","type":"User","site_admin":false},"body":"Opening for discussion, nothing is set in stone yet. This is one of at least 2 ways to implement the Firmata serial protocol. The other approach would be to create a serial object with a constructor. I started with the version that fits in better with the existing patterns in firmata.js. To compare:\r\n\r\n```\r\n// the approach implemented in this PR:\r\nboard.serialConfig(0x08, 57600, 0, 10, 11);\r\nboard.serialWrite(0x08, [112, 113, 114]);\r\n\r\n// vs the alternate approach (not implemented)\r\n// where there would be a new serial.js module added to /firmata/lib/\r\nvar Serial = require(\"../lib/serial\");\r\nvar serial1 = new Serial(0x08, 57600, 0, 10, 11);\r\nserial1.write([112, 113, 114]);\r\n```\r\n\r\nI think the alternative version would be a cleaner api but perhaps a bit tricky to implement in node-firmata.","created_at":"2015-07-26T07:06:11Z","updated_at":"2015-07-28T03:17:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"990600a33419bf32dff16fa8c10c88202565a3b9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/jgautier/firmata/pulls/97/commits","review_comments_url":"https://api.github.com/repos/jgautier/firmata/pulls/97/comments","review_comment_url":"https://api.github.com/repos/jgautier/firmata/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jgautier/firmata/issues/97/comments","statuses_url":"https://api.github.com/repos/jgautier/firmata/statuses/a929b58cac6fb692b258006345b7e3537a84c96c","head":{"label":"soundanalogous:serial","ref":"serial","sha":"a929b58cac6fb692b258006345b7e3537a84c96c","user":{"login":"soundanalogous","id":401539,"avatar_url":"https://avatars.githubusercontent.com/u/401539?v=3","gravatar_id":"","url":"https://api.github.com/users/soundanalogous","html_url":"https://github.com/soundanalogous","followers_url":"https://api.github.com/users/soundanalogous/followers","following_url":"https://api.github.com/users/soundanalogous/following{/other_user}","gists_url":"https://api.github.com/users/soundanalogous/gists{/gist_id}","starred_url":"https://api.github.com/users/soundanalogous/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/soundanalogous/subscriptions","organizations_url":"https://api.github.com/users/soundanalogous/orgs","repos_url":"https://api.github.com/users/soundanalogous/repos","events_url":"https://api.github.com/users/soundanalogous/events{/privacy}","received_events_url":"https://api.github.com/users/soundanalogous/received_events","type":"User","site_admin":false},"repo":{"id":22329130,"name":"firmata","full_name":"soundanalogous/firmata","owner":{"login":"soundanalogous","id":401539,"avatar_url":"https://avatars.githubusercontent.com/u/401539?v=3","gravatar_id":"","url":"https://api.github.com/users/soundanalogous","html_url":"https://github.com/soundanalogous","followers_url":"https://api.github.com/users/soundanalogous/followers","following_url":"https://api.github.com/users/soundanalogous/following{/other_user}","gists_url":"https://api.github.com/users/soundanalogous/gists{/gist_id}","starred_url":"https://api.github.com/users/soundanalogous/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/soundanalogous/subscriptions","organizations_url":"https://api.github.com/users/soundanalogous/orgs","repos_url":"https://api.github.com/users/soundanalogous/repos","events_url":"https://api.github.com/users/soundanalogous/events{/privacy}","received_events_url":"https://api.github.com/users/soundanalogous/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/soundanalogous/firmata","description":"firmata protocol implemented in javascript","fork":true,"url":"https://api.github.com/repos/soundanalogous/firmata","forks_url":"https://api.github.com/repos/soundanalogous/firmata/forks","keys_url":"https://api.github.com/repos/soundanalogous/firmata/keys{/key_id}","collaborators_url":"https://api.github.com/repos/soundanalogous/firmata/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/soundanalogous/firmata/teams","hooks_url":"https://api.github.com/repos/soundanalogous/firmata/hooks","issue_events_url":"https://api.github.com/repos/soundanalogous/firmata/issues/events{/number}","events_url":"https://api.github.com/repos/soundanalogous/firmata/events","assignees_url":"https://api.github.com/repos/soundanalogous/firmata/assignees{/user}","branches_url":"https://api.github.com/repos/soundanalogous/firmata/branches{/branch}","tags_url":"https://api.github.com/repos/soundanalogous/firmata/tags","blobs_url":"https://api.github.com/repos/soundanalogous/firmata/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/soundanalogous/firmata/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/soundanalogous/firmata/git/refs{/sha}","trees_url":"https://api.github.com/repos/soundanalogous/firmata/git/trees{/sha}","statuses_url":"https://api.github.com/repos/soundanalogous/firmata/statuses/{sha}","languages_url":"https://api.github.com/repos/soundanalogous/firmata/languages","stargazers_url":"https://api.github.com/repos/soundanalogous/firmata/stargazers","contributors_url":"https://api.github.com/repos/soundanalogous/firmata/contributors","subscribers_url":"https://api.github.com/repos/soundanalogous/firmata/subscribers","subscription_url":"https://api.github.com/repos/soundanalogous/firmata/subscription","commits_url":"https://api.github.com/repos/soundanalogous/firmata/commits{/sha}","git_commits_url":"https://api.github.com/repos/soundanalogous/firmata/git/commits{/sha}","comments_url":"https://api.github.com/repos/soundanalogous/firmata/comments{/number}","issue_comment_url":"https://api.github.com/repos/soundanalogous/firmata/issues/comments{/number}","contents_url":"https://api.github.com/repos/soundanalogous/firmata/contents/{+path}","compare_url":"https://api.github.com/repos/soundanalogous/firmata/compare/{base}...{head}","merges_url":"https://api.github.com/repos/soundanalogous/firmata/merges","archive_url":"https://api.github.com/repos/soundanalogous/firmata/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/soundanalogous/firmata/downloads","issues_url":"https://api.github.com/repos/soundanalogous/firmata/issues{/number}","pulls_url":"https://api.github.com/repos/soundanalogous/firmata/pulls{/number}","milestones_url":"https://api.github.com/repos/soundanalogous/firmata/milestones{/number}","notifications_url":"https://api.github.com/repos/soundanalogous/firmata/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/soundanalogous/firmata/labels{/name}","releases_url":"https://api.github.com/repos/soundanalogous/firmata/releases{/id}","created_at":"2014-07-28T03:07:14Z","updated_at":"2014-07-27T19:21:23Z","pushed_at":"2015-07-26T07:13:23Z","git_url":"git://github.com/soundanalogous/firmata.git","ssh_url":"git@github.com:soundanalogous/firmata.git","clone_url":"https://github.com/soundanalogous/firmata.git","svn_url":"https://github.com/soundanalogous/firmata","homepage":"http://jgautier.github.com/firmata/","size":420,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"jgautier:master","ref":"master","sha":"3e093e43c9d9847281854e7ffc4313764a3b9486","user":{"login":"jgautier","id":326036,"avatar_url":"https://avatars.githubusercontent.com/u/326036?v=3","gravatar_id":"","url":"https://api.github.com/users/jgautier","html_url":"https://github.com/jgautier","followers_url":"https://api.github.com/users/jgautier/followers","following_url":"https://api.github.com/users/jgautier/following{/other_user}","gists_url":"https://api.github.com/users/jgautier/gists{/gist_id}","starred_url":"https://api.github.com/users/jgautier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgautier/subscriptions","organizations_url":"https://api.github.com/users/jgautier/orgs","repos_url":"https://api.github.com/users/jgautier/repos","events_url":"https://api.github.com/users/jgautier/events{/privacy}","received_events_url":"https://api.github.com/users/jgautier/received_events","type":"User","site_admin":false},"repo":{"id":1540078,"name":"firmata","full_name":"jgautier/firmata","owner":{"login":"jgautier","id":326036,"avatar_url":"https://avatars.githubusercontent.com/u/326036?v=3","gravatar_id":"","url":"https://api.github.com/users/jgautier","html_url":"https://github.com/jgautier","followers_url":"https://api.github.com/users/jgautier/followers","following_url":"https://api.github.com/users/jgautier/following{/other_user}","gists_url":"https://api.github.com/users/jgautier/gists{/gist_id}","starred_url":"https://api.github.com/users/jgautier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgautier/subscriptions","organizations_url":"https://api.github.com/users/jgautier/orgs","repos_url":"https://api.github.com/users/jgautier/repos","events_url":"https://api.github.com/users/jgautier/events{/privacy}","received_events_url":"https://api.github.com/users/jgautier/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jgautier/firmata","description":"firmata protocol implemented in javascript","fork":false,"url":"https://api.github.com/repos/jgautier/firmata","forks_url":"https://api.github.com/repos/jgautier/firmata/forks","keys_url":"https://api.github.com/repos/jgautier/firmata/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jgautier/firmata/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jgautier/firmata/teams","hooks_url":"https://api.github.com/repos/jgautier/firmata/hooks","issue_events_url":"https://api.github.com/repos/jgautier/firmata/issues/events{/number}","events_url":"https://api.github.com/repos/jgautier/firmata/events","assignees_url":"https://api.github.com/repos/jgautier/firmata/assignees{/user}","branches_url":"https://api.github.com/repos/jgautier/firmata/branches{/branch}","tags_url":"https://api.github.com/repos/jgautier/firmata/tags","blobs_url":"https://api.github.com/repos/jgautier/firmata/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jgautier/firmata/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jgautier/firmata/git/refs{/sha}","trees_url":"https://api.github.com/repos/jgautier/firmata/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jgautier/firmata/statuses/{sha}","languages_url":"https://api.github.com/repos/jgautier/firmata/languages","stargazers_url":"https://api.github.com/repos/jgautier/firmata/stargazers","contributors_url":"https://api.github.com/repos/jgautier/firmata/contributors","subscribers_url":"https://api.github.com/repos/jgautier/firmata/subscribers","subscription_url":"https://api.github.com/repos/jgautier/firmata/subscription","commits_url":"https://api.github.com/repos/jgautier/firmata/commits{/sha}","git_commits_url":"https://api.github.com/repos/jgautier/firmata/git/commits{/sha}","comments_url":"https://api.github.com/repos/jgautier/firmata/comments{/number}","issue_comment_url":"https://api.github.com/repos/jgautier/firmata/issues/comments{/number}","contents_url":"https://api.github.com/repos/jgautier/firmata/contents/{+path}","compare_url":"https://api.github.com/repos/jgautier/firmata/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jgautier/firmata/merges","archive_url":"https://api.github.com/repos/jgautier/firmata/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jgautier/firmata/downloads","issues_url":"https://api.github.com/repos/jgautier/firmata/issues{/number}","pulls_url":"https://api.github.com/repos/jgautier/firmata/pulls{/number}","milestones_url":"https://api.github.com/repos/jgautier/firmata/milestones{/number}","notifications_url":"https://api.github.com/repos/jgautier/firmata/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jgautier/firmata/labels{/name}","releases_url":"https://api.github.com/repos/jgautier/firmata/releases{/id}","created_at":"2011-03-29T05:10:59Z","updated_at":"2015-07-27T20:12:33Z","pushed_at":"2015-07-26T07:13:24Z","git_url":"git://github.com/jgautier/firmata.git","ssh_url":"git@github.com:jgautier/firmata.git","clone_url":"https://github.com/jgautier/firmata.git","svn_url":"https://github.com/jgautier/firmata","homepage":"http://jgautier.github.com/firmata/","size":869,"stargazers_count":384,"watchers_count":384,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":72,"mirror_url":null,"open_issues_count":11,"forks":72,"open_issues":11,"watchers":384,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jgautier/firmata/pulls/97"},"html":{"href":"https://github.com/jgautier/firmata/pull/97"},"issue":{"href":"https://api.github.com/repos/jgautier/firmata/issues/97"},"comments":{"href":"https://api.github.com/repos/jgautier/firmata/issues/97/comments"},"review_comments":{"href":"https://api.github.com/repos/jgautier/firmata/pulls/97/comments"},"review_comment":{"href":"https://api.github.com/repos/jgautier/firmata/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jgautier/firmata/pulls/97/commits"},"statuses":{"href":"https://api.github.com/repos/jgautier/firmata/statuses/a929b58cac6fb692b258006345b7e3537a84c96c"}}}}