Merge pull request #281 from lurch/adc_tweaks

Tweak the ADC classes to make the docs neater and more accurate
This commit is contained in:
Dave Jones
2016-09-08 15:48:08 +01:00
committed by GitHub
5 changed files with 203 additions and 92 deletions

View File

@@ -9,6 +9,8 @@ digraph classes {
SPIDevice;
AnalogInputDevice;
MCP3xxx;
MCP30xx;
MCP32xx;
MCP33xx;
/* Concrete classes */
@@ -16,11 +18,17 @@ digraph classes {
SPIDevice->Device;
AnalogInputDevice->SPIDevice;
MCP3xxx->AnalogInputDevice;
MCP30xx->MCP3xxx;
MCP32xx->MCP3xxx;
MCP33xx->MCP3xxx;
MCP3004->MCP3xxx;
MCP3008->MCP3xxx;
MCP3204->MCP3xxx;
MCP3208->MCP3xxx;
MCP3001->MCP30xx;
MCP3002->MCP30xx;
MCP3004->MCP30xx;
MCP3008->MCP30xx;
MCP3201->MCP32xx;
MCP3202->MCP32xx;
MCP3204->MCP32xx;
MCP3208->MCP32xx;
MCP3301->MCP33xx;
MCP3302->MCP33xx;
MCP3304->MCP33xx;

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 44 KiB

View File

@@ -4,125 +4,185 @@
<!-- Generated by graphviz version 2.36.0 (20140111.2315)
-->
<!-- Title: classes Pages: 1 -->
<svg width="469pt" height="404pt"
viewBox="0.00 0.00 469.00 404.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<svg width="870pt" height="404pt"
viewBox="0.00 0.00 870.00 404.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 400)">
<title>classes</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-400 465,-400 465,4 -4,4"/>
<polygon fill="white" stroke="none" points="-4,4 -4,-400 866,-400 866,4 -4,4"/>
<!-- Device -->
<g id="node1" class="node"><title>Device</title>
<polygon fill="#9ec6e0" stroke="#9ec6e0" points="297,-396 243,-396 243,-360 297,-360 297,-396"/>
<text text-anchor="middle" x="270" y="-375.5" font-family="Sans" font-size="10.00" fill="#000000">Device</text>
<polygon fill="#9ec6e0" stroke="#9ec6e0" points="498,-396 444,-396 444,-360 498,-360 498,-396"/>
<text text-anchor="middle" x="471" y="-375.5" font-family="Sans" font-size="10.00" fill="#000000">Device</text>
</g>
<!-- SPIDevice -->
<g id="node2" class="node"><title>SPIDevice</title>
<polygon fill="#9ec6e0" stroke="#9ec6e0" points="302,-324 238,-324 238,-288 302,-288 302,-324"/>
<text text-anchor="middle" x="270" y="-303.5" font-family="Sans" font-size="10.00" fill="#000000">SPIDevice</text>
<polygon fill="#9ec6e0" stroke="#9ec6e0" points="503,-324 439,-324 439,-288 503,-288 503,-324"/>
<text text-anchor="middle" x="471" y="-303.5" font-family="Sans" font-size="10.00" fill="#000000">SPIDevice</text>
</g>
<!-- SPIDevice&#45;&gt;Device -->
<g id="edge1" class="edge"><title>SPIDevice&#45;&gt;Device</title>
<path fill="none" stroke="black" d="M270,-324.303C270,-332.017 270,-341.288 270,-349.888"/>
<polygon fill="black" stroke="black" points="266.5,-349.896 270,-359.896 273.5,-349.896 266.5,-349.896"/>
<path fill="none" stroke="black" d="M471,-324.303C471,-332.017 471,-341.288 471,-349.888"/>
<polygon fill="black" stroke="black" points="467.5,-349.896 471,-359.896 474.5,-349.896 467.5,-349.896"/>
</g>
<!-- AnalogInputDevice -->
<g id="node3" class="node"><title>AnalogInputDevice</title>
<polygon fill="#9ec6e0" stroke="#9ec6e0" points="323,-252 217,-252 217,-216 323,-216 323,-252"/>
<text text-anchor="middle" x="270" y="-231.5" font-family="Sans" font-size="10.00" fill="#000000">AnalogInputDevice</text>
<polygon fill="#9ec6e0" stroke="#9ec6e0" points="524,-252 418,-252 418,-216 524,-216 524,-252"/>
<text text-anchor="middle" x="471" y="-231.5" font-family="Sans" font-size="10.00" fill="#000000">AnalogInputDevice</text>
</g>
<!-- AnalogInputDevice&#45;&gt;SPIDevice -->
<g id="edge2" class="edge"><title>AnalogInputDevice&#45;&gt;SPIDevice</title>
<path fill="none" stroke="black" d="M270,-252.303C270,-260.017 270,-269.288 270,-277.888"/>
<polygon fill="black" stroke="black" points="266.5,-277.896 270,-287.896 273.5,-277.896 266.5,-277.896"/>
<path fill="none" stroke="black" d="M471,-252.303C471,-260.017 471,-269.288 471,-277.888"/>
<polygon fill="black" stroke="black" points="467.5,-277.896 471,-287.896 474.5,-277.896 467.5,-277.896"/>
</g>
<!-- MCP3xxx -->
<g id="node4" class="node"><title>MCP3xxx</title>
<polygon fill="#9ec6e0" stroke="#9ec6e0" points="299.5,-180 240.5,-180 240.5,-144 299.5,-144 299.5,-180"/>
<text text-anchor="middle" x="270" y="-159.5" font-family="Sans" font-size="10.00" fill="#000000">MCP3xxx</text>
<polygon fill="#9ec6e0" stroke="#9ec6e0" points="500.5,-180 441.5,-180 441.5,-144 500.5,-144 500.5,-180"/>
<text text-anchor="middle" x="471" y="-159.5" font-family="Sans" font-size="10.00" fill="#000000">MCP3xxx</text>
</g>
<!-- MCP3xxx&#45;&gt;AnalogInputDevice -->
<g id="edge3" class="edge"><title>MCP3xxx&#45;&gt;AnalogInputDevice</title>
<path fill="none" stroke="black" d="M270,-180.303C270,-188.017 270,-197.288 270,-205.888"/>
<polygon fill="black" stroke="black" points="266.5,-205.896 270,-215.896 273.5,-205.896 266.5,-205.896"/>
<path fill="none" stroke="black" d="M471,-180.303C471,-188.017 471,-197.288 471,-205.888"/>
<polygon fill="black" stroke="black" points="467.5,-205.896 471,-215.896 474.5,-205.896 467.5,-205.896"/>
</g>
<!-- MCP30xx -->
<g id="node5" class="node"><title>MCP30xx</title>
<polygon fill="#9ec6e0" stroke="#9ec6e0" points="221,-108 161,-108 161,-72 221,-72 221,-108"/>
<text text-anchor="middle" x="191" y="-87.5" font-family="Sans" font-size="10.00" fill="#000000">MCP30xx</text>
</g>
<!-- MCP30xx&#45;&gt;MCP3xxx -->
<g id="edge4" class="edge"><title>MCP30xx&#45;&gt;MCP3xxx</title>
<path fill="none" stroke="black" d="M220.7,-98.425C271.447,-111.112 374.849,-136.962 431.579,-151.145"/>
<polygon fill="black" stroke="black" points="431.055,-154.621 441.605,-153.651 432.752,-147.83 431.055,-154.621"/>
</g>
<!-- MCP32xx -->
<g id="node6" class="node"><title>MCP32xx</title>
<polygon fill="#9ec6e0" stroke="#9ec6e0" points="501,-108 441,-108 441,-72 501,-72 501,-108"/>
<text text-anchor="middle" x="471" y="-87.5" font-family="Sans" font-size="10.00" fill="#000000">MCP32xx</text>
</g>
<!-- MCP32xx&#45;&gt;MCP3xxx -->
<g id="edge5" class="edge"><title>MCP32xx&#45;&gt;MCP3xxx</title>
<path fill="none" stroke="black" d="M471,-108.303C471,-116.017 471,-125.288 471,-133.888"/>
<polygon fill="black" stroke="black" points="467.5,-133.896 471,-143.896 474.5,-133.896 467.5,-133.896"/>
</g>
<!-- MCP33xx -->
<g id="node5" class="node"><title>MCP33xx</title>
<polygon fill="#9ec6e0" stroke="#9ec6e0" points="141,-108 81,-108 81,-72 141,-72 141,-108"/>
<text text-anchor="middle" x="111" y="-87.5" font-family="Sans" font-size="10.00" fill="#000000">MCP33xx</text>
<g id="node7" class="node"><title>MCP33xx</title>
<polygon fill="#9ec6e0" stroke="#9ec6e0" points="741,-108 681,-108 681,-72 741,-72 741,-108"/>
<text text-anchor="middle" x="711" y="-87.5" font-family="Sans" font-size="10.00" fill="#000000">MCP33xx</text>
</g>
<!-- MCP33xx&#45;&gt;MCP3xxx -->
<g id="edge4" class="edge"><title>MCP33xx&#45;&gt;MCP3xxx</title>
<path fill="none" stroke="black" d="M140.534,-104.002C166.081,-115.249 203.204,-131.593 231.154,-143.898"/>
<polygon fill="black" stroke="black" points="230.062,-147.241 240.624,-148.067 232.882,-140.835 230.062,-147.241"/>
<g id="edge6" class="edge"><title>MCP33xx&#45;&gt;MCP3xxx</title>
<path fill="none" stroke="black" d="M681.089,-99.724C637.918,-112.316 558.088,-135.599 510.235,-149.556"/>
<polygon fill="black" stroke="black" points="509.154,-146.226 500.534,-152.386 511.114,-152.946 509.154,-146.226"/>
</g>
<!-- MCP3001 -->
<g id="node8" class="node"><title>MCP3001</title>
<polygon fill="#2980b9" stroke="#2980b9" points="62,-36 3.55271e-15,-36 3.55271e-15,-0 62,-0 62,-36"/>
<text text-anchor="middle" x="31" y="-15.5" font-family="Sans" font-size="10.00" fill="#ffffff">MCP3001</text>
</g>
<!-- MCP3001&#45;&gt;MCP30xx -->
<g id="edge7" class="edge"><title>MCP3001&#45;&gt;MCP30xx</title>
<path fill="none" stroke="black" d="M61.8496,-32.4967C87.5187,-43.7269 124.21,-59.7795 151.929,-71.9066"/>
<polygon fill="black" stroke="black" points="150.762,-75.2164 161.327,-76.018 153.568,-68.8032 150.762,-75.2164"/>
</g>
<!-- MCP3002 -->
<g id="node9" class="node"><title>MCP3002</title>
<polygon fill="#2980b9" stroke="#2980b9" points="142,-36 80,-36 80,-0 142,-0 142,-36"/>
<text text-anchor="middle" x="111" y="-15.5" font-family="Sans" font-size="10.00" fill="#ffffff">MCP3002</text>
</g>
<!-- MCP3002&#45;&gt;MCP30xx -->
<g id="edge8" class="edge"><title>MCP3002&#45;&gt;MCP30xx</title>
<path fill="none" stroke="black" d="M130.775,-36.3034C140.754,-45.0345 153.011,-55.7595 163.857,-65.2497"/>
<polygon fill="black" stroke="black" points="161.622,-67.9446 171.452,-71.8957 166.231,-62.6766 161.622,-67.9446"/>
</g>
<!-- MCP3004 -->
<g id="node6" class="node"><title>MCP3004</title>
<polygon fill="#2980b9" stroke="#2980b9" points="221,-108 159,-108 159,-72 221,-72 221,-108"/>
<text text-anchor="middle" x="190" y="-87.5" font-family="Sans" font-size="10.00" fill="#ffffff">MCP3004</text>
<g id="node10" class="node"><title>MCP3004</title>
<polygon fill="#2980b9" stroke="#2980b9" points="222,-36 160,-36 160,-0 222,-0 222,-36"/>
<text text-anchor="middle" x="191" y="-15.5" font-family="Sans" font-size="10.00" fill="#ffffff">MCP3004</text>
</g>
<!-- MCP3004&#45;&gt;MCP3xxx -->
<g id="edge5" class="edge"><title>MCP3004&#45;&gt;MCP3xxx</title>
<path fill="none" stroke="black" d="M209.775,-108.303C219.754,-117.035 232.011,-127.76 242.857,-137.25"/>
<polygon fill="black" stroke="black" points="240.622,-139.945 250.452,-143.896 245.231,-134.677 240.622,-139.945"/>
<!-- MCP3004&#45;&gt;MCP30xx -->
<g id="edge9" class="edge"><title>MCP3004&#45;&gt;MCP30xx</title>
<path fill="none" stroke="black" d="M191,-36.3034C191,-44.0173 191,-53.2875 191,-61.8876"/>
<polygon fill="black" stroke="black" points="187.5,-61.8956 191,-71.8957 194.5,-61.8957 187.5,-61.8956"/>
</g>
<!-- MCP3008 -->
<g id="node7" class="node"><title>MCP3008</title>
<polygon fill="#2980b9" stroke="#2980b9" points="301,-108 239,-108 239,-72 301,-72 301,-108"/>
<text text-anchor="middle" x="270" y="-87.5" font-family="Sans" font-size="10.00" fill="#ffffff">MCP3008</text>
<g id="node11" class="node"><title>MCP3008</title>
<polygon fill="#2980b9" stroke="#2980b9" points="302,-36 240,-36 240,-0 302,-0 302,-36"/>
<text text-anchor="middle" x="271" y="-15.5" font-family="Sans" font-size="10.00" fill="#ffffff">MCP3008</text>
</g>
<!-- MCP3008&#45;&gt;MCP3xxx -->
<g id="edge6" class="edge"><title>MCP3008&#45;&gt;MCP3xxx</title>
<path fill="none" stroke="black" d="M270,-108.303C270,-116.017 270,-125.288 270,-133.888"/>
<polygon fill="black" stroke="black" points="266.5,-133.896 270,-143.896 273.5,-133.896 266.5,-133.896"/>
<!-- MCP3008&#45;&gt;MCP30xx -->
<g id="edge10" class="edge"><title>MCP3008&#45;&gt;MCP30xx</title>
<path fill="none" stroke="black" d="M251.225,-36.3034C241.246,-45.0345 228.989,-55.7595 218.143,-65.2497"/>
<polygon fill="black" stroke="black" points="215.769,-62.6766 210.548,-71.8957 220.378,-67.9446 215.769,-62.6766"/>
</g>
<!-- MCP3201 -->
<g id="node12" class="node"><title>MCP3201</title>
<polygon fill="#2980b9" stroke="#2980b9" points="382,-36 320,-36 320,-0 382,-0 382,-36"/>
<text text-anchor="middle" x="351" y="-15.5" font-family="Sans" font-size="10.00" fill="#ffffff">MCP3201</text>
</g>
<!-- MCP3201&#45;&gt;MCP32xx -->
<g id="edge11" class="edge"><title>MCP3201&#45;&gt;MCP32xx</title>
<path fill="none" stroke="black" d="M380.355,-36.1239C396.045,-45.2764 415.557,-56.6583 432.454,-66.515"/>
<polygon fill="black" stroke="black" points="431.13,-69.7947 441.532,-71.8102 434.658,-63.7483 431.13,-69.7947"/>
</g>
<!-- MCP3202 -->
<g id="node13" class="node"><title>MCP3202</title>
<polygon fill="#2980b9" stroke="#2980b9" points="462,-36 400,-36 400,-0 462,-0 462,-36"/>
<text text-anchor="middle" x="431" y="-15.5" font-family="Sans" font-size="10.00" fill="#ffffff">MCP3202</text>
</g>
<!-- MCP3202&#45;&gt;MCP32xx -->
<g id="edge12" class="edge"><title>MCP3202&#45;&gt;MCP32xx</title>
<path fill="none" stroke="black" d="M440.888,-36.3034C445.489,-44.3564 451.06,-54.1055 456.153,-63.0176"/>
<polygon fill="black" stroke="black" points="453.226,-64.9497 461.226,-71.8957 459.304,-61.4767 453.226,-64.9497"/>
</g>
<!-- MCP3204 -->
<g id="node8" class="node"><title>MCP3204</title>
<polygon fill="#2980b9" stroke="#2980b9" points="381,-108 319,-108 319,-72 381,-72 381,-108"/>
<text text-anchor="middle" x="350" y="-87.5" font-family="Sans" font-size="10.00" fill="#ffffff">MCP3204</text>
<g id="node14" class="node"><title>MCP3204</title>
<polygon fill="#2980b9" stroke="#2980b9" points="542,-36 480,-36 480,-0 542,-0 542,-36"/>
<text text-anchor="middle" x="511" y="-15.5" font-family="Sans" font-size="10.00" fill="#ffffff">MCP3204</text>
</g>
<!-- MCP3204&#45;&gt;MCP3xxx -->
<g id="edge7" class="edge"><title>MCP3204&#45;&gt;MCP3xxx</title>
<path fill="none" stroke="black" d="M330.225,-108.303C320.246,-117.035 307.989,-127.76 297.143,-137.25"/>
<polygon fill="black" stroke="black" points="294.769,-134.677 289.548,-143.896 299.378,-139.945 294.769,-134.677"/>
<!-- MCP3204&#45;&gt;MCP32xx -->
<g id="edge13" class="edge"><title>MCP3204&#45;&gt;MCP32xx</title>
<path fill="none" stroke="black" d="M501.112,-36.3034C496.511,-44.3564 490.94,-54.1055 485.847,-63.0176"/>
<polygon fill="black" stroke="black" points="482.696,-61.4767 480.774,-71.8957 488.774,-64.9497 482.696,-61.4767"/>
</g>
<!-- MCP3208 -->
<g id="node9" class="node"><title>MCP3208</title>
<polygon fill="#2980b9" stroke="#2980b9" points="461,-108 399,-108 399,-72 461,-72 461,-108"/>
<text text-anchor="middle" x="430" y="-87.5" font-family="Sans" font-size="10.00" fill="#ffffff">MCP3208</text>
<g id="node15" class="node"><title>MCP3208</title>
<polygon fill="#2980b9" stroke="#2980b9" points="622,-36 560,-36 560,-0 622,-0 622,-36"/>
<text text-anchor="middle" x="591" y="-15.5" font-family="Sans" font-size="10.00" fill="#ffffff">MCP3208</text>
</g>
<!-- MCP3208&#45;&gt;MCP3xxx -->
<g id="edge8" class="edge"><title>MCP3208&#45;&gt;MCP3xxx</title>
<path fill="none" stroke="black" d="M399.15,-104.497C373.4,-115.762 336.557,-131.881 308.808,-144.022"/>
<polygon fill="black" stroke="black" points="307.163,-140.921 299.405,-148.135 309.969,-147.334 307.163,-140.921"/>
<!-- MCP3208&#45;&gt;MCP32xx -->
<g id="edge14" class="edge"><title>MCP3208&#45;&gt;MCP32xx</title>
<path fill="none" stroke="black" d="M561.645,-36.1239C545.955,-45.2764 526.443,-56.6583 509.546,-66.515"/>
<polygon fill="black" stroke="black" points="507.342,-63.7483 500.468,-71.8102 510.87,-69.7947 507.342,-63.7483"/>
</g>
<!-- MCP3301 -->
<g id="node10" class="node"><title>MCP3301</title>
<polygon fill="#2980b9" stroke="#2980b9" points="62,-36 3.55271e-15,-36 3.55271e-15,-0 62,-0 62,-36"/>
<text text-anchor="middle" x="31" y="-15.5" font-family="Sans" font-size="10.00" fill="#ffffff">MCP3301</text>
<g id="node16" class="node"><title>MCP3301</title>
<polygon fill="#2980b9" stroke="#2980b9" points="702,-36 640,-36 640,-0 702,-0 702,-36"/>
<text text-anchor="middle" x="671" y="-15.5" font-family="Sans" font-size="10.00" fill="#ffffff">MCP3301</text>
</g>
<!-- MCP3301&#45;&gt;MCP33xx -->
<g id="edge9" class="edge"><title>MCP3301&#45;&gt;MCP33xx</title>
<path fill="none" stroke="black" d="M50.7753,-36.3034C60.7537,-45.0345 73.0109,-55.7595 83.8568,-65.2497"/>
<polygon fill="black" stroke="black" points="81.6216,-67.9446 91.4522,-71.8957 86.2312,-62.6766 81.6216,-67.9446"/>
<g id="edge15" class="edge"><title>MCP3301&#45;&gt;MCP33xx</title>
<path fill="none" stroke="black" d="M680.888,-36.3034C685.489,-44.3564 691.06,-54.1055 696.153,-63.0176"/>
<polygon fill="black" stroke="black" points="693.226,-64.9497 701.226,-71.8957 699.304,-61.4767 693.226,-64.9497"/>
</g>
<!-- MCP3302 -->
<g id="node11" class="node"><title>MCP3302</title>
<polygon fill="#2980b9" stroke="#2980b9" points="142,-36 80,-36 80,-0 142,-0 142,-36"/>
<text text-anchor="middle" x="111" y="-15.5" font-family="Sans" font-size="10.00" fill="#ffffff">MCP3302</text>
<g id="node17" class="node"><title>MCP3302</title>
<polygon fill="#2980b9" stroke="#2980b9" points="782,-36 720,-36 720,-0 782,-0 782,-36"/>
<text text-anchor="middle" x="751" y="-15.5" font-family="Sans" font-size="10.00" fill="#ffffff">MCP3302</text>
</g>
<!-- MCP3302&#45;&gt;MCP33xx -->
<g id="edge10" class="edge"><title>MCP3302&#45;&gt;MCP33xx</title>
<path fill="none" stroke="black" d="M111,-36.3034C111,-44.0173 111,-53.2875 111,-61.8876"/>
<polygon fill="black" stroke="black" points="107.5,-61.8956 111,-71.8957 114.5,-61.8957 107.5,-61.8956"/>
<g id="edge16" class="edge"><title>MCP3302&#45;&gt;MCP33xx</title>
<path fill="none" stroke="black" d="M741.112,-36.3034C736.511,-44.3564 730.94,-54.1055 725.847,-63.0176"/>
<polygon fill="black" stroke="black" points="722.696,-61.4767 720.774,-71.8957 728.774,-64.9497 722.696,-61.4767"/>
</g>
<!-- MCP3304 -->
<g id="node12" class="node"><title>MCP3304</title>
<polygon fill="#2980b9" stroke="#2980b9" points="222,-36 160,-36 160,-0 222,-0 222,-36"/>
<text text-anchor="middle" x="191" y="-15.5" font-family="Sans" font-size="10.00" fill="#ffffff">MCP3304</text>
<g id="node18" class="node"><title>MCP3304</title>
<polygon fill="#2980b9" stroke="#2980b9" points="862,-36 800,-36 800,-0 862,-0 862,-36"/>
<text text-anchor="middle" x="831" y="-15.5" font-family="Sans" font-size="10.00" fill="#ffffff">MCP3304</text>
</g>
<!-- MCP3304&#45;&gt;MCP33xx -->
<g id="edge11" class="edge"><title>MCP3304&#45;&gt;MCP33xx</title>
<path fill="none" stroke="black" d="M171.225,-36.3034C161.246,-45.0345 148.989,-55.7595 138.143,-65.2497"/>
<polygon fill="black" stroke="black" points="135.769,-62.6766 130.548,-71.8957 140.378,-67.9446 135.769,-62.6766"/>
<g id="edge17" class="edge"><title>MCP3304&#45;&gt;MCP33xx</title>
<path fill="none" stroke="black" d="M801.645,-36.1239C785.955,-45.2764 766.443,-56.6583 749.546,-66.515"/>
<polygon fill="black" stroke="black" points="747.342,-63.7483 740.468,-71.8102 750.87,-69.7947 747.342,-63.7483"/>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -92,7 +92,7 @@ class AnalogInputDevice(SPIDevice):
def value(self):
"""
The current value read from the device, scaled to a value between 0 and
1 (or -1 to +1 for devices operating in differential mode).
1.
"""
return self._read() / (2**self.bits - 1)
@@ -119,8 +119,9 @@ class MCP3xxx(AnalogInputDevice):
def channel(self):
"""
The channel to read data from. The MCP3008/3208/3304 have 8 channels
(0-7), while the MCP3004/3204/3302 have 4 channels (0-3), and the
MCP3301 only has 1 channel.
(0-7), while the MCP3004/3204/3302 have 4 channels (0-3), the
MCP3002/3202 have 2 channels (0-1), and the MCP3001/3201/3301 only
have 1 channel.
"""
return self._channel
@@ -164,6 +165,26 @@ class MCP3xxx(AnalogInputDevice):
return ((data[1] & 63) << (self.bits - 6)) | (data[2] >> (14 - self.bits))
class MCP30xx(MCP3xxx):
"""
Extends :class:`MCP3xxx` to implement an interface for all ADC
chips with a protocol similar to the Microchip MCP30xx series of devices.
"""
def __init__(self, channel=0, differential=False, **spi_args):
super(MCP30xx, self).__init__(channel, 10, differential, **spi_args)
class MCP32xx(MCP3xxx):
"""
Extends :class:`MCP3xxx` to implement an interface for all ADC
chips with a protocol similar to the Microchip MCP32xx series of devices.
"""
def __init__(self, channel=0, differential=False, **spi_args):
super(MCP32xx, self).__init__(channel, 12, differential, **spi_args)
class MCP33xx(MCP3xxx):
"""
Extends :class:`MCP3xxx` with functionality specific to the MCP33xx family
@@ -213,18 +234,40 @@ class MCP33xx(MCP3xxx):
def _send(self):
return [16 + [8, 0][self.differential] + self.channel, 0, 0]
@property
def differential(self):
"""
If ``True``, the device is operated in differential mode. In this mode
one channel (specified by the channel attribute) is read relative to
the value of a second channel (implied by the chip's design).
class MCP3001(MCP3xxx):
Please refer to the device data-sheet to determine which channel is
used as the relative base value (for example, when using an
:class:`MCP3304` in differential mode, channel 0 is read relative to
channel 1).
"""
return super(MCP33xx, self).differential
@property
def value(self):
"""
The current value read from the device, scaled to a value between 0 and
1 (or -1 to +1 for devices operating in differential mode).
"""
return super(MCP33xx, self).value
class MCP3001(MCP30xx):
"""
The `MCP3001`_ is a 10-bit analog to digital converter with 1 channel
.. _MCP3001: http://www.farnell.com/datasheets/630400.pdf
"""
def __init__(self, **spi_args):
super(MCP3001, self).__init__(0, 10, differential=True, **spi_args)
super(MCP3001, self).__init__(0, differential=True, **spi_args)
class MCP3002(MCP3xxx):
class MCP3002(MCP30xx):
"""
The `MCP3002`_ is a 10-bit analog to digital converter with 2 channels
(0-1).
@@ -234,10 +277,10 @@ class MCP3002(MCP3xxx):
def __init__(self, channel=0, differential=False, **spi_args):
if not 0 <= channel < 2:
raise InputDeviceError('channel must be 0 or 1')
super(MCP3002, self).__init__(channel, 10, differential, **spi_args)
super(MCP3002, self).__init__(channel, differential, **spi_args)
class MCP3004(MCP3xxx):
class MCP3004(MCP30xx):
"""
The `MCP3004`_ is a 10-bit analog to digital converter with 4 channels
(0-3).
@@ -247,10 +290,10 @@ class MCP3004(MCP3xxx):
def __init__(self, channel=0, differential=False, **spi_args):
if not 0 <= channel < 4:
raise InputDeviceError('channel must be between 0 and 3')
super(MCP3004, self).__init__(channel, 10, differential, **spi_args)
super(MCP3004, self).__init__(channel, differential, **spi_args)
class MCP3008(MCP3xxx):
class MCP3008(MCP30xx):
"""
The `MCP3008`_ is a 10-bit analog to digital converter with 8 channels
(0-7).
@@ -260,20 +303,20 @@ class MCP3008(MCP3xxx):
def __init__(self, channel=0, differential=False, **spi_args):
if not 0 <= channel < 8:
raise InputDeviceError('channel must be between 0 and 7')
super(MCP3008, self).__init__(channel, 10, differential, **spi_args)
super(MCP3008, self).__init__(channel, differential, **spi_args)
class MCP3201(MCP3xxx):
class MCP3201(MCP32xx):
"""
The `MCP3201`_ is a 12-bit analog to digital converter with 1 channel
.. _MCP3201: http://www.farnell.com/datasheets/1669366.pdf
"""
def __init__(self, **spi_args):
super(MCP3201, self).__init__(0, 12, differential=True, **spi_args)
super(MCP3201, self).__init__(0, differential=True, **spi_args)
class MCP3202(MCP3xxx):
class MCP3202(MCP32xx):
"""
The `MCP3202`_ is a 12-bit analog to digital converter with 2 channels
(0-1).
@@ -283,10 +326,10 @@ class MCP3202(MCP3xxx):
def __init__(self, channel=0, differential=False, **spi_args):
if not 0 <= channel < 2:
raise InputDeviceError('channel must be 0 or 1')
super(MCP3202, self).__init__(channel, 12, differential, **spi_args)
super(MCP3202, self).__init__(channel, differential, **spi_args)
class MCP3204(MCP3xxx):
class MCP3204(MCP32xx):
"""
The `MCP3204`_ is a 12-bit analog to digital converter with 4 channels
(0-3).
@@ -296,10 +339,10 @@ class MCP3204(MCP3xxx):
def __init__(self, channel=0, differential=False, **spi_args):
if not 0 <= channel < 4:
raise InputDeviceError('channel must be between 0 and 3')
super(MCP3204, self).__init__(channel, 12, differential, **spi_args)
super(MCP3204, self).__init__(channel, differential, **spi_args)
class MCP3208(MCP3xxx):
class MCP3208(MCP32xx):
"""
The `MCP3208`_ is a 12-bit analog to digital converter with 8 channels
(0-7).
@@ -309,7 +352,7 @@ class MCP3208(MCP3xxx):
def __init__(self, channel=0, differential=False, **spi_args):
if not 0 <= channel < 8:
raise InputDeviceError('channel must be between 0 and 7')
super(MCP3208, self).__init__(channel, 12, differential, **spi_args)
super(MCP3208, self).__init__(channel, differential, **spi_args)
class MCP3301(MCP33xx):