in almost all methods removed timeouts in milliseconds, replaced to PISystemTime PITimer rewrite, remove internal impl, now only thread implementation, API similar to PIThread PITimer API no longer pass void* PIPeer, PIConnection improved stability on reinit and exit PISystemTime new methods pisd now exit without hanging
129 lines
4.2 KiB
Markdown
129 lines
4.2 KiB
Markdown
\~english \page using_basic Getting started
|
||
\~russian \page using_basic Простые начала
|
||
|
||
\~english
|
||
|
||
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: \n
|
||
|
||
\~russian
|
||
|
||
Многие начинающие программисты решают общие задачи взаимодействия с операционной системой:
|
||
вывод в консоль, определение нажатия клавиш, работа с последовательными портами, сетью или файлами,
|
||
и многое другое. Эти задачи решены в библиотеке, и код, основанный на PIP будет компилироваться
|
||
и работать одинаково на многих системах: Windows, любой Linux, Red Hat, FreeBSD, MacOS X и QNX.
|
||
Типовое приложение на PIP выглядит примерно так: \n
|
||
|
||
\code{.cpp}
|
||
#include <pip.h>
|
||
|
||
|
||
// declare key press handler
|
||
void key_event(char key, void * );
|
||
|
||
|
||
PIConsole console(false, key_event); // don`t start now, key handler is "key_event"
|
||
|
||
|
||
// some vars
|
||
int i = 2, j = 3;
|
||
|
||
|
||
// implicit key press handler
|
||
void key_event(char key, void * ) {
|
||
switch (key) {
|
||
case '-':
|
||
i--;
|
||
break;
|
||
case '+':
|
||
i++;
|
||
break;
|
||
case '(':
|
||
j--;
|
||
break;
|
||
case ')':
|
||
j++;
|
||
break;
|
||
};
|
||
};
|
||
|
||
|
||
class MainClass: public PITimer {
|
||
PIOBJECT(MainClass)
|
||
public:
|
||
MainClass() {}
|
||
protected:
|
||
void tick(int delimiter) {
|
||
piCout << "timer tick";
|
||
// timer tick
|
||
}
|
||
};
|
||
|
||
|
||
MainClass main_class;
|
||
|
||
|
||
int main(int argc, char * argv[]) {
|
||
// enabling auto-detection of exit button press, by default 'Q' (shift+q)
|
||
console.enableExitCapture();
|
||
|
||
// if we want to parse command-line arguments
|
||
PICLI cli(argc, argv);
|
||
cli.addArgument("console"); // "-c" or "--console"
|
||
cli.addArgument("debug"); // "-d" or "--debug"
|
||
|
||
// enabling or disabling global debug flag
|
||
piDebug = cli.hasArgument("debug");
|
||
|
||
// configure console
|
||
console.addTab("first tab", '1');
|
||
console.addString("PIP console", 1, PIConsole::Bold);
|
||
console.addVariable("int var (i)", &i, 1);
|
||
console.addVariable("int green var (j)", &j, 1, PIConsole::Green);
|
||
console.addString("'-' - i--", 2);
|
||
console.addString("'+' - i++", 2);
|
||
console.addString("'(' - j--", 2);
|
||
console.addString("')' - j++", 2);
|
||
console.addTab("second tab", '2');
|
||
console.addString("col 1", 1);
|
||
console.addString("col 2", 2);
|
||
console.addString("col 3", 3);
|
||
console.setTab("first tab");
|
||
|
||
// start output to console if "console" argument exists
|
||
if (cli.hasArgument("console"))
|
||
console.start();
|
||
|
||
// start main class, e.g. 40 Hz
|
||
main_class.start(25.);
|
||
|
||
// wait for 'Q' press, independently if console is started or not
|
||
console.waitForFinish();
|
||
|
||
return 0;
|
||
};
|
||
\endcode
|
||
|
||
\~english
|
||
|
||
This code demonstrates simple interactive configurable program, which can be started with console
|
||
display or not, and with debug or not. \b MainClass is central class that also can be inherited from
|
||
\a PIThread and reimplement \a run() function.
|
||
\n Many PIP classes has events and event handlers, which can be connected one to another.
|
||
Details you can see at \a PIObject reference page (\ref PIObject_sec0).
|
||
\n To configure your program from file use \a PIConfig.
|
||
\n If you want more information see \ref using_advanced
|
||
|
||
\~russian
|
||
|
||
Этот код демонстрирует простую конфигурируемую программу, которая может быть запущена с
|
||
This code demonstrates simple interactive configurable program, which can be started with console
|
||
display or not, and with debug or not. \b MainClass is central class that also can be inherited from
|
||
\a PIThread and reimplement \a run() function.
|
||
\n Many PIP classes has events and event handlers, which can be connected one to another.
|
||
Details you can see at \a PIObject reference page (\ref PIObject_sec0).
|
||
\n To configure your program from file use \a PIConfig.
|