Skip to content

Commit

Permalink
0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Trusty77 committed Dec 22, 2017
1 parent d5c6ddb commit 7cb6274
Show file tree
Hide file tree
Showing 77 changed files with 454 additions and 216 deletions.
Binary file modified DCCpp.zip
Binary file not shown.
5 changes: 3 additions & 2 deletions VStudio/InoProject.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "Arduino.h"

//#include "..\..\libraries\DCCpp\examples\MiniDcc\MiniDcc.ino"
#include "..\..\libraries\DCCpp\examples\MaxiDcc\MaxiDcc.ino"
#include "..\..\libraries\DCCpp\examples\MiniDcc\MiniDcc.ino"
//#include "..\..\libraries\DCCpp\examples\MaxiDcc\MaxiDcc.ino"
//#include "..\..\libraries\DCCpp\examples\SerialDcc\SerialDcc.ino"
//#include "..\..\libraries\DCCpp\examples\EthernetDcc\EthernetDcc.ino"
//#include "..\..\libraries\DCCpp\examples\Autotest\Autotest.ino"

//#include "TestExe.ino"

Expand Down
116 changes: 116 additions & 0 deletions examples/Autotest/Autotest.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*************************************************************
project: <Dc/Dcc Controller>
author: <Thierry PARIS>
description: <Dcc Automatic Controller sample>
*************************************************************/

/**
* The goal of this sample is to check if the DCC is working.
*
* The main loop function loops through the StateMachineItems linked list and
* send a command for a given delay. When the delay is expired, it pass to the
* next item. If no command is given, the delay is still taken.
* For instance to let the locomotive stop smoothly...
*
* This sample is made for a DCC address 3, a speed of 50 from 128 during rolling,
* and delays according to my test loco. Your machine could have different reactions...
*/

#include "DCCpp.h"
#include "string.h"

#ifndef USE_TEXTCOMMAND
#error To be able to compile this sample,the line #define USE_TEXTCOMMAND must be uncommented in DCCpp.h
#endif

struct StateMachineItem
{
static StateMachineItem *first;

int delay; // delay for 'this' command
char command[20];
char comment[20];
StateMachineItem *next;

static StateMachineItem *GetLastItem()
{
StateMachineItem *curr = first;
while (curr != NULL && curr->next != NULL)
curr = curr->next;

return curr;
}

StateMachineItem(int inDelay, char *inCommand, char *inComment)
{
this->delay = inDelay;
strcpy(this->command, inCommand);
strcpy(this->comment, inComment);
this->next = NULL;
if (first == NULL)
first = this;
else
GetLastItem()->next = this;
}
};

StateMachineItem *StateMachineItem::first = NULL;

StateMachineItem *currentItem = NULL;
unsigned long time = 0;

void setup()
{
Serial.begin(115200);

new StateMachineItem(0, "t 1 3 0 1", "ON"); // On register 1, set direction to forward on cab 3
new StateMachineItem(0, "f 3 144", "Light on"); // Light FL (F0) on
new StateMachineItem(3000, "t 1 3 50 1", "Forward"); // On register 1, go forward at speed 30 on cab 3
new StateMachineItem(1000, "t 1 3 0 1", "Stop"); // Stop cab 3 after 1 second
new StateMachineItem(2000, "", "Wait"); // Wait complete stop
new StateMachineItem(1000, "t 1 3 0 0", "To bwd"); // On register 1, set direction to backward on cab 3
new StateMachineItem(3000, "t 1 3 50 0", "Backward"); // On register 1, go backward at speed 30 on cab 3
new StateMachineItem(1000, "t 1 3 0 0", "Stop"); // Stop cab 3 after 1 second
new StateMachineItem(2000, "", "Wait"); // Wait complete stop
new StateMachineItem(1000, "t 1 3 0 1", "To fwd"); // On register 1, set direction to forward on cab 3
new StateMachineItem(500, "f 3 128", "Light off"); // Light off : blink three times
new StateMachineItem(500, "f 3 144", "Light on"); // Light FL (F0) on
new StateMachineItem(500, "f 3 128", "Light off"); // Light off
new StateMachineItem(500, "f 3 144", "Light on"); // Light on
new StateMachineItem(500, "f 3 128", "Light off"); // Light off
new StateMachineItem(500, "f 3 144", "Light on"); // Light on
new StateMachineItem(500, "f 3 128", "Light off"); // Light off

DCCpp::begin();
// Configuration for my LMD18200. See the page 'Configuration lines' in the documentation for other samples.
DCCpp::beginMain(UNDEFINED_PIN, DCC_SIGNAL_PIN_MAIN, 11, A0);

DCCpp::powerOn();

// Start on first item
// Start timer too.
currentItem = StateMachineItem::first;
time = millis();

TextCommand::parse(currentItem->command);
}


