ws2801-connect
Version:
A javascript class to control a WS2801 led stripe
1,504 lines (419 loc) • 17.7 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: WS2801</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Class: WS2801</h1>
<section>
<header>
<h2>WS2801</h2>
<div class="class-description">Represents your WS2801 led stripe</div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="WS2801"><span class="type-signature"></span>new WS2801<span class="signature">(options)</span><span class="type-signature"></span></h4>
<div class="description">
Creates the representation of the led stripe.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">options for the led stripe representation
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>count</code></td>
<td class="type">
<span class="param-type">Number</span>
</td>
<td class="description last">Number of led lights on the stripe (must be greater 0)</td>
</tr>
<tr>
<td class="name"><code>spiWrite</code></td>
<td class="type">
<span class="param-type"><a href="WS2801.html#~spiWrite">WS2801~spiWrite</a></span>
</td>
<td class="description last">Callback for writing to the SPI</td>
</tr>
<tr>
<td class="name"><code>rgbIndex</code></td>
<td class="type">
<span class="param-type">Array</span>
</td>
<td class="description last">[0] = index of red, [1] = index of green, [2] = index of blue;
in the resulting data array for WS2801; default: [0] = 0, [1] = 1, [2] = 2; red first, green second, blue third</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ws2801.js.html">ws2801.js</a>, <a href="ws2801.js.html#line12">line 12</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id="count"><span class="type-signature"></span>count<span class="type-signature"></span></h4>
<div class="description">
Returns the number of supported led lights.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ws2801.js.html">ws2801.js</a>, <a href="ws2801.js.html#line65">line 65</a>
</li></ul></dd>
</dl>
<h4 class="name" id="count"><span class="type-signature"></span>count<span class="type-signature"></span></h4>
<div class="description">
Sets the number of supported led lights.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ws2801.js.html">ws2801.js</a>, <a href="ws2801.js.html#line55">line 55</a>
</li></ul></dd>
</dl>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="clear"><span class="type-signature"></span>clear<span class="signature">()</span><span class="type-signature"> → {<a href="WS2801.html">WS2801</a>}</span></h4>
<div class="description">
Sets all supported led lights to black.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ws2801.js.html">ws2801.js</a>, <a href="ws2801.js.html#line186">line 186</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="WS2801.html">WS2801</a></span>
</dd>
</dl>
<h4 class="name" id="fill"><span class="type-signature"></span>fill<span class="signature">(…color)</span><span class="type-signature"> → {<a href="WS2801.html">WS2801</a>}</span></h4>
<div class="description">
Sets all supported led lights to the given color.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>color</code></td>
<td class="type">
<span class="param-type">String</span>
|
<span class="param-type">Number</span>
|
<span class="param-type">Array</span>
</td>
<td class="attributes">
<repeatable><br>
</td>
<td class="description last">Contains a string like "#fe12a9"
or an array with red, green and blue as elements like [0xfe, 0x12, 0xa9]
or a parameter list of three elments as red, green and blue like (..., 0xfe, 0x12, 0xa9)</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ws2801.js.html">ws2801.js</a>, <a href="ws2801.js.html#line203">line 203</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="WS2801.html">WS2801</a></span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>//Usage
leds.fill("#ff0000") // set all led lights to red
leds.fill(0, 255, 0) // set all led lights to green
leds.fill([0x00, 0x00, 0xff]) // set all led lights to blue</code></pre>
<h4 class="name" id="setAll"><span class="type-signature"></span>setAll<span class="signature">(colors)</span><span class="type-signature"> → {<a href="WS2801.html">WS2801</a>}</span></h4>
<div class="description">
Set possibly all lights with given colors.
If the number of given colors is to low, the rest goes black.
Superfluous are ignored.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>colors</code></td>
<td class="type">
<span class="param-type">Array.<(String|Array)></span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ws2801.js.html">ws2801.js</a>, <a href="ws2801.js.html#line148">line 148</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="WS2801.html">WS2801</a></span>
</dd>
</dl>
<h4 class="name" id="setLight"><span class="type-signature"></span>setLight<span class="signature">(number, …color)</span><span class="type-signature"> → {<a href="WS2801.html">WS2801</a>}</span></h4>
<div class="description">
Sets the color of the led light specified by the given index number.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>number</code></td>
<td class="type">
<span class="param-type">Number</span>
</td>
<td class="attributes">
</td>
<td class="description last">Index of the led light, starting at 0.
Must not exceed number of led lights.</td>
</tr>
<tr>
<td class="name"><code>color</code></td>
<td class="type">
<span class="param-type">String</span>
|
<span class="param-type">Number</span>
|
<span class="param-type">Array</span>
</td>
<td class="attributes">
<repeatable><br>
</td>
<td class="description last">Contains a string like "#fe12a9"
or an array with red, green and blue as elements like [0xfe, 0x12, 0xa9]
or a parameter list of three elments as red, green and blue like (..., 0xfe, 0x12, 0xa9)</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ws2801.js.html">ws2801.js</a>, <a href="ws2801.js.html#line125">line 125</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="WS2801.html">WS2801</a></span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>//Usage
leds.setLight(0, "#ff0000") //set first light to red
leds.setLight(1, 0, 255, 0) //set second light to green
leds.setLight(2, [0x00, 0x00, 0xff]) //set third light to blue</code></pre>
<h4 class="name" id="show"><span class="type-signature"></span>show<span class="signature">()</span><span class="type-signature"> → {<a href="WS2801.html">WS2801</a>}</span></h4>
<div class="description">
Writes the led lights colors to the led stripe using the supplied SPI instance.
You have to call this method everytime you want to see the set colors
on your led stripe.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ws2801.js.html">ws2801.js</a>, <a href="ws2801.js.html#line176">line 176</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="WS2801.html">WS2801</a></span>
</dd>
</dl>
<h4 class="name" id=".rgbFrom"><span class="type-signature">(static) </span>rgbFrom<span class="signature">(color)</span><span class="type-signature"> → {Array}</span></h4>
<div class="description">
Static helper method to determine red, green and blue values.
Either from a string like "#fe12a9"
or from the elements of the array, where the elements are red, green and blue
or from an array as once element, which is identical to the returning one.
Usually this method will be called using a rest parameter.
See setLight() or fill()
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>color</code></td>
<td class="type">
<span class="param-type">Array</span>
</td>
<td class="description last">Having one element with a string or an array
containing red, green and blue as elements or having three elements
representing red, green and blue</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ws2801.js.html">ws2801.js</a>, <a href="ws2801.js.html#line101">line 101</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
Contains red, green and blue as elements
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Array</span>
</dd>
</dl>
<h5>Examples</h5>
<pre class="prettyprint"><code>//with String
let r, g, b
[r, g, b] = ws2801.rgbFrom(["#fe12a9"])
// r = 0xfe, g = 0x12, b = 0xa9</code></pre>
<pre class="prettyprint"><code>//with Elements
let r, g, b
[r, g, b] = ws2801.rgbFrom([0xfe, 0x12, 0xa9])
// r = 0xfe, g = 0x12, b = 0xa9</code></pre>
<pre class="prettyprint"><code>//with Array
let r, g, b
[r, g, b] = ws2801.rgbFrom([[0xfe, 0x12, 0xa9]])
// r = 0xfe, g = 0x12, b = 0xa9</code></pre>
<pre class="prettyprint"><code>//with rest parameter
function rgb(...color) {
return ws2801.rgbFrom(color)
}
rgb("#fe12a9")
rgb(0xfe, 0x12, 0xa9)
rgb([0xfe, 0x12, 0xa9])</code></pre>
<h3 class="subsection-title">Type Definitions</h3>
<h4 class="name" id="~spiWrite"><span class="type-signature"></span>spiWrite<span class="signature">(data)</span><span class="type-signature"></span></h4>
<div class="description">
Callback for writing to the SPI
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type">Array</span>
</td>
<td class="description last">Data (color information) which has to be transfered to the led stripe</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ws2801.js.html">ws2801.js</a>, <a href="ws2801.js.html#line213">line 213</a>
</li></ul></dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WS2801.html">WS2801</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Thu Apr 12 2018 23:52:30 GMT+0200 (Mitteleuropäische Sommerzeit)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>