Skip to content

Commit 1f269e2

Browse files
committed
πŸ“Œ Nodepp | Stable Release | V1.3.0 πŸ“Œ
1 parent 6759b62 commit 1f269e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+3203
-1135
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 78 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ One of the standout features of Nodepp is its 100% asynchronous architecture, po
2121
- πŸ“Œ: Include support for **Reactive Programming** based on **Events** and **Observers**.
2222
- πŸ“Œ: Include an **Event Loop** that can handle multiple events and tasks on a single thread.
2323

24-
## Hello world
24+
## Examples
25+
26+
### Hello world
2527
```cpp
2628
#include <nodepp.h>
2729

@@ -33,9 +35,36 @@ void onMain() {
3335
}
3436
```
3537

36-
## Events
38+
### Coroutines
39+
```cpp
40+
#include <nodepp.h>
41+
42+
using namespace nodepp;
43+
44+
void onMain() {
45+
46+
ptr_t<uchar> IO ({ 2, 3, 4, 5 });
47+
for( auto x: IO ){ pinMode( x, OUTPUT ); }
48+
49+
process::add( coroutine::add( COROUTINE(){
50+
static uchar pin = 0;
51+
coBegin
52+
53+
while( true ){
54+
digitalWrite( pin, LOW );
55+
pin = ( pin + 1 ) % IO.size();
56+
digitalWrite( pin, HIGH );
57+
coDelay( 300 ); }
58+
59+
coFinish
60+
}));
61+
62+
}
63+
```
64+
65+
### Events
3766
```cpp
38-
#include <nodepp/nodepp.h>
67+
#include <nodepp.h>
3968
#include <nodepp/event.h>
4069

4170
using namespace nodepp;
@@ -54,40 +83,74 @@ void onMain(){
5483
ev.emit();
5584

5685
}
57-
58-
// note that we are using onMain() instead of main()
5986
```
6087

61-
## Timer
88+
### Timer
6289
```cpp
63-
#include <nodepp/nodepp.h>
90+
#include <nodepp.h>
6491
#include <nodepp/timer.h>
6592

6693
using namespace nodepp;
6794

6895
void onMain(){
6996

7097
pinMode( 13, OUTPUT );
71-
72-
timer::interval([=](){
98+
99+
timer::interval([=](){
73100
static bool b=0; b=!b;
74101
digitalWrite( 13, b );
75102
}, 1000 );
76103

77104
}
78105
```
79106

