Skip to content

Commit 9c34a52

Browse files
committed
works on arduino
1 parent 2b79ffc commit 9c34a52

4 files changed

Lines changed: 37 additions & 17 deletions

File tree

examples/data/src/main.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
#ifdef ARDUINO
2-
#include <streamFlow.h>
3-
using namespace StreamFlow;
4-
#define cout Serial
5-
#define endl "\n"
6-
#else
7-
#include <iostream>
8-
using namespace std;
9-
#endif
10-
111
#include <hapi.h>
122
using namespace hapi;
133

@@ -16,7 +6,7 @@ using Year=Parts<StaticInt<1967>,Nil>;
166
const char* label="label:";
177
NilPart<StaticText<label>,ReflexOf,FieldValue<Int>> year{2025};
188

19-
int main() {
9+
void run() {
2010
cout<<Year::get()<<endl;
2111

2212
cout<<year.changed()<<endl;
@@ -26,6 +16,20 @@ int main() {
2616
cout<<year.getValue()<<endl;
2717

2818
cout<<year<<endl;
29-
cout<<CanPrint<Year>::value<<endl;
30-
return 0;
31-
}
19+
}
20+
21+
#ifdef ARDUINO
22+
void setup() {
23+
Serial.begin(115200);
24+
while(!Serial);
25+
}
26+
void loop() {
27+
run();
28+
delay(500);
29+
}
30+
#else
31+
int main() {
32+
run();
33+
return 0;
34+
}
35+
#endif

src/hapi/base.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
#pragma once
22

3+
#ifdef ARDUINO
4+
#include <Arduino.h>
5+
#endif
6+
7+
#ifdef __AVR__
8+
#include <streamFlow.h>
9+
using namespace StreamFlow;
10+
#define cout Serial
11+
#define endl "\n"
12+
#else
13+
#include <iostream>
14+
using std::cout;
15+
using std::endl;
16+
#endif
17+
318
#ifdef __AVR__
419
#include "hapi/platform/avr/avr_std.h"
520
using avr_std::enable_if;
@@ -18,6 +33,7 @@
1833
using std::is_class;
1934
using std::forward;
2035
using std::remove_reference;
36+
using std::operator<<;
2137
#endif
2238

2339
template<bool chk,typename T=void> using When=typename enable_if<chk,T>::type;

src/hapi/canPrint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "hapi/parts.h"
3+
#include "hapi/base.h"
44

55
namespace hapi {
66
template<typename T,bool> struct _CanPrint;

src/hapi/data.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "hapi/base.h"
3+
#include "hapi/canPrint.h"
44

55
namespace hapi {
66
template<typename T,T data>
@@ -9,7 +9,7 @@ namespace hapi {
99
struct Part:O {
1010
template<typename... OO> constexpr Part(OO... oo):O{oo...}{}
1111
static constexpr const T get() {return data;}
12-
template<typename Out> Out& operator<<(Out& out) const {out<<data;O::operator<<(out);return out;}
12+
template<typename Out> Out& operator<<(Out& out) const {::operator<<(out,data);O::operator<<(out);return out;}
1313
};
1414
};
1515

0 commit comments

Comments
 (0)