{"action":"created","comment":{"url":"https://api.github.com/repos/tessel/tessel-rust/pulls/comments/72375481","id":72375481,"diff_hunk":"@@ -68,6 +113,113 @@ pub struct PortGroup {\n pub struct Port {\n     // Path of the domain socket.\n     pub socket_path: &'static str,\n+    pub socket: UnixStream,\n+}\n+\n+impl Port {\n+    pub fn new(path: &'static str) -> Port {\n+        // Connect to the unix domain socket for this port\n+        let socket = UnixStream::connect(path).unwrap();\n+        // Create and return the port struct\n+        Port {\n+            socket_path: path,\n+            socket: socket,\n+        }\n+    }\n+\n+    pub fn i2c(&mut self, address: u8, frequency: u32) -> I2C {\n+        // Create and return the I2C struct\n+        I2C::new(self, address, frequency)","path":"src/lib.rs","position":88,"original_position":88,"commit_id":"68bf090ac71208b2a76e9be685670a02d9cb27cd","original_commit_id":"68bf090ac71208b2a76e9be685670a02d9cb27cd","user":{"login":"kevinmehall","id":119951,"avatar_url":"https://avatars.githubusercontent.com/u/119951?v=3","gravatar_id":"","url":"https://api.github.com/users/kevinmehall","html_url":"https://github.com/kevinmehall","followers_url":"https://api.github.com/users/kevinmehall/followers","following_url":"https://api.github.com/users/kevinmehall/following{/other_user}","gists_url":"https://api.github.com/users/kevinmehall/gists{/gist_id}","starred_url":"https://api.github.com/users/kevinmehall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevinmehall/subscriptions","organizations_url":"https://api.github.com/users/kevinmehall/orgs","repos_url":"https://api.github.com/users/kevinmehall/repos","events_url":"https://api.github.com/users/kevinmehall/events{/privacy}","received_events_url":"https://api.github.com/users/kevinmehall/received_events","type":"User","site_admin":false},"body":"One caveat I'll note with this kind of API is that there can only be one `&mut` borrow of an object in existence at any given time, so you while you have an I2C object, you aren't allowed to touch the Port directly. That's almost a good thing as it prevents you from enabling SPI + I2C + UART at once, but it does prevent using non-I2C pins as GPIO through the Port object.\r\n\r\nI can think of a couple of ways around this:\r\n\r\n* To be like the JS API, with no compile-time checks on API misuse, you could have a `Backend` struct that holds the domain socket and manages the command queue. `Port`, `I2C`, and all other objects could share the same backend by holding `Arc<Mutex<Backend>>` and call methods on it after acquiring the lock. The Port and the I2C objects could be sent to separate threads, and the Backend would be responsible at runtime for making sure that the options they're asking for don't conflict with each other.\r\n\r\n* You could add methods to the I2C struct to access the GPIO and other functionality that are legal to use in I2C mode. In this case, you'd probably want to make this method take `self` by value, and have I2C own `Port` rather than `&mut Port`. This way would mean separate types representing the port for unconfigured vs I2C vs SPI, etc, with methods to convert between the types that also send commands to change the mode. This would require all code that uses the port to be aware of what mode it's in, which doesn't seem completely unreasonable.","created_at":"2016-07-27T03:24:47Z","updated_at":"2016-07-27T03:24:47Z","html_url":"https://github.com/tessel/tessel-rust/pull/23#discussion_r72375481","pull_request_url":"https://api.github.com/repos/tessel/tessel-rust/pulls/23","_links":{"self":{"href":"https://api.github.com/repos/tessel/tessel-rust/pulls/comments/72375481"},"html":{"href":"https://github.com/tessel/tessel-rust/pull/23#discussion_r72375481"},"pull_request":{"href":"https://api.github.com/repos/tessel/tessel-rust/pulls/23"}}},"pull_request":{"url":"https://api.github.com/repos/tessel/tessel-rust/pulls/23","id":77878397,"html_url":"https://github.com/tessel/tessel-rust/pull/23","diff_url":"https://github.com/tessel/tessel-rust/pull/23.diff","patch_url":"https://github.com/tessel/tessel-rust/pull/23.patch","issue_url":"https://api.github.com/repos/tessel/tessel-rust/issues/23","number":23,"state":"open","locked":false,"title":"[WIP] Adds I2C hardware interface","user":{"login":"johnnyman727","id":432909,"avatar_url":"https://avatars.githubusercontent.com/u/432909?v=3","gravatar_id":"","url":"https://api.github.com/users/johnnyman727","html_url":"https://github.com/johnnyman727","followers_url":"https://api.github.com/users/johnnyman727/followers","following_url":"https://api.github.com/users/johnnyman727/following{/other_user}","gists_url":"https://api.github.com/users/johnnyman727/gists{/gist_id}","starred_url":"https://api.github.com/users/johnnyman727/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnnyman727/subscriptions","organizations_url":"https://api.github.com/users/johnnyman727/orgs","repos_url":"https://api.github.com/users/johnnyman727/repos","events_url":"https://api.github.com/users/johnnyman727/events{/privacy}","received_events_url":"https://api.github.com/users/johnnyman727/received_events","type":"User","site_admin":false},"body":"Does not work yet for unknown reasons. It does not seem to be flushing the socket buffer at any point.\r\n\r\nBased on I2C work previously in JS [here](https://github.com/tessel/t2-firmware/blob/master/node/tessel-export.js#L795-L875).\r\n\r\nCould definitely use comments about how to make it more idiomatic.","created_at":"2016-07-18T20:59:39Z","updated_at":"2016-07-27T03:24:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"930e17e56002fdb017882d44a1a0d5efd9214658","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/tessel/tessel-rust/pulls/23/commits","review_comments_url":"https://api.github.com/repos/tessel/tessel-rust/pulls/23/comments","review_comment_url":"https://api.github.com/repos/tessel/tessel-rust/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tessel/tessel-rust/issues/23/comments","statuses_url":"https://api.github.com/repos/tessel/tessel-rust/statuses/68bf090ac71208b2a76e9be685670a02d9cb27cd","head":{"label":"tessel:add-domain-socket","ref":"add-domain-socket","sha":"68bf090ac71208b2a76e9be685670a02d9cb27cd","user":{"login":"tessel","id":5573563,"avatar_url":"https://avatars.githubusercontent.com/u/5573563?v=3","gravatar_id":"","url":"https://api.github.com/users/tessel","html_url":"https://github.com/tessel","followers_url":"https://api.github.com/users/tessel/followers","following_url":"https://api.github.com/users/tessel/following{/other_user}","gists_url":"https://api.github.com/users/tessel/gists{/gist_id}","starred_url":"https://api.github.com/users/tessel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tessel/subscriptions","organizations_url":"https://api.github.com/users/tessel/orgs","repos_url":"https://api.github.com/users/tessel/repos","events_url":"https://api.github.com/users/tessel/events{/privacy}","received_events_url":"https://api.github.com/users/tessel/received_events","type":"Organization","site_admin":false},"repo":{"id":34026171,"name":"tessel-rust","full_name":"tessel/tessel-rust","owner":{"login":"tessel","id":5573563,"avatar_url":"https://avatars.githubusercontent.com/u/5573563?v=3","gravatar_id":"","url":"https://api.github.com/users/tessel","html_url":"https://github.com/tessel","followers_url":"https://api.github.com/users/tessel/followers","following_url":"https://api.github.com/users/tessel/following{/other_user}","gists_url":"https://api.github.com/users/tessel/gists{/gist_id}","starred_url":"https://api.github.com/users/tessel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tessel/subscriptions","organizations_url":"https://api.github.com/users/tessel/orgs","repos_url":"https://api.github.com/users/tessel/repos","events_url":"https://api.github.com/users/tessel/events{/privacy}","received_events_url":"https://api.github.com/users/tessel/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tessel/tessel-rust","description":"Rust driver for Tessel 2.","fork":false,"url":"https://api.github.com/repos/tessel/tessel-rust","forks_url":"https://api.github.com/repos/tessel/tessel-rust/forks","keys_url":"https://api.github.com/repos/tessel/tessel-rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tessel/tessel-rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tessel/tessel-rust/teams","hooks_url":"https://api.github.com/repos/tessel/tessel-rust/hooks","issue_events_url":"https://api.github.com/repos/tessel/tessel-rust/issues/events{/number}","events_url":"https://api.github.com/repos/tessel/tessel-rust/events","assignees_url":"https://api.github.com/repos/tessel/tessel-rust/assignees{/user}","branches_url":"https://api.github.com/repos/tessel/tessel-rust/branches{/branch}","tags_url":"https://api.github.com/repos/tessel/tessel-rust/tags","blobs_url":"https://api.github.com/repos/tessel/tessel-rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tessel/tessel-rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tessel/tessel-rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/tessel/tessel-rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tessel/tessel-rust/statuses/{sha}","languages_url":"https://api.github.com/repos/tessel/tessel-rust/languages","stargazers_url":"https://api.github.com/repos/tessel/tessel-rust/stargazers","contributors_url":"https://api.github.com/repos/tessel/tessel-rust/contributors","subscribers_url":"https://api.github.com/repos/tessel/tessel-rust/subscribers","subscription_url":"https://api.github.com/repos/tessel/tessel-rust/subscription","commits_url":"https://api.github.com/repos/tessel/tessel-rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/tessel/tessel-rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/tessel/tessel-rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/tessel/tessel-rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/tessel/tessel-rust/contents/{+path}","compare_url":"https://api.github.com/repos/tessel/tessel-rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tessel/tessel-rust/merges","archive_url":"https://api.github.com/repos/tessel/tessel-rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tessel/tessel-rust/downloads","issues_url":"https://api.github.com/repos/tessel/tessel-rust/issues{/number}","pulls_url":"https://api.github.com/repos/tessel/tessel-rust/pulls{/number}","milestones_url":"https://api.github.com/repos/tessel/tessel-rust/milestones{/number}","notifications_url":"https://api.github.com/repos/tessel/tessel-rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tessel/tessel-rust/labels{/name}","releases_url":"https://api.github.com/repos/tessel/tessel-rust/releases{/id}","deployments_url":"https://api.github.com/repos/tessel/tessel-rust/deployments","created_at":"2015-04-16T00:44:06Z","updated_at":"2016-07-25T10:15:09Z","pushed_at":"2016-07-26T21:41:09Z","git_url":"git://github.com/tessel/tessel-rust.git","ssh_url":"git@github.com:tessel/tessel-rust.git","clone_url":"https://github.com/tessel/tessel-rust.git","svn_url":"https://github.com/tessel/tessel-rust","homepage":"https://www.tessel.io","size":31,"stargazers_count":40,"watchers_count":40,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":14,"forks":3,"open_issues":14,"watchers":40,"default_branch":"master"}},"base":{"label":"tessel:master","ref":"master","sha":"2a435d8f3dadbdea6c966ca97af4070c09fc6193","user":{"login":"tessel","id":5573563,"avatar_url":"https://avatars.githubusercontent.com/u/5573563?v=3","gravatar_id":"","url":"https://api.github.com/users/tessel","html_url":"https://github.com/tessel","followers_url":"https://api.github.com/users/tessel/followers","following_url":"https://api.github.com/users/tessel/following{/other_user}","gists_url":"https://api.github.com/users/tessel/gists{/gist_id}","starred_url":"https://api.github.com/users/tessel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tessel/subscriptions","organizations_url":"https://api.github.com/users/tessel/orgs","repos_url":"https://api.github.com/users/tessel/repos","events_url":"https://api.github.com/users/tessel/events{/privacy}","received_events_url":"https://api.github.com/users/tessel/received_events","type":"Organization","site_admin":false},"repo":{"id":34026171,"name":"tessel-rust","full_name":"tessel/tessel-rust","owner":{"login":"tessel","id":5573563,"avatar_url":"https://avatars.githubusercontent.com/u/5573563?v=3","gravatar_id":"","url":"https://api.github.com/users/tessel","html_url":"https://github.com/tessel","followers_url":"https://api.github.com/users/tessel/followers","following_url":"https://api.github.com/users/tessel/following{/other_user}","gists_url":"https://api.github.com/users/tessel/gists{/gist_id}","starred_url":"https://api.github.com/users/tessel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tessel/subscriptions","organizations_url":"https://api.github.com/users/tessel/orgs","repos_url":"https://api.github.com/users/tessel/repos","events_url":"https://api.github.com/users/tessel/events{/privacy}","received_events_url":"https://api.github.com/users/tessel/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tessel/tessel-rust","description":"Rust driver for Tessel 2.","fork":false,"url":"https://api.github.com/repos/tessel/tessel-rust","forks_url":"https://api.github.com/repos/tessel/tessel-rust/forks","keys_url":"https://api.github.com/repos/tessel/tessel-rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tessel/tessel-rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tessel/tessel-rust/teams","hooks_url":"https://api.github.com/repos/tessel/tessel-rust/hooks","issue_events_url":"https://api.github.com/repos/tessel/tessel-rust/issues/events{/number}","events_url":"https://api.github.com/repos/tessel/tessel-rust/events","assignees_url":"https://api.github.com/repos/tessel/tessel-rust/assignees{/user}","branches_url":"https://api.github.com/repos/tessel/tessel-rust/branches{/branch}","tags_url":"https://api.github.com/repos/tessel/tessel-rust/tags","blobs_url":"https://api.github.com/repos/tessel/tessel-rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tessel/tessel-rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tessel/tessel-rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/tessel/tessel-rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tessel/tessel-rust/statuses/{sha}","languages_url":"https://api.github.com/repos/tessel/tessel-rust/languages","stargazers_url":"https://api.github.com/repos/tessel/tessel-rust/stargazers","contributors_url":"https://api.github.com/repos/tessel/tessel-rust/contributors","subscribers_url":"https://api.github.com/repos/tessel/tessel-rust/subscribers","subscription_url":"https://api.github.com/repos/tessel/tessel-rust/subscription","commits_url":"https://api.github.com/repos/tessel/tessel-rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/tessel/tessel-rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/tessel/tessel-rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/tessel/tessel-rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/tessel/tessel-rust/contents/{+path}","compare_url":"https://api.github.com/repos/tessel/tessel-rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tessel/tessel-rust/merges","archive_url":"https://api.github.com/repos/tessel/tessel-rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tessel/tessel-rust/downloads","issues_url":"https://api.github.com/repos/tessel/tessel-rust/issues{/number}","pulls_url":"https://api.github.com/repos/tessel/tessel-rust/pulls{/number}","milestones_url":"https://api.github.com/repos/tessel/tessel-rust/milestones{/number}","notifications_url":"https://api.github.com/repos/tessel/tessel-rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tessel/tessel-rust/labels{/name}","releases_url":"https://api.github.com/repos/tessel/tessel-rust/releases{/id}","deployments_url":"https://api.github.com/repos/tessel/tessel-rust/deployments","created_at":"2015-04-16T00:44:06Z","updated_at":"2016-07-25T10:15:09Z","pushed_at":"2016-07-26T21:41:09Z","git_url":"git://github.com/tessel/tessel-rust.git","ssh_url":"git@github.com:tessel/tessel-rust.git","clone_url":"https://github.com/tessel/tessel-rust.git","svn_url":"https://github.com/tessel/tessel-rust","homepage":"https://www.tessel.io","size":31,"stargazers_count":40,"watchers_count":40,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":14,"forks":3,"open_issues":14,"watchers":40,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tessel/tessel-rust/pulls/23"},"html":{"href":"https://github.com/tessel/tessel-rust/pull/23"},"issue":{"href":"https://api.github.com/repos/tessel/tessel-rust/issues/23"},"comments":{"href":"https://api.github.com/repos/tessel/tessel-rust/issues/23/comments"},"review_comments":{"href":"https://api.github.com/repos/tessel/tessel-rust/pulls/23/comments"},"review_comment":{"href":"https://api.github.com/repos/tessel/tessel-rust/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tessel/tessel-rust/pulls/23/commits"},"statuses":{"href":"https://api.github.com/repos/tessel/tessel-rust/statuses/68bf090ac71208b2a76e9be685670a02d9cb27cd"}}}}
{"actor":{"display_login":"kevinmehall"}}