{"action":"created","comment":{"url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/pulls/comments/50620468","id":50620468,"diff_hunk":"@@ -551,53 +552,94 @@ def _read(self):\n     @property\n     def value(self):\n         \"\"\"\n-        A value read from the device. This will be a floating point value\n+        The absolute value as read from the device and the relative floating point value\n         between 0 and 1 (scaled according to the number of bits supported by\n         the device).\n         \"\"\"\n-        return self._read() / (2**self._bits - 1)\n+        return self._read(), (self._read() / (2**self._bits - 1))\n \n \n-class MCP3008(AnalogInputDevice):\n-    def __init__(self, channel=0, device=0):\n+\n+class MCP3xxx(AnalogInputDevice):\n+    def __init__(self, channel=0, device=0, bits=None):\n         if not 0 <= channel < 8:\n             raise InputDeviceError('channel must be between 0 and 7')\n-        super(MCP3008, self).__init__(device=device, bits=10)\n+        super(MCP3xxx, self).__init__(device=device, bits=bits)\n         self._channel = channel\n-\n+        self._bits = bits   \n+       \n     @property\n     def channel(self):\n         \"\"\"\n-        The channel to read data from. The MCP3008 has 8 channels (so this will\n-        be between 0 and 7) while the MCP3004 has 4 channels (range 0 to 3).\n+        The channel to read data from. The MCP3208 has 8 channels (so this will\n+        be between 0 and 7) while the MCP3204 has 4 channels (range 0 to 3).\n         \"\"\"\n         return self._channel\n \n+    @property\n+    def bits(self):\n+        \"\"\"\n+        The bit-resolution of the channel. \n+        \"\"\"\n+        return self._bits\n+\n+\n     def _read(self):\n-        # MCP3008 protocol looks like the following:\n+        # MCP3008/04 or MCP3208/04 protocol looks like the following:\n         #\n         #     Byte        0        1        2\n         #     ==== ======== ======== ========\n-        #     Tx   00000001 MCCCxxxx xxxxxxxx\n-        #     Rx   xxxxxxxx xxxxx0RR RRRRRRRR\n+        #     Tx   0001MCCC xxxxxxxx xxxxxxxx\n+        #     Rx   xxxxxxxx x0RRRRRR RRRRxxxx for the 3008/04\n+        #     Rx   xxxxxxxx x0RRRRRR RRRRRRxx for the 3208/04\n         #\n-        # The first byte sent is a start byte (1). The top bit of the second\n-        # holds the mode (M) which is 1 for single-ended read, and 0 for\n-        # differential read (we only support single here), followed by 3-bits\n-        # for the channel (C). The remainder of the transmission are \"don't\n-        # care\" bits (x).\n+        # The transmit bits start with 3 preamble bits \"000\" (to warm up), \n+        # a start bit \"1\" followed by the mode bit(M) which is 1 for\n+        # single-ended read, and 0 for differential read (we only support\n+        # single here), followed by 3-bits for the channel (C). \n+        # The remainder of the transmission are \"don't care\" bits (x).\n         #\n-        # The first byte and the top 5 bits of the second byte received are\n+        # The first byte received and the top 1 bit of the second byte are\n         # don't care bits (x). These are followed by a null bit (0), and then\n-        # the 10 bits of the result (R).\n-        data = self._spi.xfer2([1, (8 + self.channel) << 4, 0])\n-        return ((data[1] & 3) << 8) | data[2]\n+        # the result bits (R). 10 bits for the MCP30xx and 12 bits for the MCP32xx\n \n+        data = self._spi.xfer2([(24 + self.channel), 0, 0])\n+        return ((data[1] & 63) << (self.bits-6)) | (data[2] >> (14 - self.bits))\n \n-class MCP3004(MCP3008):\n+class MCP3004(MCP3xxx):\n     def __init__(self, channel=0, device=0):\n-        # MCP3004 protocol is identical to MCP3008 but the top bit of the\n-        # channel number must be 0 (effectively restricting it to 4 channels)\n+        # MCP3004 is a 10 bit Analog to Ditytal Converter with 4 channels.\n+        # The channel number must be 0, 1, 2 or 3 \n         if not 0 <= channel < 4:\n             raise InputDeviceError('channel must be between 0 and 3')\n-        super(MCP3004, self).__init__(channel, device)\n+        super(MCP3004, self).__init__(channel, device, bits=10)\n+        self._channel = channel\n+\n+class MCP3008(MCP3xxx):\n+    def __init__(self, channel=0, device=0):\n+        # MCP3208 is a 10 bit Analog to Ditytal Converter with 8 channels.\n+        # The channel number must be 0, 1, 2, 3, 4, 5, 6, 7 or 8 \n+        if not 0 <= channel < 8:\n+            raise InputDeviceError('channel must be between 0 and 7')\n+        super(MCP3008, self).__init__(device=device, bits=10)\n+        self._channel = channel\n+\n+class MCP3204(MCP3xxx):\n+    def __init__(self, channel=0, device=0, bits=12):\n+        # MCP3204 is a 12 bit Analog to Ditytal Converter with 4 channels.","path":"gpiozero/input_devices.py","position":110,"original_position":110,"commit_id":"b89ecdbea13f74e095cd366a795ca7817eea00c5","original_commit_id":"b89ecdbea13f74e095cd366a795ca7817eea00c5","user":{"login":"pcopa","id":15312957,"avatar_url":"https://avatars.githubusercontent.com/u/15312957?v=3","gravatar_id":"","url":"https://api.github.com/users/pcopa","html_url":"https://github.com/pcopa","followers_url":"https://api.github.com/users/pcopa/followers","following_url":"https://api.github.com/users/pcopa/following{/other_user}","gists_url":"https://api.github.com/users/pcopa/gists{/gist_id}","starred_url":"https://api.github.com/users/pcopa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcopa/subscriptions","organizations_url":"https://api.github.com/users/pcopa/orgs","repos_url":"https://api.github.com/users/pcopa/repos","events_url":"https://api.github.com/users/pcopa/events{/privacy}","received_events_url":"https://api.github.com/users/pcopa/received_events","type":"User","site_admin":false},"body":"Spelling: change \"Ditytal\" to \"Digital\"","created_at":"2016-01-23T13:50:19Z","updated_at":"2016-01-23T13:50:19Z","html_url":"https://github.com/RPi-Distro/python-gpiozero/pull/150#discussion_r50620468","pull_request_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/pulls/150","_links":{"self":{"href":"https://api.github.com/repos/RPi-Distro/python-gpiozero/pulls/comments/50620468"},"html":{"href":"https://github.com/RPi-Distro/python-gpiozero/pull/150#discussion_r50620468"},"pull_request":{"href":"https://api.github.com/repos/RPi-Distro/python-gpiozero/pulls/150"}}},"pull_request":{"url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/pulls/150","id":56416126,"html_url":"https://github.com/RPi-Distro/python-gpiozero/pull/150","diff_url":"https://github.com/RPi-Distro/python-gpiozero/pull/150.diff","patch_url":"https://github.com/RPi-Distro/python-gpiozero/pull/150.patch","issue_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/issues/150","number":150,"state":"open","locked":false,"title":" Adding MCP3208/3204 12 bit ADC with 8 or 4 channels","user":{"login":"pcopa","id":15312957,"avatar_url":"https://avatars.githubusercontent.com/u/15312957?v=3","gravatar_id":"","url":"https://api.github.com/users/pcopa","html_url":"https://github.com/pcopa","followers_url":"https://api.github.com/users/pcopa/followers","following_url":"https://api.github.com/users/pcopa/following{/other_user}","gists_url":"https://api.github.com/users/pcopa/gists{/gist_id}","starred_url":"https://api.github.com/users/pcopa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcopa/subscriptions","organizations_url":"https://api.github.com/users/pcopa/orgs","repos_url":"https://api.github.com/users/pcopa/repos","events_url":"https://api.github.com/users/pcopa/events{/privacy}","received_events_url":"https://api.github.com/users/pcopa/received_events","type":"User","site_admin":false},"body":"The text needs more editing, but the code is running stable on my Pi 2.\r\n\r\n ","created_at":"2016-01-19T02:57:40Z","updated_at":"2016-01-23T13:50:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dc817a9aed528b7d0953331879ea2b2db9cd05a6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/pulls/150/commits","review_comments_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/pulls/150/comments","review_comment_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/pulls/comments{/number}","comments_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/issues/150/comments","statuses_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/statuses/b89ecdbea13f74e095cd366a795ca7817eea00c5","head":{"label":"pcopa:master","ref":"master","sha":"b89ecdbea13f74e095cd366a795ca7817eea00c5","user":{"login":"pcopa","id":15312957,"avatar_url":"https://avatars.githubusercontent.com/u/15312957?v=3","gravatar_id":"","url":"https://api.github.com/users/pcopa","html_url":"https://github.com/pcopa","followers_url":"https://api.github.com/users/pcopa/followers","following_url":"https://api.github.com/users/pcopa/following{/other_user}","gists_url":"https://api.github.com/users/pcopa/gists{/gist_id}","starred_url":"https://api.github.com/users/pcopa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcopa/subscriptions","organizations_url":"https://api.github.com/users/pcopa/orgs","repos_url":"https://api.github.com/users/pcopa/repos","events_url":"https://api.github.com/users/pcopa/events{/privacy}","received_events_url":"https://api.github.com/users/pcopa/received_events","type":"User","site_admin":false},"repo":{"id":49848185,"name":"python-gpiozero","full_name":"pcopa/python-gpiozero","owner":{"login":"pcopa","id":15312957,"avatar_url":"https://avatars.githubusercontent.com/u/15312957?v=3","gravatar_id":"","url":"https://api.github.com/users/pcopa","html_url":"https://github.com/pcopa","followers_url":"https://api.github.com/users/pcopa/followers","following_url":"https://api.github.com/users/pcopa/following{/other_user}","gists_url":"https://api.github.com/users/pcopa/gists{/gist_id}","starred_url":"https://api.github.com/users/pcopa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcopa/subscriptions","organizations_url":"https://api.github.com/users/pcopa/orgs","repos_url":"https://api.github.com/users/pcopa/repos","events_url":"https://api.github.com/users/pcopa/events{/privacy}","received_events_url":"https://api.github.com/users/pcopa/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pcopa/python-gpiozero","description":"A simple interface to everyday GPIO components used with Raspberry Pi","fork":true,"url":"https://api.github.com/repos/pcopa/python-gpiozero","forks_url":"https://api.github.com/repos/pcopa/python-gpiozero/forks","keys_url":"https://api.github.com/repos/pcopa/python-gpiozero/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pcopa/python-gpiozero/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pcopa/python-gpiozero/teams","hooks_url":"https://api.github.com/repos/pcopa/python-gpiozero/hooks","issue_events_url":"https://api.github.com/repos/pcopa/python-gpiozero/issues/events{/number}","events_url":"https://api.github.com/repos/pcopa/python-gpiozero/events","assignees_url":"https://api.github.com/repos/pcopa/python-gpiozero/assignees{/user}","branches_url":"https://api.github.com/repos/pcopa/python-gpiozero/branches{/branch}","tags_url":"https://api.github.com/repos/pcopa/python-gpiozero/tags","blobs_url":"https://api.github.com/repos/pcopa/python-gpiozero/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pcopa/python-gpiozero/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pcopa/python-gpiozero/git/refs{/sha}","trees_url":"https://api.github.com/repos/pcopa/python-gpiozero/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pcopa/python-gpiozero/statuses/{sha}","languages_url":"https://api.github.com/repos/pcopa/python-gpiozero/languages","stargazers_url":"https://api.github.com/repos/pcopa/python-gpiozero/stargazers","contributors_url":"https://api.github.com/repos/pcopa/python-gpiozero/contributors","subscribers_url":"https://api.github.com/repos/pcopa/python-gpiozero/subscribers","subscription_url":"https://api.github.com/repos/pcopa/python-gpiozero/subscription","commits_url":"https://api.github.com/repos/pcopa/python-gpiozero/commits{/sha}","git_commits_url":"https://api.github.com/repos/pcopa/python-gpiozero/git/commits{/sha}","comments_url":"https://api.github.com/repos/pcopa/python-gpiozero/comments{/number}","issue_comment_url":"https://api.github.com/repos/pcopa/python-gpiozero/issues/comments{/number}","contents_url":"https://api.github.com/repos/pcopa/python-gpiozero/contents/{+path}","compare_url":"https://api.github.com/repos/pcopa/python-gpiozero/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pcopa/python-gpiozero/merges","archive_url":"https://api.github.com/repos/pcopa/python-gpiozero/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pcopa/python-gpiozero/downloads","issues_url":"https://api.github.com/repos/pcopa/python-gpiozero/issues{/number}","pulls_url":"https://api.github.com/repos/pcopa/python-gpiozero/pulls{/number}","milestones_url":"https://api.github.com/repos/pcopa/python-gpiozero/milestones{/number}","notifications_url":"https://api.github.com/repos/pcopa/python-gpiozero/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pcopa/python-gpiozero/labels{/name}","releases_url":"https://api.github.com/repos/pcopa/python-gpiozero/releases{/id}","deployments_url":"https://api.github.com/repos/pcopa/python-gpiozero/deployments","created_at":"2016-01-18T02:53:20Z","updated_at":"2016-01-18T02:53:24Z","pushed_at":"2016-01-23T01:40:34Z","git_url":"git://github.com/pcopa/python-gpiozero.git","ssh_url":"git@github.com:pcopa/python-gpiozero.git","clone_url":"https://github.com/pcopa/python-gpiozero.git","svn_url":"https://github.com/pcopa/python-gpiozero","homepage":"http://pythonhosted.org/gpiozero/","size":330,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"RPi-Distro:master","ref":"master","sha":"15ce68d1a769073888ee4653e46fe48a250a2390","user":{"login":"RPi-Distro","id":12276469,"avatar_url":"https://avatars.githubusercontent.com/u/12276469?v=3","gravatar_id":"","url":"https://api.github.com/users/RPi-Distro","html_url":"https://github.com/RPi-Distro","followers_url":"https://api.github.com/users/RPi-Distro/followers","following_url":"https://api.github.com/users/RPi-Distro/following{/other_user}","gists_url":"https://api.github.com/users/RPi-Distro/gists{/gist_id}","starred_url":"https://api.github.com/users/RPi-Distro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RPi-Distro/subscriptions","organizations_url":"https://api.github.com/users/RPi-Distro/orgs","repos_url":"https://api.github.com/users/RPi-Distro/repos","events_url":"https://api.github.com/users/RPi-Distro/events{/privacy}","received_events_url":"https://api.github.com/users/RPi-Distro/received_events","type":"Organization","site_admin":false},"repo":{"id":42439862,"name":"python-gpiozero","full_name":"RPi-Distro/python-gpiozero","owner":{"login":"RPi-Distro","id":12276469,"avatar_url":"https://avatars.githubusercontent.com/u/12276469?v=3","gravatar_id":"","url":"https://api.github.com/users/RPi-Distro","html_url":"https://github.com/RPi-Distro","followers_url":"https://api.github.com/users/RPi-Distro/followers","following_url":"https://api.github.com/users/RPi-Distro/following{/other_user}","gists_url":"https://api.github.com/users/RPi-Distro/gists{/gist_id}","starred_url":"https://api.github.com/users/RPi-Distro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RPi-Distro/subscriptions","organizations_url":"https://api.github.com/users/RPi-Distro/orgs","repos_url":"https://api.github.com/users/RPi-Distro/repos","events_url":"https://api.github.com/users/RPi-Distro/events{/privacy}","received_events_url":"https://api.github.com/users/RPi-Distro/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/RPi-Distro/python-gpiozero","description":"A simple interface to everyday GPIO components used with Raspberry Pi","fork":false,"url":"https://api.github.com/repos/RPi-Distro/python-gpiozero","forks_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/forks","keys_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/teams","hooks_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/hooks","issue_events_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/issues/events{/number}","events_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/events","assignees_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/assignees{/user}","branches_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/branches{/branch}","tags_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/tags","blobs_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/git/refs{/sha}","trees_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/statuses/{sha}","languages_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/languages","stargazers_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/stargazers","contributors_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/contributors","subscribers_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/subscribers","subscription_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/subscription","commits_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/commits{/sha}","git_commits_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/git/commits{/sha}","comments_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/comments{/number}","issue_comment_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/issues/comments{/number}","contents_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/contents/{+path}","compare_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/merges","archive_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/downloads","issues_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/issues{/number}","pulls_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/pulls{/number}","milestones_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/milestones{/number}","notifications_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/labels{/name}","releases_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/releases{/id}","deployments_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/deployments","created_at":"2015-09-14T09:36:03Z","updated_at":"2016-01-22T15:55:36Z","pushed_at":"2016-01-23T01:40:34Z","git_url":"git://github.com/RPi-Distro/python-gpiozero.git","ssh_url":"git@github.com:RPi-Distro/python-gpiozero.git","clone_url":"https://github.com/RPi-Distro/python-gpiozero.git","svn_url":"https://github.com/RPi-Distro/python-gpiozero","homepage":"http://pythonhosted.org/gpiozero/","size":571,"stargazers_count":102,"watchers_count":102,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":29,"mirror_url":null,"open_issues_count":32,"forks":29,"open_issues":32,"watchers":102,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/RPi-Distro/python-gpiozero/pulls/150"},"html":{"href":"https://github.com/RPi-Distro/python-gpiozero/pull/150"},"issue":{"href":"https://api.github.com/repos/RPi-Distro/python-gpiozero/issues/150"},"comments":{"href":"https://api.github.com/repos/RPi-Distro/python-gpiozero/issues/150/comments"},"review_comments":{"href":"https://api.github.com/repos/RPi-Distro/python-gpiozero/pulls/150/comments"},"review_comment":{"href":"https://api.github.com/repos/RPi-Distro/python-gpiozero/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/RPi-Distro/python-gpiozero/pulls/150/commits"},"statuses":{"href":"https://api.github.com/repos/RPi-Distro/python-gpiozero/statuses/b89ecdbea13f74e095cd366a795ca7817eea00c5"}}}}