{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/iot/pulls/comments/241876135","pull_request_review_id":185263767,"id":241876135,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0MTg3NjEzNQ==","diff_hunk":"@@ -0,0 +1,190 @@\n+﻿using System;\n+using System.Collections.Generic;\n+using System.Diagnostics;\n+using System.IO;\n+using System.Text;\n+using System.Threading;\n+\n+namespace System.Device.Gpio.Drivers\n+{\n+    public class LibgpiodDriver : GpioDriver\n+    {\n+        private const string GpioGet = \"gpioget\";\n+        private const string GpioChip0 = \"gpiochip0 \";\n+        private const string GpioSet = \"gpioset\";\n+        public int _waitMilliSeconds { get; set;}\n+        private Dictionary<int, PinMode> _pinNumperToPinModes;\n+        private Dictionary<int, Process> _pinNumperToProcess;\n+        protected internal override int PinCount => throw new PlatformNotSupportedException(\"This driver is generic so it can not enumerate how many pins are available.\");\n+\n+        public LibgpiodDriver() {\n+            _pinNumperToPinModes = new Dictionary<int, PinMode>();\n+            _pinNumperToProcess = new Dictionary<int, Process>();\n+            _waitMilliSeconds = (int)TimeSpan.FromSeconds(1).TotalMilliseconds;\n+        }\n+        protected internal override void AddCallbackForPinValueChangedEvent(int pinNumber, PinEventTypes eventType, PinChangeEventHandler callback)\n+        {\n+            throw new NotImplementedException();\n+        }\n+\n+        protected internal override void ClosePin(int pinNumber)\n+        {\n+            // do nothing_pinNumperToProcess\n+        }\n+\n+        protected internal override int ConvertPinNumberToLogicalNumberingScheme(int pinNumber) => throw new PlatformNotSupportedException(\"This driver is generic so it can not perform conversions between pin numbering schemes.\");\n+\n+        protected internal override PinMode GetPinMode(int pinNumber)\n+        {\n+            if (_pinNumperToPinModes.ContainsKey(pinNumber))\n+             {\n+                return _pinNumperToPinModes[pinNumber];\n+            }\n+            else\n+            {\n+                throw new InvalidOperationException(\"There was an attempt to get a mode to a pin that is not yet open.\");\n+            }\n+        }\n+\n+        protected internal override bool IsPinModeSupported(int pinNumber, PinMode mode)\n+        {\n+            // Libgpiod driver does not support pull up or pull down resistors.\n+            if (mode == PinMode.InputPullDown || mode == PinMode.InputPullUp)\n+                return false;\n+            return true;\n+        }\n+\n+        protected internal override void OpenPin(int pinNumber)\n+        {\n+            // do nothing\n+        }\n+\n+        protected internal override PinValue Read(int pinNumber)\n+        {\n+            PinValue result = default(PinValue);\n+            try\n+            {\n+                Process myProc = new Process();\n+                myProc.StartInfo.FileName = GpioGet;\n+                myProc.StartInfo.Arguments = $\" {GpioChip0} {pinNumber}\";\n+                myProc.StartInfo.RedirectStandardOutput = true;\n+                myProc.Start();\n+                if (HandlProcessExit(myProc, $\"{GpioGet} {GpioChip0} {pinNumber}\", _waitMilliSeconds))\n+                {\n+                    string valueContents = myProc.StandardOutput.ReadToEnd();\n+                    result = ConvertSysFsValueToPinValue(valueContents);\n+                }\n+            }\n+            catch (UnauthorizedAccessException e)\n+            {\n+                throw new UnauthorizedAccessException(\"Reading a pin value requires root permissions.\", e);\n+            }\n+            return result;\n+        }\n+        private PinValue ConvertSysFsValueToPinValue(string value)\n+        {\n+            PinValue result;\n+            value = value.Trim();","path":"src/System.Device.Gpio/System/Device/Gpio/Drivers/LibgpiodDriver.cs","position":87,"original_position":87,"commit_id":"1bbcd3335045ce8d0c5f99f5d316194eaecf5529","original_commit_id":"1bbcd3335045ce8d0c5f99f5d316194eaecf5529","user":{"login":"krwq","id":660048,"node_id":"MDQ6VXNlcjY2MDA0OA==","avatar_url":"https://avatars1.githubusercontent.com/u/660048?v=4","gravatar_id":"","url":"https://api.github.com/users/krwq","html_url":"https://github.com/krwq","followers_url":"https://api.github.com/users/krwq/followers","following_url":"https://api.github.com/users/krwq/following{/other_user}","gists_url":"https://api.github.com/users/krwq/gists{/gist_id}","starred_url":"https://api.github.com/users/krwq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krwq/subscriptions","organizations_url":"https://api.github.com/users/krwq/orgs","repos_url":"https://api.github.com/users/krwq/repos","events_url":"https://api.github.com/users/krwq/events{/privacy}","received_events_url":"https://api.github.com/users/krwq/received_events","type":"User","site_admin":false},"body":"I agree - optionally perhaps something like: `return value.IndexOf('1') != -1 ? PinValue.High : PinValue.Low` or just get a char if possible (you should be able to read it directly from the stream and there should be a way of doing that so it ignores whitespaces)","created_at":"2018-12-14T20:10:12Z","updated_at":"2018-12-14T20:15:58Z","html_url":"https://github.com/dotnet/iot/pull/96#discussion_r241876135","pull_request_url":"https://api.github.com/repos/dotnet/iot/pulls/96","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/dotnet/iot/pulls/comments/241876135"},"html":{"href":"https://github.com/dotnet/iot/pull/96#discussion_r241876135"},"pull_request":{"href":"https://api.github.com/repos/dotnet/iot/pulls/96"}},"in_reply_to_id":241858397},"pull_request":{"url":"https://api.github.com/repos/dotnet/iot/pulls/96","id":238582754,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM4NTgyNzU0","html_url":"https://github.com/dotnet/iot/pull/96","diff_url":"https://github.com/dotnet/iot/pull/96.diff","patch_url":"https://github.com/dotnet/iot/pull/96.patch","issue_url":"https://api.github.com/repos/dotnet/iot/issues/96","number":96,"state":"open","locked":false,"title":"[WIP] libgpiod driver using command line tools (Read, Write, OpenPin, ClosePin only","user":{"login":"buyaa-n","id":45579687,"node_id":"MDQ6VXNlcjQ1NTc5Njg3","avatar_url":"https://avatars0.githubusercontent.com/u/45579687?v=4","gravatar_id":"","url":"https://api.github.com/users/buyaa-n","html_url":"https://github.com/buyaa-n","followers_url":"https://api.github.com/users/buyaa-n/followers","following_url":"https://api.github.com/users/buyaa-n/following{/other_user}","gists_url":"https://api.github.com/users/buyaa-n/gists{/gist_id}","starred_url":"https://api.github.com/users/buyaa-n/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/buyaa-n/subscriptions","organizations_url":"https://api.github.com/users/buyaa-n/orgs","repos_url":"https://api.github.com/users/buyaa-n/repos","events_url":"https://api.github.com/users/buyaa-n/events{/privacy}","received_events_url":"https://api.github.com/users/buyaa-n/received_events","type":"User","site_admin":false},"body":"Just for review, not for merge","created_at":"2018-12-14T01:15:08Z","updated_at":"2018-12-14T20:15:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e1aa6a93386c3d1bf0a0f436319045872d16b723","assignee":null,"assignees":[],"requested_reviewers":[{"login":"tarekgh","id":10833894,"node_id":"MDQ6VXNlcjEwODMzODk0","avatar_url":"https://avatars2.githubusercontent.com/u/10833894?v=4","gravatar_id":"","url":"https://api.github.com/users/tarekgh","html_url":"https://github.com/tarekgh","followers_url":"https://api.github.com/users/tarekgh/followers","following_url":"https://api.github.com/users/tarekgh/following{/other_user}","gists_url":"https://api.github.com/users/tarekgh/gists{/gist_id}","starred_url":"https://api.github.com/users/tarekgh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tarekgh/subscriptions","organizations_url":"https://api.github.com/users/tarekgh/orgs","repos_url":"https://api.github.com/users/tarekgh/repos","events_url":"https://api.github.com/users/tarekgh/events{/privacy}","received_events_url":"https://api.github.com/users/tarekgh/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":1151698609,"node_id":"MDU6TGFiZWwxMTUxNjk4NjA5","url":"https://api.github.com/repos/dotnet/iot/labels/*%20NO%20MERGE%20*","name":"* NO MERGE *","color":"e11d21","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/iot/pulls/96/commits","review_comments_url":"https://api.github.com/repos/dotnet/iot/pulls/96/comments","review_comment_url":"https://api.github.com/repos/dotnet/iot/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/iot/issues/96/comments","statuses_url":"https://api.github.com/repos/dotnet/iot/statuses/1bbcd3335045ce8d0c5f99f5d316194eaecf5529","head":{"label":"buyaa-n:libgpiod_using_command_line_tools","ref":"libgpiod_using_command_line_tools","sha":"1bbcd3335045ce8d0c5f99f5d316194eaecf5529","user":{"login":"buyaa-n","id":45579687,"node_id":"MDQ6VXNlcjQ1NTc5Njg3","avatar_url":"https://avatars0.githubusercontent.com/u/45579687?v=4","gravatar_id":"","url":"https://api.github.com/users/buyaa-n","html_url":"https://github.com/buyaa-n","followers_url":"https://api.github.com/users/buyaa-n/followers","following_url":"https://api.github.com/users/buyaa-n/following{/other_user}","gists_url":"https://api.github.com/users/buyaa-n/gists{/gist_id}","starred_url":"https://api.github.com/users/buyaa-n/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/buyaa-n/subscriptions","organizations_url":"https://api.github.com/users/buyaa-n/orgs","repos_url":"https://api.github.com/users/buyaa-n/repos","events_url":"https://api.github.com/users/buyaa-n/events{/privacy}","received_events_url":"https://api.github.com/users/buyaa-n/received_events","type":"User","site_admin":false},"repo":{"id":160405001,"node_id":"MDEwOlJlcG9zaXRvcnkxNjA0MDUwMDE=","name":"iot","full_name":"buyaa-n/iot","private":false,"owner":{"login":"buyaa-n","id":45579687,"node_id":"MDQ6VXNlcjQ1NTc5Njg3","avatar_url":"https://avatars0.githubusercontent.com/u/45579687?v=4","gravatar_id":"","url":"https://api.github.com/users/buyaa-n","html_url":"https://github.com/buyaa-n","followers_url":"https://api.github.com/users/buyaa-n/followers","following_url":"https://api.github.com/users/buyaa-n/following{/other_user}","gists_url":"https://api.github.com/users/buyaa-n/gists{/gist_id}","starred_url":"https://api.github.com/users/buyaa-n/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/buyaa-n/subscriptions","organizations_url":"https://api.github.com/users/buyaa-n/orgs","repos_url":"https://api.github.com/users/buyaa-n/repos","events_url":"https://api.github.com/users/buyaa-n/events{/privacy}","received_events_url":"https://api.github.com/users/buyaa-n/received_events","type":"User","site_admin":false},"html_url":"https://github.com/buyaa-n/iot","description":"This repo includes .NET Core implementations for various IoT boards, chips, displays and PCBs.","fork":true,"url":"https://api.github.com/repos/buyaa-n/iot","forks_url":"https://api.github.com/repos/buyaa-n/iot/forks","keys_url":"https://api.github.com/repos/buyaa-n/iot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/buyaa-n/iot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/buyaa-n/iot/teams","hooks_url":"https://api.github.com/repos/buyaa-n/iot/hooks","issue_events_url":"https://api.github.com/repos/buyaa-n/iot/issues/events{/number}","events_url":"https://api.github.com/repos/buyaa-n/iot/events","assignees_url":"https://api.github.com/repos/buyaa-n/iot/assignees{/user}","branches_url":"https://api.github.com/repos/buyaa-n/iot/branches{/branch}","tags_url":"https://api.github.com/repos/buyaa-n/iot/tags","blobs_url":"https://api.github.com/repos/buyaa-n/iot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/buyaa-n/iot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/buyaa-n/iot/git/refs{/sha}","trees_url":"https://api.github.com/repos/buyaa-n/iot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/buyaa-n/iot/statuses/{sha}","languages_url":"https://api.github.com/repos/buyaa-n/iot/languages","stargazers_url":"https://api.github.com/repos/buyaa-n/iot/stargazers","contributors_url":"https://api.github.com/repos/buyaa-n/iot/contributors","subscribers_url":"https://api.github.com/repos/buyaa-n/iot/subscribers","subscription_url":"https://api.github.com/repos/buyaa-n/iot/subscription","commits_url":"https://api.github.com/repos/buyaa-n/iot/commits{/sha}","git_commits_url":"https://api.github.com/repos/buyaa-n/iot/git/commits{/sha}","comments_url":"https://api.github.com/repos/buyaa-n/iot/comments{/number}","issue_comment_url":"https://api.github.com/repos/buyaa-n/iot/issues/comments{/number}","contents_url":"https://api.github.com/repos/buyaa-n/iot/contents/{+path}","compare_url":"https://api.github.com/repos/buyaa-n/iot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/buyaa-n/iot/merges","archive_url":"https://api.github.com/repos/buyaa-n/iot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/buyaa-n/iot/downloads","issues_url":"https://api.github.com/repos/buyaa-n/iot/issues{/number}","pulls_url":"https://api.github.com/repos/buyaa-n/iot/pulls{/number}","milestones_url":"https://api.github.com/repos/buyaa-n/iot/milestones{/number}","notifications_url":"https://api.github.com/repos/buyaa-n/iot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/buyaa-n/iot/labels{/name}","releases_url":"https://api.github.com/repos/buyaa-n/iot/releases{/id}","deployments_url":"https://api.github.com/repos/buyaa-n/iot/deployments","created_at":"2018-12-04T18:59:31Z","updated_at":"2018-12-04T18:59:33Z","pushed_at":"2018-12-14T01:11:26Z","git_url":"git://github.com/buyaa-n/iot.git","ssh_url":"git@github.com:buyaa-n/iot.git","clone_url":"https://github.com/buyaa-n/iot.git","svn_url":"https://github.com/buyaa-n/iot","homepage":"","size":4220,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"9dd969d40c6aeb509c27e24e4211fbcced9118a7","user":{"login":"dotnet","id":9141961,"node_id":"MDEyOk9yZ2FuaXphdGlvbjkxNDE5NjE=","avatar_url":"https://avatars0.githubusercontent.com/u/9141961?v=4","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":151623607,"node_id":"MDEwOlJlcG9zaXRvcnkxNTE2MjM2MDc=","name":"iot","full_name":"dotnet/iot","private":false,"owner":{"login":"dotnet","id":9141961,"node_id":"MDEyOk9yZ2FuaXphdGlvbjkxNDE5NjE=","avatar_url":"https://avatars0.githubusercontent.com/u/9141961?v=4","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/dotnet/iot","description":"This repo includes .NET Core implementations for various IoT boards, chips, displays and PCBs.","fork":false,"url":"https://api.github.com/repos/dotnet/iot","forks_url":"https://api.github.com/repos/dotnet/iot/forks","keys_url":"https://api.github.com/repos/dotnet/iot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/iot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/iot/teams","hooks_url":"https://api.github.com/repos/dotnet/iot/hooks","issue_events_url":"https://api.github.com/repos/dotnet/iot/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/iot/events","assignees_url":"https://api.github.com/repos/dotnet/iot/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/iot/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/iot/tags","blobs_url":"https://api.github.com/repos/dotnet/iot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/iot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/iot/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/iot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/iot/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/iot/languages","stargazers_url":"https://api.github.com/repos/dotnet/iot/stargazers","contributors_url":"https://api.github.com/repos/dotnet/iot/contributors","subscribers_url":"https://api.github.com/repos/dotnet/iot/subscribers","subscription_url":"https://api.github.com/repos/dotnet/iot/subscription","commits_url":"https://api.github.com/repos/dotnet/iot/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/iot/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/iot/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/iot/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/iot/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/iot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/iot/merges","archive_url":"https://api.github.com/repos/dotnet/iot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/iot/downloads","issues_url":"https://api.github.com/repos/dotnet/iot/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/iot/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/iot/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/iot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/iot/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/iot/releases{/id}","deployments_url":"https://api.github.com/repos/dotnet/iot/deployments","created_at":"2018-10-04T19:15:33Z","updated_at":"2018-12-14T08:07:59Z","pushed_at":"2018-12-14T09:29:55Z","git_url":"git://github.com/dotnet/iot.git","ssh_url":"git@github.com:dotnet/iot.git","clone_url":"https://github.com/dotnet/iot.git","svn_url":"https://github.com/dotnet/iot","homepage":"","size":4227,"stargazers_count":126,"watchers_count":126,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":19,"mirror_url":null,"archived":false,"open_issues_count":29,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":19,"open_issues":29,"watchers":126,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/iot/pulls/96"},"html":{"href":"https://github.com/dotnet/iot/pull/96"},"issue":{"href":"https://api.github.com/repos/dotnet/iot/issues/96"},"comments":{"href":"https://api.github.com/repos/dotnet/iot/issues/96/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/iot/pulls/96/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/iot/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/iot/pulls/96/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/iot/statuses/1bbcd3335045ce8d0c5f99f5d316194eaecf5529"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"krwq"}}