{"action":"created","comment":{"url":"https://api.github.com/repos/nebrius/abstract-io/pulls/comments/236529854","pull_request_review_id":178621555,"id":236529854,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNjUyOTg1NA==","diff_hunk":"@@ -1,22 +1,107 @@\n /// <reference types=\"node\" />\n import { EventEmitter } from 'events';\n-export interface IAbstractIO {\n-    isReady: boolean;\n-    readonly MODES: {\n-        INPUT: number;\n-        OUTPUT: number;\n-        ANALOG: number;\n-        PWM: number;\n-        SERVO: number;\n-    };\n+export declare enum Mode {\n+    INPUT = 0,\n+    OUTPUT = 1,\n+    ANALOG = 2,\n+    PWM = 3,\n+    SERVO = 4,\n+    UNKOWN = 99\n+}\n+export declare enum Value {\n+    HIGH = 1,\n+    LOW = 0\n+}\n+export interface IPinConfiguration {\n+    supportedModes: Mode[];\n+    mode: Mode;\n+    value: Value;\n+    reporting: 0 | 1;\n+    analogChannel: number;\n+}\n+export interface IPingReadSettings {\n+    pin: number | string;\n+    value?: Value;\n+    pulseOut?: number;\n+}\n+export interface II2CConfig {\n+    address: number;\n+    bus?: number | string;\n+    port?: number;\n+    delay?: number;\n+}\n+export interface ISerialConfig {\n+    portId: number | string;\n+    baud?: number;\n+    rxPin?: number | string;\n+    txPin?: number | string;\n+}\n+export interface IServoConfig {\n+    pin: number | string;\n+    min?: number;\n+    max?: number;\n }\n-export declare class AbstractIO extends EventEmitter implements IAbstractIO {\n-    isReady: boolean;\n+export declare type ReadHandler = (data: number[]) => void;\n+export declare class AbstractIO extends EventEmitter {\n     readonly MODES: {\n-        INPUT: number;\n-        OUTPUT: number;\n-        ANALOG: number;\n-        PWM: number;\n-        SERVO: number;\n+        INPUT: Mode;\n+        OUTPUT: Mode;\n+        ANALOG: Mode;\n+        PWM: Mode;\n+        SERVO: Mode;\n+        UNKOWN: Mode;\n     };\n+    readonly HIGH: Value;\n+    readonly LOW: Value;\n+    readonly pins: IPinConfiguration[];\n+    readonly analogPins: number[];\n+    readonly name: string;\n+    readonly defaultLed: string | number | undefined;\n+    readonly isReady: boolean;\n+    pinMode(pin: string | number, mode: Mode): void;\n+    pwmWrite(pin: string | number, value: number): void;\n+    servoWrite(pin: string | number, value: number): void;\n+    digitalWrite(pin: string | number, value: number): void;","path":"declarations/index.d.ts","position":80,"original_position":80,"commit_id":"c2b2477aa08981f12b88200cd86b403a3cb3420f","original_commit_id":"c2b2477aa08981f12b88200cd86b403a3cb3420f","user":{"login":"nebrius","id":1141386,"node_id":"MDQ6VXNlcjExNDEzODY=","avatar_url":"https://avatars3.githubusercontent.com/u/1141386?v=4","gravatar_id":"","url":"https://api.github.com/users/nebrius","html_url":"https://github.com/nebrius","followers_url":"https://api.github.com/users/nebrius/followers","following_url":"https://api.github.com/users/nebrius/following{/other_user}","gists_url":"https://api.github.com/users/nebrius/gists{/gist_id}","starred_url":"https://api.github.com/users/nebrius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nebrius/subscriptions","organizations_url":"https://api.github.com/users/nebrius/orgs","repos_url":"https://api.github.com/users/nebrius/repos","events_url":"https://api.github.com/users/nebrius/events{/privacy}","received_events_url":"https://api.github.com/users/nebrius/received_events","type":"User","site_admin":false},"body":"Oh interesting. I've added an entry for it that does nothing if not overridden (as opposed to throwing an exception). Does this sound right to you?","created_at":"2018-11-27T06:06:06Z","updated_at":"2018-11-27T06:06:06Z","html_url":"https://github.com/nebrius/abstract-io/pull/1#discussion_r236529854","pull_request_url":"https://api.github.com/repos/nebrius/abstract-io/pulls/1","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/nebrius/abstract-io/pulls/comments/236529854"},"html":{"href":"https://github.com/nebrius/abstract-io/pull/1#discussion_r236529854"},"pull_request":{"href":"https://api.github.com/repos/nebrius/abstract-io/pulls/1"}},"in_reply_to_id":236049358},"pull_request":{"url":"https://api.github.com/repos/nebrius/abstract-io/pulls/1","id":232506015,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMyNTA2MDE1","html_url":"https://github.com/nebrius/abstract-io/pull/1","diff_url":"https://github.com/nebrius/abstract-io/pull/1.diff","patch_url":"https://github.com/nebrius/abstract-io/pull/1.patch","issue_url":"https://api.github.com/repos/nebrius/abstract-io/issues/1","number":1,"state":"open","locked":false,"title":"First draft of Abstract IO","user":{"login":"nebrius","id":1141386,"node_id":"MDQ6VXNlcjExNDEzODY=","avatar_url":"https://avatars3.githubusercontent.com/u/1141386?v=4","gravatar_id":"","url":"https://api.github.com/users/nebrius","html_url":"https://github.com/nebrius","followers_url":"https://api.github.com/users/nebrius/followers","following_url":"https://api.github.com/users/nebrius/following{/other_user}","gists_url":"https://api.github.com/users/nebrius/gists{/gist_id}","starred_url":"https://api.github.com/users/nebrius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nebrius/subscriptions","organizations_url":"https://api.github.com/users/nebrius/orgs","repos_url":"https://api.github.com/users/nebrius/repos","events_url":"https://api.github.com/users/nebrius/events{/privacy}","received_events_url":"https://api.github.com/users/nebrius/received_events","type":"User","site_admin":false},"body":"I created a first draft of Abstract IO. I think it's over all usable as is, but could definitely use some vetting. This is a follow-up from the [Johnny-Five collaborators summit](https://github.com/rwaldron/johnny-five/issues/1463#issuecomment-414544943) and fulfills one of the action items we identified.\r\n\r\nAbstract IO is a base class that all IO Plugins can inherit from. This should help us iron out inconsistencies between IO Plugins and help us spin up new IO Plugins easier. I intend to rearchitect Raspi IO to use Abstract IO once this PR is landed and published to npm.\r\n\r\n**About the architecture**\r\n\r\n~~Abstract IO is written in TypeScript, and I paid attention to both TypeScript consumers and non-TypeScript consumers. I played with a variety of approaches, and decided that a split-class approach is best. There is `AbstractIOCore` for TypeScript users and `AbstractIO` for non-TypeScript users, which inherits from `AbstractIOCore`.~~\r\n\r\n~~The reason for the two classes has to do with tooling and what's most the effective method for overriding base methods. As an example, let's take the `digitalWrite()` method. TypeScript has the concept of [abstract classes and methods](https://www.typescriptlang.org/docs/handbook/classes.html), which are perfect for this use case. They are declared as such:~~\r\n\r\n```TypeScript\r\nclass AbstractIOCore extends EventEmitter {\r\n  public abstract digitalWrite(pin: string | number, value: HIGH | LOW): void;\r\n}\r\n```\r\n\r\n~~Then, when you create a new TypeScript class that derives from `AbstractIOCore`, you have to implement the `digitalWrite` method or else you get a compile time error. The issue, however, is that this compiles down to the following vanilla JavaScript code:~~\r\n\r\n```JavaScript\r\nclass AbstractIOCore extends EventEmitter {\r\n}\r\n```\r\n\r\n~~There is no longer any reference to `digitalWrite`, which doesn't help non-TypeScript users. So, I created a second class that inherits from `AbstractIOCore` that does the following:~~\r\n\r\n```TypeScript\r\nclass AbstractIO extends AbstractIOCore {\r\n  public digitalWrite(pin: string | number, value: HIGH | LOW): void {\r\n    throw new Error('This method must be implemented by a derived IO Plugin class');\r\n  }\r\n}\r\n```\r\n\r\n~~With this approach, we get a best of both worlds for both TypeScript and non-TypeScript users, even if the implementation is a bit clunky IMO.~~\r\n\r\nThe newly revised architecture is a more classical single base-class approach. In it, methods that are not overridden by an IO plugin will automatically throw a message stating \"[functionName] is not supported by [IO Plugin Name]\".\r\n\r\nThe read only properties, e.g. `isReady`, are implemented with a getter that throws an exception stating \"throw new Error(`The \"[property name]\" property must be overridden by a derived IO Plugin class`);\"\r\n\r\n**About methods/properties included**\r\n\r\nThe methods that are implemented are based on cross-referencing the [IO Plugin spec](https://github.com/nebrius/io-plugins) with [Raspi IO Core](https://github.com/nebrius/raspi-io-core) (the logic implementation for Raspi IO), firmata.js, and Johnny-Five itself.\r\n\r\nThis means there are deprecated methods, undocumented methods, and methods that only exist for compatibility with firmata.js. This should increase compatibility, but is nonetheless a superset of of the IO Plugin spec. I tried to take things that aren't used by Johnny-Five, such as `reportAnalogPin`, and give them base implementations without marking them as abstract. Indeed, these implementations are basically copy-pasted from Raspi IO. This way, we should get this extra level of backwards compatibility without IO Plugins needing to do anything.\r\n\r\nI'd love to hear what everyone else things about this approach, and if there's anything missing since I only used one IO Plugin as a base comparison.\r\n","created_at":"2018-11-21T00:53:48Z","updated_at":"2018-11-27T06:06:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"990245ca61160a207b8d5ec84db33286ecb691de","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/nebrius/abstract-io/pulls/1/commits","review_comments_url":"https://api.github.com/repos/nebrius/abstract-io/pulls/1/comments","review_comment_url":"https://api.github.com/repos/nebrius/abstract-io/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nebrius/abstract-io/issues/1/comments","statuses_url":"https://api.github.com/repos/nebrius/abstract-io/statuses/c2b2477aa08981f12b88200cd86b403a3cb3420f","head":{"label":"nebrius:first-draft","ref":"first-draft","sha":"c2b2477aa08981f12b88200cd86b403a3cb3420f","user":{"login":"nebrius","id":1141386,"node_id":"MDQ6VXNlcjExNDEzODY=","avatar_url":"https://avatars3.githubusercontent.com/u/1141386?v=4","gravatar_id":"","url":"https://api.github.com/users/nebrius","html_url":"https://github.com/nebrius","followers_url":"https://api.github.com/users/nebrius/followers","following_url":"https://api.github.com/users/nebrius/following{/other_user}","gists_url":"https://api.github.com/users/nebrius/gists{/gist_id}","starred_url":"https://api.github.com/users/nebrius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nebrius/subscriptions","organizations_url":"https://api.github.com/users/nebrius/orgs","repos_url":"https://api.github.com/users/nebrius/repos","events_url":"https://api.github.com/users/nebrius/events{/privacy}","received_events_url":"https://api.github.com/users/nebrius/received_events","type":"User","site_admin":false},"repo":{"id":145481152,"node_id":"MDEwOlJlcG9zaXRvcnkxNDU0ODExNTI=","name":"abstract-io","full_name":"nebrius/abstract-io","private":false,"owner":{"login":"nebrius","id":1141386,"node_id":"MDQ6VXNlcjExNDEzODY=","avatar_url":"https://avatars3.githubusercontent.com/u/1141386?v=4","gravatar_id":"","url":"https://api.github.com/users/nebrius","html_url":"https://github.com/nebrius","followers_url":"https://api.github.com/users/nebrius/followers","following_url":"https://api.github.com/users/nebrius/following{/other_user}","gists_url":"https://api.github.com/users/nebrius/gists{/gist_id}","starred_url":"https://api.github.com/users/nebrius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nebrius/subscriptions","organizations_url":"https://api.github.com/users/nebrius/orgs","repos_url":"https://api.github.com/users/nebrius/repos","events_url":"https://api.github.com/users/nebrius/events{/privacy}","received_events_url":"https://api.github.com/users/nebrius/received_events","type":"User","site_admin":false},"html_url":"https://github.com/nebrius/abstract-io","description":"An interface and base class for creating Johnny-Five IO plugins","fork":false,"url":"https://api.github.com/repos/nebrius/abstract-io","forks_url":"https://api.github.com/repos/nebrius/abstract-io/forks","keys_url":"https://api.github.com/repos/nebrius/abstract-io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nebrius/abstract-io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nebrius/abstract-io/teams","hooks_url":"https://api.github.com/repos/nebrius/abstract-io/hooks","issue_events_url":"https://api.github.com/repos/nebrius/abstract-io/issues/events{/number}","events_url":"https://api.github.com/repos/nebrius/abstract-io/events","assignees_url":"https://api.github.com/repos/nebrius/abstract-io/assignees{/user}","branches_url":"https://api.github.com/repos/nebrius/abstract-io/branches{/branch}","tags_url":"https://api.github.com/repos/nebrius/abstract-io/tags","blobs_url":"https://api.github.com/repos/nebrius/abstract-io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nebrius/abstract-io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nebrius/abstract-io/git/refs{/sha}","trees_url":"https://api.github.com/repos/nebrius/abstract-io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nebrius/abstract-io/statuses/{sha}","languages_url":"https://api.github.com/repos/nebrius/abstract-io/languages","stargazers_url":"https://api.github.com/repos/nebrius/abstract-io/stargazers","contributors_url":"https://api.github.com/repos/nebrius/abstract-io/contributors","subscribers_url":"https://api.github.com/repos/nebrius/abstract-io/subscribers","subscription_url":"https://api.github.com/repos/nebrius/abstract-io/subscription","commits_url":"https://api.github.com/repos/nebrius/abstract-io/commits{/sha}","git_commits_url":"https://api.github.com/repos/nebrius/abstract-io/git/commits{/sha}","comments_url":"https://api.github.com/repos/nebrius/abstract-io/comments{/number}","issue_comment_url":"https://api.github.com/repos/nebrius/abstract-io/issues/comments{/number}","contents_url":"https://api.github.com/repos/nebrius/abstract-io/contents/{+path}","compare_url":"https://api.github.com/repos/nebrius/abstract-io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nebrius/abstract-io/merges","archive_url":"https://api.github.com/repos/nebrius/abstract-io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nebrius/abstract-io/downloads","issues_url":"https://api.github.com/repos/nebrius/abstract-io/issues{/number}","pulls_url":"https://api.github.com/repos/nebrius/abstract-io/pulls{/number}","milestones_url":"https://api.github.com/repos/nebrius/abstract-io/milestones{/number}","notifications_url":"https://api.github.com/repos/nebrius/abstract-io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nebrius/abstract-io/labels{/name}","releases_url":"https://api.github.com/repos/nebrius/abstract-io/releases{/id}","deployments_url":"https://api.github.com/repos/nebrius/abstract-io/deployments","created_at":"2018-08-20T23:35:32Z","updated_at":"2018-09-24T08:59:33Z","pushed_at":"2018-11-21T19:48:40Z","git_url":"git://github.com/nebrius/abstract-io.git","ssh_url":"git@github.com:nebrius/abstract-io.git","clone_url":"https://github.com/nebrius/abstract-io.git","svn_url":"https://github.com/nebrius/abstract-io","homepage":null,"size":25,"stargazers_count":9,"watchers_count":9,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":1,"watchers":9,"default_branch":"master"}},"base":{"label":"nebrius:master","ref":"master","sha":"6b7283673c41f59c1a1a7244c77b195531107220","user":{"login":"nebrius","id":1141386,"node_id":"MDQ6VXNlcjExNDEzODY=","avatar_url":"https://avatars3.githubusercontent.com/u/1141386?v=4","gravatar_id":"","url":"https://api.github.com/users/nebrius","html_url":"https://github.com/nebrius","followers_url":"https://api.github.com/users/nebrius/followers","following_url":"https://api.github.com/users/nebrius/following{/other_user}","gists_url":"https://api.github.com/users/nebrius/gists{/gist_id}","starred_url":"https://api.github.com/users/nebrius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nebrius/subscriptions","organizations_url":"https://api.github.com/users/nebrius/orgs","repos_url":"https://api.github.com/users/nebrius/repos","events_url":"https://api.github.com/users/nebrius/events{/privacy}","received_events_url":"https://api.github.com/users/nebrius/received_events","type":"User","site_admin":false},"repo":{"id":145481152,"node_id":"MDEwOlJlcG9zaXRvcnkxNDU0ODExNTI=","name":"abstract-io","full_name":"nebrius/abstract-io","private":false,"owner":{"login":"nebrius","id":1141386,"node_id":"MDQ6VXNlcjExNDEzODY=","avatar_url":"https://avatars3.githubusercontent.com/u/1141386?v=4","gravatar_id":"","url":"https://api.github.com/users/nebrius","html_url":"https://github.com/nebrius","followers_url":"https://api.github.com/users/nebrius/followers","following_url":"https://api.github.com/users/nebrius/following{/other_user}","gists_url":"https://api.github.com/users/nebrius/gists{/gist_id}","starred_url":"https://api.github.com/users/nebrius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nebrius/subscriptions","organizations_url":"https://api.github.com/users/nebrius/orgs","repos_url":"https://api.github.com/users/nebrius/repos","events_url":"https://api.github.com/users/nebrius/events{/privacy}","received_events_url":"https://api.github.com/users/nebrius/received_events","type":"User","site_admin":false},"html_url":"https://github.com/nebrius/abstract-io","description":"An interface and base class for creating Johnny-Five IO plugins","fork":false,"url":"https://api.github.com/repos/nebrius/abstract-io","forks_url":"https://api.github.com/repos/nebrius/abstract-io/forks","keys_url":"https://api.github.com/repos/nebrius/abstract-io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nebrius/abstract-io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nebrius/abstract-io/teams","hooks_url":"https://api.github.com/repos/nebrius/abstract-io/hooks","issue_events_url":"https://api.github.com/repos/nebrius/abstract-io/issues/events{/number}","events_url":"https://api.github.com/repos/nebrius/abstract-io/events","assignees_url":"https://api.github.com/repos/nebrius/abstract-io/assignees{/user}","branches_url":"https://api.github.com/repos/nebrius/abstract-io/branches{/branch}","tags_url":"https://api.github.com/repos/nebrius/abstract-io/tags","blobs_url":"https://api.github.com/repos/nebrius/abstract-io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nebrius/abstract-io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nebrius/abstract-io/git/refs{/sha}","trees_url":"https://api.github.com/repos/nebrius/abstract-io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nebrius/abstract-io/statuses/{sha}","languages_url":"https://api.github.com/repos/nebrius/abstract-io/languages","stargazers_url":"https://api.github.com/repos/nebrius/abstract-io/stargazers","contributors_url":"https://api.github.com/repos/nebrius/abstract-io/contributors","subscribers_url":"https://api.github.com/repos/nebrius/abstract-io/subscribers","subscription_url":"https://api.github.com/repos/nebrius/abstract-io/subscription","commits_url":"https://api.github.com/repos/nebrius/abstract-io/commits{/sha}","git_commits_url":"https://api.github.com/repos/nebrius/abstract-io/git/commits{/sha}","comments_url":"https://api.github.com/repos/nebrius/abstract-io/comments{/number}","issue_comment_url":"https://api.github.com/repos/nebrius/abstract-io/issues/comments{/number}","contents_url":"https://api.github.com/repos/nebrius/abstract-io/contents/{+path}","compare_url":"https://api.github.com/repos/nebrius/abstract-io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nebrius/abstract-io/merges","archive_url":"https://api.github.com/repos/nebrius/abstract-io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nebrius/abstract-io/downloads","issues_url":"https://api.github.com/repos/nebrius/abstract-io/issues{/number}","pulls_url":"https://api.github.com/repos/nebrius/abstract-io/pulls{/number}","milestones_url":"https://api.github.com/repos/nebrius/abstract-io/milestones{/number}","notifications_url":"https://api.github.com/repos/nebrius/abstract-io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nebrius/abstract-io/labels{/name}","releases_url":"https://api.github.com/repos/nebrius/abstract-io/releases{/id}","deployments_url":"https://api.github.com/repos/nebrius/abstract-io/deployments","created_at":"2018-08-20T23:35:32Z","updated_at":"2018-09-24T08:59:33Z","pushed_at":"2018-11-21T19:48:40Z","git_url":"git://github.com/nebrius/abstract-io.git","ssh_url":"git@github.com:nebrius/abstract-io.git","clone_url":"https://github.com/nebrius/abstract-io.git","svn_url":"https://github.com/nebrius/abstract-io","homepage":null,"size":25,"stargazers_count":9,"watchers_count":9,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":1,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nebrius/abstract-io/pulls/1"},"html":{"href":"https://github.com/nebrius/abstract-io/pull/1"},"issue":{"href":"https://api.github.com/repos/nebrius/abstract-io/issues/1"},"comments":{"href":"https://api.github.com/repos/nebrius/abstract-io/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/nebrius/abstract-io/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/nebrius/abstract-io/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nebrius/abstract-io/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/nebrius/abstract-io/statuses/c2b2477aa08981f12b88200cd86b403a3cb3420f"}},"author_association":"OWNER"}}
{"actor":{"display_login":"nebrius"}}