Files
pip/doc/html/using_basic.html
Пелипенко Иван cc22bf0c67 PIChunkStream
git-svn-id: svn://db.shs.com.ru/pip@176 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
2016-01-31 09:05:23 +00:00

172 lines
11 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.9.1"/>
<title>PIP: Getting started</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
$(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">PIP
&#160;<span id="projectnumber">0.5.0_alpha</span>
</div>
<div id="projectbrief">Platform-Independent Primitives</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.9.1 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('using_basic.html','');});
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<div class="title">Getting started </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Many novice programmers are solved many common task with system integrity: output to console, keyboard buttons press detecting, working with serial ports, ethernet or files, and many other. These tasks can solve this library, and code, based only on PIP will be compile and work similar on many systems: Windows, any Linux, Red Hat, FreeBSD, MacOS X and QNX. Typical application on PIP looks like this: <br />
</p><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;pip.h&gt;</span></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="comment">// declare key press handler</span></div>
<div class="line"><span class="keywordtype">void</span> key_event(<span class="keywordtype">char</span> key, <span class="keywordtype">void</span> * );</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><a class="code" href="class_p_i_console.html">PIConsole</a> console(<span class="keyword">false</span>, key_event); <span class="comment">// don`t start now, key handler is &quot;key_event&quot;</span></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="comment">// some vars</span></div>
<div class="line"><span class="keywordtype">int</span> i = 2, j = 3;</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="comment">// implicit key press handler</span></div>
<div class="line"><span class="keywordtype">void</span> key_event(<span class="keywordtype">char</span> key, <span class="keywordtype">void</span> * ) {</div>
<div class="line"> <span class="keywordflow">switch</span> (key) {</div>
<div class="line"> <span class="keywordflow">case</span> <span class="charliteral">&#39;-&#39;</span>:</div>
<div class="line"> i--;</div>
<div class="line"> <span class="keywordflow">break</span>;</div>
<div class="line"> <span class="keywordflow">case</span> <span class="charliteral">&#39;+&#39;</span>:</div>
<div class="line"> i++;</div>
<div class="line"> <span class="keywordflow">break</span>;</div>
<div class="line"> <span class="keywordflow">case</span> <span class="charliteral">&#39;(&#39;</span>:</div>
<div class="line"> j--;</div>
<div class="line"> <span class="keywordflow">break</span>;</div>
<div class="line"> <span class="keywordflow">case</span> <span class="charliteral">&#39;)&#39;</span>:</div>
<div class="line"> j++;</div>
<div class="line"> <span class="keywordflow">break</span>;</div>
<div class="line"> };</div>
<div class="line">};</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">class </span>MainClass: <span class="keyword">public</span> <a class="code" href="class_p_i_timer.html">PITimer</a> {</div>
<div class="line"> <a class="code" href="class_p_i_object.html#affa62b02040517a34b3f173d804e487f">PIOBJECT</a>(MainClass)</div>
<div class="line">public:</div>
<div class="line"> MainClass() {}</div>
<div class="line"><span class="keyword">protected</span>:</div>
<div class="line"> <span class="keywordtype">void</span> <a class="code" href="class_p_i_timer.html#af94038669f0798c21cc2208da9945406">tick</a>(<span class="keywordtype">void</span> * data, <span class="keywordtype">int</span> delimiter) {</div>
<div class="line"> <a class="code" href="picout_8h.html#ad21862cbba89aead064fbef4c825030e">piCout</a> &lt;&lt; <span class="stringliteral">&quot;timer tick&quot;</span>;</div>
<div class="line"> <span class="comment">// timer tick</span></div>
<div class="line"> }</div>
<div class="line">};</div>
<div class="line"></div>
<div class="line"></div>
<div class="line">MainClass main_class;</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> * argv[]) {</div>
<div class="line"> <span class="comment">// enabling auto-detection of exit button press, by default &#39;Q&#39; (shift+q)</span></div>
<div class="line"> console.enableExitCapture();</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// if we want to parse command-line arguments</span></div>
<div class="line"> <a class="code" href="class_p_i_c_l_i.html">PICLI</a> cli(argc, argv);</div>
<div class="line"> cli.addArgument(<span class="stringliteral">&quot;console&quot;</span>); <span class="comment">// &quot;-c&quot; or &quot;--console&quot;</span></div>
<div class="line"> cli.addArgument(<span class="stringliteral">&quot;debug&quot;</span>); <span class="comment">// &quot;-d&quot; or &quot;--debug&quot;</span></div>
<div class="line"> </div>
<div class="line"> <span class="comment">// enabling or disabling global debug flag</span></div>
<div class="line"> <a class="code" href="pibase_8h.html#a4f24177400b625bdd603032fa6e2e14a">piDebug</a> = cli.hasArgument(<span class="stringliteral">&quot;debug&quot;</span>);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// configure console</span></div>
<div class="line"> console.addTab(<span class="stringliteral">&quot;first tab&quot;</span>, <span class="charliteral">&#39;1&#39;</span>);</div>
<div class="line"> console.addString(<span class="stringliteral">&quot;PIP console&quot;</span>, 1, <a class="code" href="class_p_i_console.html#ad19497b9c33393ffe08856c622e3a579a78328fa8e10b199523d20b782d6fbc5b">PIConsole::Bold</a>);</div>
<div class="line"> console.addVariable(<span class="stringliteral">&quot;int var (i)&quot;</span>, &amp;i, 1);</div>
<div class="line"> console.addVariable(<span class="stringliteral">&quot;int green var (j)&quot;</span>, &amp;j, 1, <a class="code" href="class_p_i_console.html#ad19497b9c33393ffe08856c622e3a579ae959969cfc547e2f48dbe3b51056d931">PIConsole::Green</a>);</div>
<div class="line"> console.addString(<span class="stringliteral">&quot;&#39;-&#39; - i--&quot;</span>, 2);</div>
<div class="line"> console.addString(<span class="stringliteral">&quot;&#39;+&#39; - i++&quot;</span>, 2);</div>
<div class="line"> console.addString(<span class="stringliteral">&quot;&#39;(&#39; - j--&quot;</span>, 2);</div>
<div class="line"> console.addString(<span class="stringliteral">&quot;&#39;)&#39; - j++&quot;</span>, 2);</div>
<div class="line"> console.addTab(<span class="stringliteral">&quot;second tab&quot;</span>, <span class="charliteral">&#39;2&#39;</span>);</div>
<div class="line"> console.addString(<span class="stringliteral">&quot;col 1&quot;</span>, 1);</div>
<div class="line"> console.addString(<span class="stringliteral">&quot;col 2&quot;</span>, 2);</div>
<div class="line"> console.addString(<span class="stringliteral">&quot;col 3&quot;</span>, 3);</div>
<div class="line"> console.setTab(<span class="stringliteral">&quot;first tab&quot;</span>);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// start output to console if &quot;console&quot; argument exists</span></div>
<div class="line"> <span class="keywordflow">if</span> (cli.hasArgument(<span class="stringliteral">&quot;console&quot;</span>))</div>
<div class="line"> console.start();</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// start main class, e.g. 40 Hz</span></div>
<div class="line"> main_class.start(25.);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// wait for &#39;Q&#39; press, independently if console is started or not</span></div>
<div class="line"> console.waitForFinish();</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line">};</div>
</div><!-- fragment --><p> This code demonstrates simple interactive configurable program, which can be started with console display or not, and with debug or not. <b>MainClass</b> is central class that also can be inherited from <em><a class="el" href="class_p_i_thread.html" title="Thread class. ">PIThread</a></em> and reimplement <em>run()</em> function. <br />
Many PIP classes has events and event handlers, which can be connected one to another. Details you can see at <em><a class="el" href="class_p_i_object.html" title="This is base class for any classes which use events -> handlers mechanism. ">PIObject</a></em> reference page (<a class="el" href="class_p_i_object.html#PIObject_sec0">Events and Event handlers</a>). <br />
To configure your program from file use <em><a class="el" href="class_p_i_config.html" title="Configuration file. ">PIConfig</a></em>. <br />
If you want more information see <a class="el" href="using_advanced.html">Advanced using</a> </p>
</div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated on Sat Jan 30 2016 21:43:28 for PIP by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.9.1 </li>
</ul>
</div>
</body>
</html>