{"action":"created","comment":{"url":"https://api.github.com/repos/Restioson/flower/pulls/comments/155925606","pull_request_review_id":82328426,"id":155925606,"diff_hunk":"@@ -90,167 +93,159 @@ impl Ps2Controller {\n             println!(\"ps2c: detected no available devices\");\n         }\n \n-        flush_output();\n+        flush_output()?;\n \n         self.initialized = true;\n+\n+        Ok(())\n     }\n \n     /// Initializes the config for this controller\n-    fn initialize_config(&mut self) {\n+    fn initialize_config(&mut self) -> Result<(), Ps2Error> {\n         // Read the config from the controller\n-        self.read_config();\n+        self.read_config()?;\n \n         // Set all required config flags\n-        self.config.set(ControllerConfigBit::PortInterrupt1, false);\n-        self.config.set(ControllerConfigBit::PortInterrupt2, false);\n-        self.config.set(ControllerConfigBit::PortTranslation1, false);\n+        self.config.set(Ps2ConfigFlags::PORT_INTERRUPT_1, false);\n+        self.config.set(Ps2ConfigFlags::PORT_INTERRUPT_2, false);\n+        self.config.set(Ps2ConfigFlags::PORT_TRANSLATION_1, false);\n \n         // Write the updated config back to the controller\n-        self.write_config();\n+        self.write_config()?;\n \n         println!(\"ps2c: initialized config\");\n+\n+        Ok(())\n     }\n \n     /// Tests this controller\n-    fn test_controller(&mut self) -> bool {\n-        command_ret(ControllerReturnCommand::TestController) == Some(0x55)\n+    fn test_controller(&mut self) -> Result<bool, Ps2Error> {\n+        Ok(command_ret(ControllerReturnCommand::TestController)? == 0x55)\n     }\n \n     /// Writes the current config to the PS2 controller\n-    pub fn write_config(&mut self) {\n-        command_data(ControllerCommand::WriteConfig, self.config.data);\n+    pub fn write_config(&mut self) -> Result<(), Ps2Error> {\n+        command_data(ControllerCommand::WriteConfig, self.config.bits())\n     }\n \n     /// Reads the config from the PS2 controller\n-    pub fn read_config(&mut self) {\n-        self.config.data = command_ret(ControllerReturnCommand::ReadConfig).unwrap_or(self.config.data);\n-    }\n-}\n+    pub fn read_config(&mut self) -> Result<(), Ps2Error> {\n+        let read = command_ret(ControllerReturnCommand::ReadConfig)?;\n+        self.config = Ps2ConfigFlags::from_bits_truncate(read);\n \n-/// Returns if the given code is OK\n-#[allow(dead_code)] // To be used by keyboard / mouse driver depending on PS/2\n-pub fn is_ok(code: Option<u8>) -> bool {\n-    code == Some(ACK) || code == Some(SELF_TEST_PASSED)\n+        Ok(())\n+    }\n }\n \n /// Represents a PS2 device\n pub struct Ps2Device {\n-    flags: u8,\n+    state: DeviceState,\n+    port: DevicePort,\n }\n \n impl Ps2Device {\n+    const fn new(port: DevicePort) -> Self {\n+        Ps2Device {\n+            state: DeviceState::Unavailable,\n+            port,\n+        }\n+    }\n+\n     /// Tests this device to see if it is available\n-    pub fn test(&mut self) -> bool {\n-        let available = command_ret(if self.get_flag(DEVICE_SECOND_FLAG) {\n+    pub fn test(&mut self) -> Result<bool, Ps2Error> {\n+        let available = command_ret(if self.port == DevicePort::Mouse {\n             ControllerReturnCommand::TestPort2\n         } else {\n             ControllerReturnCommand::TestPort1\n-        }) == Some(0x0);\n-        self.set_flag(DEVICE_AVAILABLE_FLAG, available);\n-        available\n+        })? == 0x0;\n+\n+        if available {\n+            self.state = DeviceState::Available;\n+        } else {\n+            self.state = DeviceState::Unavailable;\n+        }\n+\n+        Ok(available)\n     }\n \n     /// Enables this device\n-    pub fn enable(&mut self) {\n-        if self.get_flag(DEVICE_AVAILABLE_FLAG) {\n-            command(if self.get_flag(DEVICE_SECOND_FLAG) {\n+    pub fn enable(&mut self) -> Result<(), Ps2Error> {\n+        if self.state == DeviceState::Available {\n+            command(if self.port == DevicePort::Mouse {\n                 ControllerCommand::EnablePort2\n             } else {\n                 ControllerCommand::EnablePort1\n-            });\n-            self.set_flag(DEVICE_ENABLED_FLAG, true);\n+            })?;\n+            self.state = DeviceState::Enabled;\n         }\n+        Ok(())\n     }\n \n     /// Disables this device\n-    pub fn disable(&mut self) {\n-        command(if self.get_flag(DEVICE_SECOND_FLAG) {\n+    pub fn disable(&mut self) -> Result<(), Ps2Error> {\n+        command(if self.port == DevicePort::Mouse {\n             ControllerCommand::DisablePort2\n         } else {\n             ControllerCommand::DisablePort1\n-        });\n-        self.set_flag(DEVICE_ENABLED_FLAG, false);\n+        })?;\n+        self.state = DeviceState::Available;\n+        Ok(())\n     }\n \n     /// Resets this device\n-    pub fn reset(&mut self) {\n-        self.command(DeviceCommand::Reset);\n+    pub fn reset(&mut self) -> Result<(), Ps2Error> {\n+        self.command(DeviceCommand::Reset)?;\n+\n+        Ok(())\n     }\n \n     /// Sends a command for this PS2 device and returns result\n     #[allow(dead_code)] // Used by drivers depending on PS/2","path":"kernel/src/drivers/ps2/mod.rs","position":null,"original_position":266,"commit_id":"3c190e1d8f174967bc9e62e6062374521fc4881f","original_commit_id":"3c190e1d8f174967bc9e62e6062374521fc4881f","user":{"login":"gegy1000","id":5172118,"avatar_url":"https://avatars3.githubusercontent.com/u/5172118?v=4","gravatar_id":"","url":"https://api.github.com/users/gegy1000","html_url":"https://github.com/gegy1000","followers_url":"https://api.github.com/users/gegy1000/followers","following_url":"https://api.github.com/users/gegy1000/following{/other_user}","gists_url":"https://api.github.com/users/gegy1000/gists{/gist_id}","starred_url":"https://api.github.com/users/gegy1000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gegy1000/subscriptions","organizations_url":"https://api.github.com/users/gegy1000/orgs","repos_url":"https://api.github.com/users/gegy1000/repos","events_url":"https://api.github.com/users/gegy1000/events{/privacy}","received_events_url":"https://api.github.com/users/gegy1000/received_events","type":"User","site_admin":false},"body":"They are allowed because the API is not used yet and that's out of scope.","created_at":"2017-12-09T15:52:56Z","updated_at":"2017-12-09T15:52:56Z","html_url":"https://github.com/Restioson/flower/pull/21#discussion_r155925606","pull_request_url":"https://api.github.com/repos/Restioson/flower/pulls/21","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/Restioson/flower/pulls/comments/155925606"},"html":{"href":"https://github.com/Restioson/flower/pull/21#discussion_r155925606"},"pull_request":{"href":"https://api.github.com/repos/Restioson/flower/pulls/21"}},"in_reply_to_id":155923874},"pull_request":{"url":"https://api.github.com/repos/Restioson/flower/pulls/21","id":157260240,"html_url":"https://github.com/Restioson/flower/pull/21","diff_url":"https://github.com/Restioson/flower/pull/21.diff","patch_url":"https://github.com/Restioson/flower/pull/21.patch","issue_url":"https://api.github.com/repos/Restioson/flower/issues/21","number":21,"state":"open","locked":false,"title":"PS/2 cleanup","user":{"login":"gegy1000","id":5172118,"avatar_url":"https://avatars3.githubusercontent.com/u/5172118?v=4","gravatar_id":"","url":"https://api.github.com/users/gegy1000","html_url":"https://github.com/gegy1000","followers_url":"https://api.github.com/users/gegy1000/followers","following_url":"https://api.github.com/users/gegy1000/following{/other_user}","gists_url":"https://api.github.com/users/gegy1000/gists{/gist_id}","starred_url":"https://api.github.com/users/gegy1000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gegy1000/subscriptions","organizations_url":"https://api.github.com/users/gegy1000/orgs","repos_url":"https://api.github.com/users/gegy1000/repos","events_url":"https://api.github.com/users/gegy1000/events{/privacy}","received_events_url":"https://api.github.com/users/gegy1000/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-12-08T14:53:34Z","updated_at":"2017-12-09T15:52:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5270616003253b50f35e0e3d6a6f64484a54b8e7","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/Restioson/flower/pulls/21/commits","review_comments_url":"https://api.github.com/repos/Restioson/flower/pulls/21/comments","review_comment_url":"https://api.github.com/repos/Restioson/flower/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Restioson/flower/issues/21/comments","statuses_url":"https://api.github.com/repos/Restioson/flower/statuses/3c190e1d8f174967bc9e62e6062374521fc4881f","head":{"label":"Restioson:ps2-cleanup","ref":"ps2-cleanup","sha":"3c190e1d8f174967bc9e62e6062374521fc4881f","user":{"login":"Restioson","id":6688948,"avatar_url":"https://avatars2.githubusercontent.com/u/6688948?v=4","gravatar_id":"","url":"https://api.github.com/users/Restioson","html_url":"https://github.com/Restioson","followers_url":"https://api.github.com/users/Restioson/followers","following_url":"https://api.github.com/users/Restioson/following{/other_user}","gists_url":"https://api.github.com/users/Restioson/gists{/gist_id}","starred_url":"https://api.github.com/users/Restioson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Restioson/subscriptions","organizations_url":"https://api.github.com/users/Restioson/orgs","repos_url":"https://api.github.com/users/Restioson/repos","events_url":"https://api.github.com/users/Restioson/events{/privacy}","received_events_url":"https://api.github.com/users/Restioson/received_events","type":"User","site_admin":false},"repo":{"id":109166201,"name":"flower","full_name":"Restioson/flower","owner":{"login":"Restioson","id":6688948,"avatar_url":"https://avatars2.githubusercontent.com/u/6688948?v=4","gravatar_id":"","url":"https://api.github.com/users/Restioson","html_url":"https://github.com/Restioson","followers_url":"https://api.github.com/users/Restioson/followers","following_url":"https://api.github.com/users/Restioson/following{/other_user}","gists_url":"https://api.github.com/users/Restioson/gists{/gist_id}","starred_url":"https://api.github.com/users/Restioson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Restioson/subscriptions","organizations_url":"https://api.github.com/users/Restioson/orgs","repos_url":"https://api.github.com/users/Restioson/repos","events_url":"https://api.github.com/users/Restioson/events{/privacy}","received_events_url":"https://api.github.com/users/Restioson/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Restioson/flower","description":"A learning OS","fork":false,"url":"https://api.github.com/repos/Restioson/flower","forks_url":"https://api.github.com/repos/Restioson/flower/forks","keys_url":"https://api.github.com/repos/Restioson/flower/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Restioson/flower/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Restioson/flower/teams","hooks_url":"https://api.github.com/repos/Restioson/flower/hooks","issue_events_url":"https://api.github.com/repos/Restioson/flower/issues/events{/number}","events_url":"https://api.github.com/repos/Restioson/flower/events","assignees_url":"https://api.github.com/repos/Restioson/flower/assignees{/user}","branches_url":"https://api.github.com/repos/Restioson/flower/branches{/branch}","tags_url":"https://api.github.com/repos/Restioson/flower/tags","blobs_url":"https://api.github.com/repos/Restioson/flower/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Restioson/flower/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Restioson/flower/git/refs{/sha}","trees_url":"https://api.github.com/repos/Restioson/flower/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Restioson/flower/statuses/{sha}","languages_url":"https://api.github.com/repos/Restioson/flower/languages","stargazers_url":"https://api.github.com/repos/Restioson/flower/stargazers","contributors_url":"https://api.github.com/repos/Restioson/flower/contributors","subscribers_url":"https://api.github.com/repos/Restioson/flower/subscribers","subscription_url":"https://api.github.com/repos/Restioson/flower/subscription","commits_url":"https://api.github.com/repos/Restioson/flower/commits{/sha}","git_commits_url":"https://api.github.com/repos/Restioson/flower/git/commits{/sha}","comments_url":"https://api.github.com/repos/Restioson/flower/comments{/number}","issue_comment_url":"https://api.github.com/repos/Restioson/flower/issues/comments{/number}","contents_url":"https://api.github.com/repos/Restioson/flower/contents/{+path}","compare_url":"https://api.github.com/repos/Restioson/flower/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Restioson/flower/merges","archive_url":"https://api.github.com/repos/Restioson/flower/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Restioson/flower/downloads","issues_url":"https://api.github.com/repos/Restioson/flower/issues{/number}","pulls_url":"https://api.github.com/repos/Restioson/flower/pulls{/number}","milestones_url":"https://api.github.com/repos/Restioson/flower/milestones{/number}","notifications_url":"https://api.github.com/repos/Restioson/flower/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Restioson/flower/labels{/name}","releases_url":"https://api.github.com/repos/Restioson/flower/releases{/id}","deployments_url":"https://api.github.com/repos/Restioson/flower/deployments","created_at":"2017-11-01T18:12:14Z","updated_at":"2017-12-06T13:20:40Z","pushed_at":"2017-12-08T14:53:35Z","git_url":"git://github.com/Restioson/flower.git","ssh_url":"git@github.com:Restioson/flower.git","clone_url":"https://github.com/Restioson/flower.git","svn_url":"https://github.com/Restioson/flower","homepage":null,"size":110,"stargazers_count":1,"watchers_count":1,"language":"Rust","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":11,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":11,"watchers":1,"default_branch":"master"}},"base":{"label":"Restioson:development","ref":"development","sha":"fbd0c7cf77fd720c67f3c7a4ce3afc3c24911132","user":{"login":"Restioson","id":6688948,"avatar_url":"https://avatars2.githubusercontent.com/u/6688948?v=4","gravatar_id":"","url":"https://api.github.com/users/Restioson","html_url":"https://github.com/Restioson","followers_url":"https://api.github.com/users/Restioson/followers","following_url":"https://api.github.com/users/Restioson/following{/other_user}","gists_url":"https://api.github.com/users/Restioson/gists{/gist_id}","starred_url":"https://api.github.com/users/Restioson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Restioson/subscriptions","organizations_url":"https://api.github.com/users/Restioson/orgs","repos_url":"https://api.github.com/users/Restioson/repos","events_url":"https://api.github.com/users/Restioson/events{/privacy}","received_events_url":"https://api.github.com/users/Restioson/received_events","type":"User","site_admin":false},"repo":{"id":109166201,"name":"flower","full_name":"Restioson/flower","owner":{"login":"Restioson","id":6688948,"avatar_url":"https://avatars2.githubusercontent.com/u/6688948?v=4","gravatar_id":"","url":"https://api.github.com/users/Restioson","html_url":"https://github.com/Restioson","followers_url":"https://api.github.com/users/Restioson/followers","following_url":"https://api.github.com/users/Restioson/following{/other_user}","gists_url":"https://api.github.com/users/Restioson/gists{/gist_id}","starred_url":"https://api.github.com/users/Restioson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Restioson/subscriptions","organizations_url":"https://api.github.com/users/Restioson/orgs","repos_url":"https://api.github.com/users/Restioson/repos","events_url":"https://api.github.com/users/Restioson/events{/privacy}","received_events_url":"https://api.github.com/users/Restioson/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Restioson/flower","description":"A learning OS","fork":false,"url":"https://api.github.com/repos/Restioson/flower","forks_url":"https://api.github.com/repos/Restioson/flower/forks","keys_url":"https://api.github.com/repos/Restioson/flower/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Restioson/flower/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Restioson/flower/teams","hooks_url":"https://api.github.com/repos/Restioson/flower/hooks","issue_events_url":"https://api.github.com/repos/Restioson/flower/issues/events{/number}","events_url":"https://api.github.com/repos/Restioson/flower/events","assignees_url":"https://api.github.com/repos/Restioson/flower/assignees{/user}","branches_url":"https://api.github.com/repos/Restioson/flower/branches{/branch}","tags_url":"https://api.github.com/repos/Restioson/flower/tags","blobs_url":"https://api.github.com/repos/Restioson/flower/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Restioson/flower/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Restioson/flower/git/refs{/sha}","trees_url":"https://api.github.com/repos/Restioson/flower/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Restioson/flower/statuses/{sha}","languages_url":"https://api.github.com/repos/Restioson/flower/languages","stargazers_url":"https://api.github.com/repos/Restioson/flower/stargazers","contributors_url":"https://api.github.com/repos/Restioson/flower/contributors","subscribers_url":"https://api.github.com/repos/Restioson/flower/subscribers","subscription_url":"https://api.github.com/repos/Restioson/flower/subscription","commits_url":"https://api.github.com/repos/Restioson/flower/commits{/sha}","git_commits_url":"https://api.github.com/repos/Restioson/flower/git/commits{/sha}","comments_url":"https://api.github.com/repos/Restioson/flower/comments{/number}","issue_comment_url":"https://api.github.com/repos/Restioson/flower/issues/comments{/number}","contents_url":"https://api.github.com/repos/Restioson/flower/contents/{+path}","compare_url":"https://api.github.com/repos/Restioson/flower/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Restioson/flower/merges","archive_url":"https://api.github.com/repos/Restioson/flower/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Restioson/flower/downloads","issues_url":"https://api.github.com/repos/Restioson/flower/issues{/number}","pulls_url":"https://api.github.com/repos/Restioson/flower/pulls{/number}","milestones_url":"https://api.github.com/repos/Restioson/flower/milestones{/number}","notifications_url":"https://api.github.com/repos/Restioson/flower/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Restioson/flower/labels{/name}","releases_url":"https://api.github.com/repos/Restioson/flower/releases{/id}","deployments_url":"https://api.github.com/repos/Restioson/flower/deployments","created_at":"2017-11-01T18:12:14Z","updated_at":"2017-12-06T13:20:40Z","pushed_at":"2017-12-08T14:53:35Z","git_url":"git://github.com/Restioson/flower.git","ssh_url":"git@github.com:Restioson/flower.git","clone_url":"https://github.com/Restioson/flower.git","svn_url":"https://github.com/Restioson/flower","homepage":null,"size":110,"stargazers_count":1,"watchers_count":1,"language":"Rust","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":11,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":11,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Restioson/flower/pulls/21"},"html":{"href":"https://github.com/Restioson/flower/pull/21"},"issue":{"href":"https://api.github.com/repos/Restioson/flower/issues/21"},"comments":{"href":"https://api.github.com/repos/Restioson/flower/issues/21/comments"},"review_comments":{"href":"https://api.github.com/repos/Restioson/flower/pulls/21/comments"},"review_comment":{"href":"https://api.github.com/repos/Restioson/flower/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Restioson/flower/pulls/21/commits"},"statuses":{"href":"https://api.github.com/repos/Restioson/flower/statuses/3c190e1d8f174967bc9e62e6062374521fc4881f"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"gegy1000"}}