void loop()
{
DCCpp::loop();

if ((int)(millis() - time) >= currentItem->delay)
{
currentItem = currentItem->next;
if (currentItem == NULL)
{
currentItem = StateMachineItem::first;
Serial.println("Restart");
}

time = millis();
TextCommand::parse(currentItem->command);
Serial.println(currentItem->comment);
}
}
2 changes: 1 addition & 1 deletion extras/Doc/Comm_8h_source.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="dir_d41d8cd98f00b204e9800998ecf8427e.html">src</a></li><li class="navelem"><b>Comm.h</b></li>
<li class="footer">Generated on lun. déc. 11 2017 18:07:04 for DCCpp &nbsp; by
<li class="footer">Generated on ven. déc. 22 2017 14:02:05 for DCCpp &nbsp; by
<a href="http://www.copperspice.com/documentation-doxypress.html">
<img class="footer" src="doxypress.png" alt="DoxyPress"/></a> 1.2.10 </li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion extras/Doc/Config_8h_source.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="dir_d41d8cd98f00b204e9800998ecf8427e.html">src</a></li><li class="navelem"><b>Config.h</b></li>
<li class="footer">Generated on lun. déc. 11 2017 18:07:04 for DCCpp &nbsp; by
<li class="footer">Generated on ven. déc. 22 2017 14:02:05 for DCCpp &nbsp; by
<a href="http://www.copperspice.com/documentation-doxypress.html">
<img class="footer" src="doxypress.png" alt="DoxyPress"/></a> 1.2.10 </li>
</ul>
Expand Down
4 changes: 2 additions & 2 deletions extras/Doc/CurrentMonitor_8cpp_source.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,20 @@
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;<span class="comment">/**********************************************************************</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span>&#160;<span class="comment">CurrentMonitor.cpp</span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span>&#160;<span class="comment">COPYRIGHT (c) 2013-2016 Gregg E. Berman</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span>&#160;<span class="comment">Part of DCC++ BASE STATION for the Arduino</span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span>&#160;<span class="comment">**********************************************************************/</span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span>&#160;</div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span>&#160;<span class="preprocessor">#include &quot;DCCpp_Uno.h&quot;</span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span>&#160;<span class="preprocessor">#include &quot;CurrentMonitor.h&quot;</span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span>&#160;<span class="preprocessor">#include &quot;Comm.h&quot;</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span>&#160;</div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span>&#160;</div><div class="line"><a name="l00016"></a><span class="lineno"><a class="line" href="structCurrentMonitor.html#a02f9ea5e724c59e5325100488b068ac9"> 16</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="structCurrentMonitor.html#a02f9ea5e724c59e5325100488b068ac9">CurrentMonitor::begin</a>(<span class="keywordtype">int</span> pin, <span class="keyword">const</span> <span class="keywordtype">char</span> *msg, <span class="keywordtype">float</span> inSampleMax)</div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span>&#160;{</div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span>&#160; this-&gt;pin = <a class="code" href="structCurrentMonitor.html#aeabac9491522ec7f68102bfeab33d5c1">pin</a>;</div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span>&#160; this-&gt;msg = <a class="code" href="structCurrentMonitor.html#a2c3cb87d009c003069b9a90f020f8a9f">msg</a>;</div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span>&#160; this-&gt;<a class="code" href="structCurrentMonitor.html#af9653d31acfffa5a40aa709b2065e00b">current</a> = 0;</div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span>&#160; this-&gt;<a class="code" href="structCurrentMonitor.html#ae04eb956c01d669583be386c2400a6ed">currentSampleMax</a> = inSampleMax;</div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span>&#160;} <span class="comment">// CurrentMonitor::begin</span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span>&#160; </div><div class="line"><a name="l00024"></a><span class="lineno"><a class="line" href="structCurrentMonitor.html#aa1551a05a2069e54f59fd50984884199"> 24</a></span>&#160;<span class="keywordtype">boolean</span> <a class="code" href="structCurrentMonitor.html#aa1551a05a2069e54f59fd50984884199">CurrentMonitor::checkTime</a>()</div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span>&#160;{</div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span>&#160; <span class="keywordflow">if</span>(millis( ) - <a class="code" href="structCurrentMonitor.html#ac4ebbe3141ce8efde47e5b55259a6998">sampleTime</a> &lt; CURRENT_SAMPLE_TIME) <span class="comment">// no need to check current yet</span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span>&#160; <span class="keywordflow">return</span>(<span class="keyword">false</span>);</div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span>&#160; <a class="code" href="structCurrentMonitor.html#ac4ebbe3141ce8efde47e5b55259a6998">sampleTime</a> = millis(); <span class="comment">// note millis() uses TIMER-0. For UNO, we change the scale on Timer-0. For MEGA we do not. This means CURENT_SAMPLE_TIME is different for UNO then MEGA</span></div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span>&#160; <span class="keywordflow">return</span>(<span class="keyword">true</span>); </div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span>&#160;} <span class="comment">// CurrentMonitor::checkTime</span></div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span>&#160; </div><div class="line"><a name="l00032"></a><span class="lineno"><a class="line" href="structCurrentMonitor.html#a83f8adca24e250bfb5c9a90a35503ae9"> 32</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="structCurrentMonitor.html#a83f8adca24e250bfb5c9a90a35503ae9">CurrentMonitor::check</a>()</div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span>&#160;{</div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span>&#160; <span class="keywordflow">if</span> (this-&gt;<a class="code" href="structCurrentMonitor.html#aeabac9491522ec7f68102bfeab33d5c1">pin</a> == UNDEFINED_PIN)</div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span>&#160; <span class="keywordflow">return</span>;</div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span>&#160; this-&gt;<a class="code" href="structCurrentMonitor.html#af9653d31acfffa5a40aa709b2065e00b">current</a> = (float) (analogRead(this-&gt;<a class="code" href="structCurrentMonitor.html#aeabac9491522ec7f68102bfeab33d5c1">pin</a>) * CURRENT_SAMPLE_SMOOTHING + this-&gt;<a class="code" href="structCurrentMonitor.html#af9653d31acfffa5a40aa709b2065e00b">current</a> * (1.0-CURRENT_SAMPLE_SMOOTHING)); <span class="comment">// compute new exponentially-smoothed current</span></div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span>&#160; <span class="keywordtype">int</span> signalPin = DCCppConfig::SignalEnablePinProg;</div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span>&#160; <span class="keywordflow">if</span> (signalPin == UNDEFINED_PIN)</div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span>&#160; signalPin = DCCppConfig::SignalEnablePinMain;</div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span>&#160;</div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span>&#160; <span class="comment">// current overload and Programming Signal is on (or could have checked Main Signal, since both are always on or off together)</span></div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span>&#160; <span class="keywordflow">if</span> (this-&gt;<a class="code" href="structCurrentMonitor.html#af9653d31acfffa5a40aa709b2065e00b">current</a> &gt; this-&gt;<a class="code" href="structCurrentMonitor.html#ae04eb956c01d669583be386c2400a6ed">currentSampleMax</a> &amp;&amp; digitalRead(signalPin) == HIGH)</div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>&#160; {</div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span>&#160; <span class="keywordflow">if</span> (DCCppConfig::SignalEnablePinProg != UNDEFINED_PIN)</div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span>&#160; digitalWrite(DCCppConfig::SignalEnablePinProg, LOW); <span class="comment">// disable both Motor Shield Channels</span></div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span>&#160; <span class="keywordflow">if</span> (DCCppConfig::SignalEnablePinMain != UNDEFINED_PIN)</div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span>&#160; digitalWrite(DCCppConfig::SignalEnablePinMain, LOW); <span class="comment">// regardless of which caused current overload</span></div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>&#160; INTERFACE.print(this-&gt;<a class="code" href="structCurrentMonitor.html#a2c3cb87d009c003069b9a90f020f8a9f">msg</a>); <span class="comment">// print corresponding error message</span></div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>&#160;<span class="preprocessor">#if !defined(USE_ETHERNET)</span></div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>&#160; INTERFACE.println(<span class="stringliteral">&quot;&quot;</span>);</div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>&#160; }</div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span>&#160;} <span class="comment">// CurrentMonitor::check </span></div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>&#160;</div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>&#160;<span class="keywordtype">long</span> <span class="keywordtype">int</span> <a class="code" href="structCurrentMonitor.html#ac4ebbe3141ce8efde47e5b55259a6998">CurrentMonitor::sampleTime</a>=0;</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>&#160;</div><div class="ttc" id="structCurrentMonitor_html_a83f8adca24e250bfb5c9a90a35503ae9"><div class="ttname"><a href="structCurrentMonitor.html#a83f8adca24e250bfb5c9a90a35503ae9">CurrentMonitor::check</a></div><div class="ttdeci">void check()</div><div class="ttdef"><b>Definition:</b> <a href="CurrentMonitor_8cpp_source.html#l00032">CurrentMonitor.cpp:32</a></div></div>
<div class="ttc" id="structCurrentMonitor_html_ac4ebbe3141ce8efde47e5b55259a6998"><div class="ttname"><a href="structCurrentMonitor.html#ac4ebbe3141ce8efde47e5b55259a6998">CurrentMonitor::sampleTime</a></div><div class="ttdeci">static long int sampleTime</div><div class="ttdef"><b>Definition:</b> <a href="CurrentMonitor_8h_source.html#l00028">CurrentMonitor.h:28</a></div></div>
<div class="ttc" id="structCurrentMonitor_html_aa1551a05a2069e54f59fd50984884199"><div class="ttname"><a href="structCurrentMonitor.html#aa1551a05a2069e54f59fd50984884199">CurrentMonitor::checkTime</a></div><div class="ttdeci">static boolean checkTime()</div><div class="ttdef"><b>Definition:</b> <a href="CurrentMonitor_8cpp_source.html#l00024">CurrentMonitor.cpp:24</a></div></div>
<div class="ttc" id="structCurrentMonitor_html_ae04eb956c01d669583be386c2400a6ed"><div class="ttname"><a href="structCurrentMonitor.html#ae04eb956c01d669583be386c2400a6ed">CurrentMonitor::currentSampleMax</a></div><div class="ttdeci">float currentSampleMax</div><div class="ttdef"><b>Definition:</b> <a href="CurrentMonitor_8h_source.html#l00030">CurrentMonitor.h:30</a></div></div>
<div class="ttc" id="structCurrentMonitor_html_af9653d31acfffa5a40aa709b2065e00b"><div class="ttname"><a href="structCurrentMonitor.html#af9653d31acfffa5a40aa709b2065e00b">CurrentMonitor::current</a></div><div class="ttdeci">float current</div><div class="ttdef"><b>Definition:</b> <a href="CurrentMonitor_8h_source.html#l00031">CurrentMonitor.h:31</a></div></div>
<div class="ttc" id="structCurrentMonitor_html_a2c3cb87d009c003069b9a90f020f8a9f"><div class="ttname"><a href="structCurrentMonitor.html#a2c3cb87d009c003069b9a90f020f8a9f">CurrentMonitor::msg</a></div><div class="ttdeci">const char * msg</div><div class="ttdef"><b>Definition:</b> <a href="CurrentMonitor_8h_source.html#l00032">CurrentMonitor.h:32</a></div></div>
<div class="ttc" id="structCurrentMonitor_html_aeabac9491522ec7f68102bfeab33d5c1"><div class="ttname"><a href="structCurrentMonitor.html#aeabac9491522ec7f68102bfeab33d5c1">CurrentMonitor::pin</a></div><div class="ttdeci">int pin</div><div class="ttdef"><b>Definition:</b> <a href="CurrentMonitor_8h_source.html#l00029">CurrentMonitor.h:29</a></div></div>
<div class="ttc" id="structCurrentMonitor_html_ac4ebbe3141ce8efde47e5b55259a6998"><div class="ttname"><a href="structCurrentMonitor.html#ac4ebbe3141ce8efde47e5b55259a6998">CurrentMonitor::sampleTime</a></div><div class="ttdeci">static long int sampleTime</div><div class="ttdef"><b>Definition:</b> <a href="CurrentMonitor_8h_source.html#l00028">CurrentMonitor.h:28</a></div></div>
<div class="ttc" id="structCurrentMonitor_html_a02f9ea5e724c59e5325100488b068ac9"><div class="ttname"><a href="structCurrentMonitor.html#a02f9ea5e724c59e5325100488b068ac9">CurrentMonitor::begin</a></div><div class="ttdeci">void begin(int pin, const char *msg, float inSampleMax = 300)</div><div class="ttdef"><b>Definition:</b> <a href="CurrentMonitor_8cpp_source.html#l00016">CurrentMonitor.cpp:16</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- Generated by DoxyPress 1.2.10 -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="dir_d41d8cd98f00b204e9800998ecf8427e.html">src</a></li><li class="navelem"><b>CurrentMonitor.cpp</b></li>
<li class="footer">Generated on lun. déc. 11 2017 18:07:04 for DCCpp &nbsp; by
<li class="footer">Generated on ven. déc. 22 2017 14:02:05 for DCCpp &nbsp; by
<a href="http://www.copperspice.com/documentation-doxypress.html">
<img class="footer" src="doxypress.png" alt="DoxyPress"/></a> 1.2.10 </li>
</ul>
Expand Down
Loading

0 comments on commit 7cb6274

Please sign in to comment.