107+
### Promises
108+
```cpp
109+
#include <nodepp.h>
110+
#include <nodepp/promise.h>
111+
112+
using namespace nodepp;
113+
114+
void onMain(){ Serial.begin( 9600 );
115+
116+
promise_t<int,except_t>([=]( res_t<int> res, rej_t<except_t> rej ){
117+
res( 10 );
118+
})
119+
120+
.then([=]( int res ){ console::log( res ); })
121+
122+
.fail([=]( except_t err ){ console::log( err.what() ); })
123+
124+
}
125+
```
126+
127+
### More Examples [here](https://nodeppofficial.github.io/nodepp-doc/guide.html)
128+
129+
## Learn By Projects
130+
### 3 channel Asynchronous Led Chaser
131+
[![IMAGE](https://thumbs.wokwi.com/projects/397439909199432705/thumbnail.jpg?tile&t=1764261498303)](https://wokwi.com/projects/397439909199432705)
132+
133+
### 3 Channel Asynchronous Counter
134+
135+
[![IMAGE](https://thumbs.wokwi.com/projects/448348853985471489/thumbnail.jpg?tile&t=1764010799509)](https://wokwi.com/projects/448348853985471489)
136+
137+
### Dining Philosophers
80138

81-
### More Examples [here](https://github.com/NodeppOfficial/Nodepp/tree/main/examples)
139+
[![IMAGE](https://thumbs.wokwi.com/projects/448442428745256961/thumbnail.jpg?tile&t=1764005366748)](https://wokwi.com/projects/448442428745256961)
82140

83-
## Compatibility
141+
### Asynchronous measurement
142+
143+
[![IMAGE](https://thumbs.wokwi.com/projects/448295308358068225/thumbnail.jpg?tile&t=1763835521676)](https://wokwi.com/projects/448295308358068225)
144+
145+
### Event-Driven Button
146+
147+
[![IMAGE](https://thumbs.wokwi.com/projects/448281938490194945/thumbnail.jpg?tile&t=1764262506939)](https://wokwi.com/projects/448281938490194945)
148+
149+
## Nodepp Supports Other Platforms Too
84150
- πŸ”—: [NodePP for Window | Linux | Mac | Bsd ](https://github.com/NodeppOfficial/nodepp)
85151
- πŸ”—: [NodePP for Arduino](https://github.com/NodeppOfficial/nodepp-arduino)
86152
- πŸ”—: [Nodepp for WASM](https://github.com/NodeppOfficial/nodepp-wasm)
87-
88-
## FAQ
89-
- πŸ”— : [/r/Nodepp/](https://www.reddit.com/r/Nodepp/comments/1eaq1pu/faq_ask_anything_about_nodepp/)
90-
153+
91154
## Contribution
92155

93156
If you want to contribute to **Nodepp**, you are welcome to do so! You can contribute in several ways:

β€Žexamples/0-Test.cppβ€Ž

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#include <nodepp/nodepp.h>
2+
#include <nodepp/test.h>
3+
4+
using namespace nodepp;
5+
6+
namespace TEST { namespace CONSOLE {
7+
8+
void TEST_RUNNER(){
9+
ptr_t<uint> totl = new uint(0);
10+
ptr_t<uint> done = new uint(0);
11+
ptr_t<uint> err = new uint(0);
12+
ptr_t<uint> skp = new uint(0);
13+
14+
auto test = TEST_CREATE();
15+
16+
TEST_ADD( test, "TEST 1 | console log ", [](){
17+
try {
18+
conio::log("-> "); console::log("Hello World!");
19+
TEST_DONE();
20+
} catch ( ... ) {
21+
TEST_FAIL();
22+
}
23+
});
24+
25+
TEST_ADD( test, "TEST 2 | console info ", [](){
26+
try {
27+
conio::log("-> "); console::info("Hello World!");
28+
TEST_DONE();
29+
} catch ( ... ) {
30+
TEST_FAIL();
31+
}
32+
});
33+
34+
TEST_ADD( test, "TEST 3 | console done ", [](){
35+
try {
36+
conio::log("-> "); console::done("Hello World!");
37+
TEST_DONE();
38+
} catch ( ... ) {
39+
TEST_FAIL();
40+
}
41+
});
42+
43+
TEST_ADD( test, "TEST 4 | console error ", [](){
44+
try {
45+
conio::log("-> "); console::error("Hello World!");
46+
TEST_DONE();
47+
} catch ( ... ) {
48+
TEST_FAIL();
49+
}
50+
});
51+
52+
TEST_ADD( test, "TEST 5 | console success ", [](){
53+
try {
54+
conio::log("-> "); console::success("Hello World!");
55+
TEST_DONE();
56+
} catch ( ... ) {
57+
TEST_FAIL();
58+
}
59+
});
60+
61+
TEST_ADD( test, "TEST 6 | console warning ", [](){
62+
try {
63+
conio::log("-> "); console::warning("Hello World!");
64+
TEST_DONE();
65+
} catch ( ... ) {
66+
TEST_FAIL();
67+
}
68+
});
69+
70+
test.onClose.once([=](){
71+
console::log(":> RESULT | total:", *totl, "| passed:", *done, "| error:", *err, "| skipped:", *skp );
72+
});
73+
74+
test.onDone([=](){ (*done)++; (*totl)++; });
75+
test.onFail([=](){ (*err)++; (*totl)++; });
76+
test.onSkip([=](){ (*skp)++; (*totl)++; });
77+
78+
TEST_AWAIT( test );
79+
80+
}
81+
82+
}}
83+
84+
void onMain(){
85+
console::enable( 9600 );
86+
TEST::CONSOLE::TEST_RUNNER();
87+
}

β€Žexamples/1-Hello-World.cppβ€Ž

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <nodepp.h>
2+
3+
using namespace nodepp;
4+
5+
void onMain(){
6+
7+
console::enable( 9600 );
8+
console::log("Β‘Hello World!");
9+
10+
}

β€Žexamples/10-Optional.cppβ€Ž

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <nodepp.h>
2+
#include <nodepp/optional.h>
3+
4+
using namespace nodepp;
5+
6+
void onMain(){
7+
8+
console::enable( 9600 );
9+
10+
optional_t<string_t> x;
11+
if( x.has_value() ) console::done( x.value() );
12+
else console::error( "x is empty" );
13+
14+
optional_t<string_t> y ("y has value");
15+
if( y.has_value() ) console::done( y.value() );
16+
else console::error( "y is empty" );
17+
18+
}

β€Žexamples/10-Regex.cppβ€Ž

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <nodepp.h>
2+
#include <nodepp/regex.h>
3+
4+
using namespace nodepp;
5+
6+
void onMain(){
7+
8+
console::enable( 9600 );
9+
10+
string_t message = R"(
11+
![Imagen1](URL1)
12+
![Imagen2](URL2)
13+
![Imagen3](URL3)
14+
![Imagen4](URL5)
15+
)";
16+
17+
regex_t reg ("!\\[([^\\]]+)\\]\\(([^\\)]+)\\)");
18+
19+
console::log( "-- --" );
20+
for( auto &x: reg.match_all( message ) ){
21+
console::log( "->", x );
22+
}
23+
24+
console::log( "-- --" );
25+
for( auto &x: reg.get_memory() ){
26+
console::log( "->", x );
27+
}
28+
29+
}

β€Žexamples/11-Expected.cppβ€Ž

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <nodepp.h>
2+
#include <nodepp/expected.h>
3+
4+
using namespace nodepp;
5+
6+
void onMain(){
7+
8+
console::enable( 9600 );
9+
10+
expected_t<int,string_t> x ( 10 );
11+
if( x.has_value() ) console::done( x.value() );
12+
else console::error( x.error() );
13+
14+
expected_t<int,string_t> y ( "hello" );
15+
if( y.has_value() ) console::done( y.value() );
16+
else console::error( y.error() );
17+
18+
}

β€Žexamples/11-Task.cppβ€Ž

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <nodepp.h>
2+
3+
/*────────────────────────────────────────────────────────────────────────────*/
4+
5+
using namespace nodepp;
6+
7+
/*────────────────────────────────────────────────────────────────────────────*/
8+
9+
void onMain(){
10+
11+
console::enable( 9600 );
12+
13+
//return 1 -> will repeat the task
14+
process::add([=](){
15+
console::done("repeat mode");
16+
return 1;
17+
});
18+
19+
//return -1 -> will kill the task
20+
process::add([=](){
21+
console::error("once mode");
22+
return -1;
23+
});
24+
25+
//return 0 -> will block until != 0
26+
process::add([=](){
27+
console::error("block mode");
28+
return 0;
29+
});
30+
31+
}
32+
33+
/*────────────────────────────────────────────────────────────────────────────*/

β€Žexamples/12-Coroutine.cppβ€Ž

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <nodepp.h>
2+
3+
using namespace nodepp;
4+
5+
void onMain() {
6+
7+
ptr_t<uchar> IO ({ 2, 3, 4, 5 });
8+
for( auto x: IO ){ pinMode( x, OUTPUT ); }
9+
10+
process::add( coroutine::add( COROUTINE(){
11+
static uchar pin = 0;
12+
coBegin
13+
14+
while( true ){
15+
digitalWrite( pin, LOW );
16+
pin = ( pin + 1 ) % IO.size();
17+
digitalWrite( pin, HIGH );
18+
coDelay( 300 ); }
19+
20+
coFinish
21+
}));
22+
23+
}

β€Žexamples/13-Generator.cppβ€Ž

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <nodepp.h>
2+
3+
using namespace nodepp;
4+
5+
GENERATOR( process_1 ) {
6+
7+
int counter = 10;
8+
9+
coEmit(){
10+
coBegin
11+
12+
while( counter-->0 ){
13+
console::done( ":>", counter );
14+
coNext;
15+
}
16+
17+
coFinish
18+
}
19+
20+
};
21+
22+
void onMain(){
23+
console::enable( 9600 );
24+
process_1 A; process::add(A);
25+
}

0 commit comments

Comments
Β (0)