Skip to content

Commit 9e1c0a2

Browse files
committed
Improved Arduino Ethernet Connectivity.
Added proper support for control dashboards. Added some syntactic sugar for defining input/output resources.
1 parent a331e9d commit 9e1c0a2

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/ThingerClient.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,30 @@ class ThingerClient : public thinger::thinger {
247247
size_t out_size_;
248248
};
249249

250+
/**
251+
* Some syntactic sugar for defining input/output resources easily
252+
*/
253+
254+
void digital_pin(protoson::pson& in, int pin){
255+
if(in.is_empty()) in = (bool) digitalRead(pin);
256+
else digitalWrite(pin, in ? HIGH : LOW);
257+
}
258+
259+
void inverted_digital_pin(protoson::pson& in, int pin){
260+
if(in.is_empty()) in = !(bool) digitalRead(pin);
261+
else digitalWrite(pin, in ? LOW : HIGH);
262+
}
263+
264+
void analog_pin(protoson::pson& in, int pin){
265+
if(in.is_empty()) in = analogRead(pin);
266+
else analogWrite(pin, in);
267+
}
268+
269+
#define digitalPin(PIN) [](pson& in){ digital_pin(in, PIN);}
270+
#define invertedDigitalPin(PIN) [](pson& in){ inverted_digital_pin(in, PIN);}
271+
#define analogPin(PIN) [](pson& in){ analog_pin(in, PIN);}
272+
#define inputValue(value, callback) [](pson& in){ if(in.is_empty()){ in = value; } else{ value = in; callback; } }
273+
#define outputValue(value) [](pson& out){ out = value; }
274+
#define servo(servo) [](pson& in){ if(in.is_empty()) in = (int)servo.read(); else servo.write((int)in); }
275+
250276
#endif

src/ThingerEthernet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class ThingerEthernet : public ThingerClient {
4040
protected:
4141

4242
virtual bool network_connected(){
43+
Ethernet.maintain();
4344
return connected_;
4445
}
4546

src/thinger/thinger.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ namespace thinger{
249249
response.set_signal_flag(thinger_message::REQUEST_ERROR);
250250
}else{
251251
thing_resource->handle_request(request, response);
252+
// stream enabled over a resource input -> notify the current state
253+
if(thing_resource->stream_enabled() && thing_resource->get_io_type()==thinger_resource::pson_in){
254+
// send normal response
255+
send_message(response);
256+
// stream the event to notify the change
257+
return stream_resource(*thing_resource, thinger_message::STREAM_EVENT);
258+
}
252259
}
253260
}
254261
}

0 commit comments

Comments
 (0)