3#include <ossia/network/generic/generic_node.hpp>
4#include <ossia/network/generic/generic_parameter.hpp>
5#include <ossia/network/phidgets/phidgets_node.hpp>
9template <
typename Impl>
12 PhidgetHandle m_phidget{};
15 std::mutex m_valueMutex;
17 auto get_phidget()
const
19 return reinterpret_cast<decltype(Impl::phidget)
>(m_phidget);
21 auto get_impl()
const {
return Impl{get_phidget()}; }
24 phidget_generic_parameter(PhidgetHandle p, net::node_base& par)
25 :
ossia::net::parameter_base{par}
28 m_domain = get_impl().get_domain();
31 void on_first_callback_added()
override { get_impl().enable_callbacks(*
this); }
32 void on_removing_last_callback()
override { get_impl().disable_callbacks(); }
34 ~phidget_generic_parameter() { }
36 void pull_value()
override { }
50 net::parameter_base&
push_value()
override {
return *
this; }
52 net::parameter_base& set_value(
const ossia::value& val)
override
57 get_impl().set_value(ossia::convert<
decltype(Impl{get_phidget()}.get_value())>(val));
62 net::parameter_base& set_value(
ossia::value&& v)
override {
return set_value(v); }
64 val_type get_value_type()
const override
66 return ossia::value_trait<
decltype(Impl{get_phidget()}.get_value())>::ossia_enum;
69 net::parameter_base& set_value_type(
val_type)
override {
return *
this; }
71 access_mode get_access()
const override {
return ossia::access_mode::BI; }
72 net::parameter_base& set_access(
access_mode)
override {
return *
this; }
74 const domain& get_domain()
const override {
return m_domain; }
75 net::parameter_base& set_domain(
const domain&)
override {
return *
this; }
77 bounding_mode get_bounding()
const override {
return ossia::bounding_mode::FREE; }
78 net::parameter_base& set_bounding(
bounding_mode)
override {
return *
this; }
81template <
typename Impl>
84 auto get_phidget()
const
86 return reinterpret_cast<decltype(Impl::phidget)
>(m_phidget);
88 auto get_impl()
const {
return Impl{get_phidget()}; }
90 PhidgetHandle m_phidget{};
93 using value_type =
decltype(std::declval<Impl>().get_value());
97 phidget_control_parameter(PhidgetHandle p, net::node_base& par)
98 :
ossia::net::parameter_base{par}
101 m_domain = get_impl().get_domain();
104 ~phidget_control_parameter()
override { }
108 void pull_value()
override { }
125 net::parameter_base& set_value(
const ossia::value& val)
override
130 auto v = ossia::convert<value_type>(val);
132 get_impl().set_value(v);
137 net::parameter_base& set_value(
ossia::value&& v)
override {
return set_value(v); }
139 val_type get_value_type()
const override
141 return ossia::value_trait<
decltype(Impl{get_phidget()}.get_value())>::ossia_enum;
144 net::parameter_base& set_value_type(
val_type)
override {
return *
this; }
146 access_mode get_access()
const override {
return ossia::access_mode::BI; }
147 net::parameter_base& set_access(
access_mode)
override {
return *
this; }
149 const domain& get_domain()
const override {
return m_domain; }
150 net::parameter_base& set_domain(
const domain&)
override {
return *
this; }
152 bounding_mode get_bounding()
const override {
return ossia::bounding_mode::FREE; }
153 net::parameter_base& set_bounding(
bounding_mode)
override {
return *
this; }
158 PhidgetHandle m_phidget{};
162 phidget_open_parameter(PhidgetHandle p, net::node_base& par)
163 :
ossia::net::parameter_base{par}
168 ~phidget_open_parameter()
override { Phidget_close(m_phidget); }
172 void pull_value()
override { }
184 net::parameter_base&
push_value()
override {
return *
this; }
186 net::parameter_base& set_value(
const ossia::value& val)
override
191 auto res = ossia::convert<bool>(val);
196 auto err = Phidget_openWaitForAttachment(m_phidget, 1000);
197 if(err != EPHIDGET_OK)
199 const char* err_txt{};
200 Phidget_getErrorDescription(err, &err_txt);
203 "Phidget Open error: {} ({})", this->get_node().osc_address(), err_txt);
206 "Phidget Open error: {} (timeout)", this->get_node().osc_address());
213 Phidget_close(m_phidget);
221 net::parameter_base& set_value(
ossia::value&& v)
override {
return set_value(v); }
224 net::parameter_base& set_value_type(
val_type)
override {
return *
this; }
226 access_mode get_access()
const override {
return ossia::access_mode::BI; }
227 net::parameter_base& set_access(
access_mode)
override {
return *
this; }
229 const domain& get_domain()
const override
231 static const domain d = ossia::make_domain(
false,
true);
234 net::parameter_base& set_domain(
const domain&)
override {
return *
this; }
237 net::parameter_base& set_bounding(
bounding_mode)
override {
return *
this; }
242 PhidgetHandle m_phidget{};
245 phidget_channel_parameter(PhidgetHandle p, net::node_base& par)
246 :
ossia::net::parameter_base{par}
251 ~phidget_channel_parameter()
override { }
256 Phidget_getChannel(m_phidget, &c);
260 void pull_value()
override { }
264 net::parameter_base&
push_value()
override {
return *
this; }
265 net::parameter_base& set_value(
const ossia::value& val)
override {
return *
this; }
266 net::parameter_base& set_value(
ossia::value&& v)
override {
return *
this; }
269 net::parameter_base& set_value_type(
val_type)
override {
return *
this; }
272 net::parameter_base& set_access(
access_mode)
override {
return *
this; }
274 const domain& get_domain()
const override
276 static const domain d = ossia::make_domain(0, 1024);
279 net::parameter_base& set_domain(
const domain&)
override {
return *
this; }
282 net::parameter_base& set_bounding(
bounding_mode)
override {
return *
this; }
285template <
typename Impl,
typename Parent>
286auto make_parameter(Parent& parent)
288 return std::make_unique<phidget_generic_parameter<Impl>>(parent.phidget(), parent);
291template <
typename Impl>
292struct Control_Double_parameter
294 typename Impl::handle_type phidget;
299 if(Impl::Get(phidget, &val) != EPHIDGET_OK)
304 void set_value(
float v) { Impl::Set(phidget, v); }
309 if(Impl::Min(phidget, &
min) != EPHIDGET_OK)
311 if(Impl::Max(phidget, &
max) != EPHIDGET_OK)
313 return ossia::make_domain(
min,
max);
316 void enable_callbacks(phidget_generic_parameter<Control_Double_parameter>& p) { }
318 void disable_callbacks() { }
321template <
typename Impl>
322struct Control_UInt_parameter
324 typename Impl::handle_type phidget;
329 if(Impl::Get(phidget, &val) != EPHIDGET_OK)
334 void set_value(
int v) { Impl::Set(phidget, v); }
339 if(Impl::Min(phidget, &
min) != EPHIDGET_OK)
341 if(Impl::Max(phidget, &
max) != EPHIDGET_OK)
343 return ossia::make_domain((
int)
min, (
int)
max);
346 void enable_callbacks(phidget_generic_parameter<Control_UInt_parameter>& p) { }
348 void disable_callbacks() { }
351template <
typename Impl>
352struct Double_parameter
354 typename Impl::handle_type phidget;
359 if(Impl::Get(phidget, &val) != EPHIDGET_OK)
364 void set_value(
float) { }
369 if(Impl::Min(phidget, &
min) != EPHIDGET_OK)
371 if(Impl::Max(phidget, &
max) != EPHIDGET_OK)
373 return ossia::make_domain(
min,
max);
376 void enable_callbacks(phidget_generic_parameter<Double_parameter>& p)
380 [](
typename Impl::handle_type ch,
void* ctx,
const double ratio) {
381 auto& p = *
static_cast<phidget_generic_parameter<Double_parameter>*
>(ctx);
387 void disable_callbacks() { Impl::Change(phidget,
nullptr,
nullptr); }
390template <
typename Impl>
393 typename Impl::handle_type phidget;
398 if(Impl::Get(phidget, &val) != EPHIDGET_OK)
403 void set_value(
int) { }
408 if(Impl::Min(phidget, &
min) != EPHIDGET_OK)
410 if(Impl::Max(phidget, &
max) != EPHIDGET_OK)
412 return ossia::make_domain((
int)
min, (
int)
max);
415 void enable_callbacks(phidget_generic_parameter<UInt_parameter>& p)
419 [](
typename Impl::handle_type ch,
void* ctx,
const uint32_t ratio) {
420 auto& p = *
static_cast<phidget_generic_parameter<UInt_parameter>*
>(ctx);
421 p.set_value((
int)ratio);
426 void disable_callbacks() { Impl::Change(phidget,
nullptr,
nullptr); }
429template <
typename Impl>
432 typename Impl::handle_type phidget;
434 ossia::vec3f get_value()
437 if(Impl::Min(phidget, &val) != EPHIDGET_OK)
443 return ossia::make_vec(val[0], val[1], val[2]);
446 void set_value(ossia::vec3f) { }
452 if(Impl::Min(phidget, &
min) != EPHIDGET_OK)
458 if(Impl::Max(phidget, &
max) != EPHIDGET_OK)
464 return ossia::make_domain(
466 ossia::make_vec(
max[0],
max[1],
max[2]));
469 void enable_callbacks(phidget_generic_parameter<Vec3_parameter>& p)
473 [](
typename Impl::handle_type ch,
void* ctx,
const double val[3],
double ts) {
474 auto& p = *
static_cast<phidget_generic_parameter<Vec3_parameter>*
>(ctx);
475 p.set_value(ossia::make_vec(val[0], val[1], val[2]));
480 void disable_callbacks() { Impl::Change(phidget,
nullptr,
nullptr); }
483class phidget_control_node :
public ossia::net::generic_node
486 template <
typename Desc>
487 phidget_control_node(
490 : generic_node{name, dev, parent}
492 m_parameter = std::make_unique<phidget_control_parameter<Desc>>(hdl, *
this);
493 m_device.on_parameter_created(*m_parameter);
497class phidget_open_node :
public ossia::net::generic_node
502 : generic_node{
"open", dev, parent}
504 m_parameter = std::make_unique<phidget_open_parameter>(hdl, *
this);
505 m_device.on_parameter_created(*m_parameter);
509class phidget_channel_node :
public ossia::net::generic_node
512 phidget_channel_node(
514 : generic_node{
"channel", dev, parent}
516 m_parameter = std::make_unique<phidget_channel_parameter>(hdl, *
this);
517 m_device.on_parameter_created(*m_parameter);
521class phidget_voltage_ratio_node :
public ossia::phidget_node
526 using handle_type = PhidgetVoltageRatioInputHandle;
527 inline static const auto Get = PhidgetVoltageRatioInput_getVoltageRatio;
528 inline static const auto Change
529 = PhidgetVoltageRatioInput_setOnVoltageRatioChangeHandler;
530 inline static const auto Min = PhidgetVoltageRatioInput_getMinVoltageRatio;
531 inline static const auto Max = PhidgetVoltageRatioInput_getMaxVoltageRatio;
535 using handle_type = PhidgetVoltageRatioInputHandle;
536 inline static const auto Get = PhidgetVoltageRatioInput_getDataInterval;
537 inline static const auto Set = PhidgetVoltageRatioInput_setDataInterval;
538 inline static const auto Min = PhidgetVoltageRatioInput_getMinDataInterval;
539 inline static const auto Max = PhidgetVoltageRatioInput_getMaxDataInterval;
543 using handle_type = PhidgetVoltageRatioInputHandle;
544 inline static const auto Get = PhidgetVoltageRatioInput_getVoltageRatioChangeTrigger;
545 inline static const auto Set = PhidgetVoltageRatioInput_setVoltageRatioChangeTrigger;
546 inline static const auto Min
547 = PhidgetVoltageRatioInput_getMinVoltageRatioChangeTrigger;
548 inline static const auto Max
549 = PhidgetVoltageRatioInput_getMaxVoltageRatioChangeTrigger;
552 phidget_voltage_ratio_node(
554 : phidget_node{hdl, dev, parent}
560 m_parameter = make_parameter<Double_parameter<param_desc>>(*this);
561 m_device.on_parameter_created(*m_parameter);
563 add_child_simple(std::make_unique<ossia::phidget_open_node>(m_hdl, m_device, *
this));
565 std::make_unique<ossia::phidget_channel_node>(m_hdl, m_device, *
this));
566 add_child_simple(std::make_unique<ossia::phidget_control_node>(
567 Control_UInt_parameter<rate_desc>{},
"rate", m_hdl, m_device, *
this));
568 add_child_simple(std::make_unique<ossia::phidget_control_node>(
569 Control_Double_parameter<trigger_desc>{},
"trigger", m_hdl, m_device, *
this));
570 m_children[0]->get_parameter()->add_callback([=](
const ossia::value& val) {
571 bool b = ossia::convert<bool>(val);
574 m_children[2]->get_parameter()->push_value();
575 m_children[3]->get_parameter()->push_value();
581class phidget_current_input_node :
public ossia::phidget_node
586 using handle_type = PhidgetCurrentInputHandle;
587 inline static const auto Get = PhidgetCurrentInput_getCurrent;
588 inline static const auto Change = PhidgetCurrentInput_setOnCurrentChangeHandler;
589 inline static const auto Min = PhidgetCurrentInput_getMinCurrent;
590 inline static const auto Max = PhidgetCurrentInput_getMaxCurrent;
595 using handle_type = PhidgetCurrentInputHandle;
596 inline static const auto Get = PhidgetCurrentInput_getDataInterval;
597 inline static const auto Set = PhidgetCurrentInput_setDataInterval;
598 inline static const auto Min = PhidgetCurrentInput_getMinDataInterval;
599 inline static const auto Max = PhidgetCurrentInput_getMaxDataInterval;
602 phidget_current_input_node(
604 : phidget_node{hdl, dev, parent}
610 m_parameter = make_parameter<Double_parameter<param_desc>>(*this);
611 m_device.on_parameter_created(*m_parameter);
612 add_child_simple(std::make_unique<ossia::phidget_open_node>(m_hdl, m_device, *
this));
614 std::make_unique<ossia::phidget_channel_node>(m_hdl, m_device, *
this));
615 add_child_simple(std::make_unique<ossia::phidget_control_node>(
616 Control_UInt_parameter<rate_desc>{},
"rate", m_hdl, m_device, *
this));
617 m_children[0]->get_parameter()->add_callback([=](
const ossia::value& val) {
618 bool b = ossia::convert<bool>(val);
621 m_children[2]->get_parameter()->push_value();
627class phidget_voltage_input_node :
public ossia::phidget_node
632 using handle_type = PhidgetVoltageInputHandle;
633 inline static const auto Get = PhidgetVoltageInput_getVoltage;
634 inline static const auto Change = PhidgetVoltageInput_setOnVoltageChangeHandler;
635 inline static const auto Min = PhidgetVoltageInput_getMinVoltage;
636 inline static const auto Max = PhidgetVoltageInput_getMaxVoltage;
641 using handle_type = PhidgetVoltageInputHandle;
642 inline static const auto Get = PhidgetVoltageInput_getDataInterval;
643 inline static const auto Set = PhidgetVoltageInput_setDataInterval;
644 inline static const auto Min = PhidgetVoltageInput_getMinDataInterval;
645 inline static const auto Max = PhidgetVoltageInput_getMaxDataInterval;
649 using handle_type = PhidgetVoltageInputHandle;
650 inline static const auto Get = PhidgetVoltageInput_getVoltageChangeTrigger;
651 inline static const auto Set = PhidgetVoltageInput_setVoltageChangeTrigger;
652 inline static const auto Min = PhidgetVoltageInput_getMinVoltageChangeTrigger;
653 inline static const auto Max = PhidgetVoltageInput_getMaxVoltageChangeTrigger;
656 phidget_voltage_input_node(
658 : phidget_node{hdl, dev, parent}
664 m_parameter = make_parameter<Double_parameter<param_desc>>(*this);
665 m_device.on_parameter_created(*m_parameter);
666 add_child_simple(std::make_unique<ossia::phidget_open_node>(m_hdl, m_device, *
this));
668 std::make_unique<ossia::phidget_channel_node>(m_hdl, m_device, *
this));
669 add_child_simple(std::make_unique<ossia::phidget_control_node>(
670 Control_UInt_parameter<rate_desc>{},
"rate", m_hdl, m_device, *
this));
671 add_child_simple(std::make_unique<ossia::phidget_control_node>(
672 Control_Double_parameter<trigger_desc>{},
"trigger", m_hdl, m_device, *
this));
673 m_children[0]->get_parameter()->add_callback([=](
const ossia::value& val) {
674 bool b = ossia::convert<bool>(val);
677 m_children[2]->get_parameter()->push_value();
678 m_children[3]->get_parameter()->push_value();
684class phidget_capacitive_touch_input_node :
public ossia::phidget_node
689 using handle_type = PhidgetCapacitiveTouchHandle;
690 inline static const auto Get = PhidgetCapacitiveTouch_getTouchValue;
691 inline static const auto Change = PhidgetCapacitiveTouch_setOnTouchHandler;
692 inline static const auto Min = PhidgetCapacitiveTouch_getMinTouchValue;
693 inline static const auto Max = PhidgetCapacitiveTouch_getMaxTouchValue;
698 using handle_type = PhidgetCapacitiveTouchHandle;
699 inline static const auto Get = PhidgetCapacitiveTouch_getDataInterval;
700 inline static const auto Set = PhidgetCapacitiveTouch_setDataInterval;
701 inline static const auto Min = PhidgetCapacitiveTouch_getMinDataInterval;
702 inline static const auto Max = PhidgetCapacitiveTouch_getMaxDataInterval;
705 phidget_capacitive_touch_input_node(
707 : phidget_node{hdl, dev, parent}
713 m_parameter = make_parameter<Double_parameter<param_desc>>(*this);
714 m_device.on_parameter_created(*m_parameter);
715 add_child_simple(std::make_unique<ossia::phidget_open_node>(m_hdl, m_device, *
this));
717 std::make_unique<ossia::phidget_channel_node>(m_hdl, m_device, *
this));
718 add_child_simple(std::make_unique<ossia::phidget_control_node>(
719 Control_UInt_parameter<rate_desc>{},
"rate", m_hdl, m_device, *
this));
720 m_children[0]->get_parameter()->add_callback([=](
const ossia::value& val) {
721 bool b = ossia::convert<bool>(val);
724 m_children[2]->get_parameter()->push_value();
730class phidget_distance_sensor_node :
public ossia::phidget_node
735 using handle_type = PhidgetDistanceSensorHandle;
736 inline static const auto Get = PhidgetDistanceSensor_getDistance;
737 inline static const auto Change = PhidgetDistanceSensor_setOnDistanceChangeHandler;
738 inline static const auto Min = PhidgetDistanceSensor_getMinDistance;
739 inline static const auto Max = PhidgetDistanceSensor_getMaxDistance;
744 using handle_type = PhidgetDistanceSensorHandle;
745 inline static const auto Get = PhidgetDistanceSensor_getDataInterval;
746 inline static const auto Set = PhidgetDistanceSensor_setDataInterval;
747 inline static const auto Min = PhidgetDistanceSensor_getMinDataInterval;
748 inline static const auto Max = PhidgetDistanceSensor_getMaxDataInterval;
751 phidget_distance_sensor_node(
753 : phidget_node{hdl, dev, parent}
759 m_parameter = make_parameter<UInt_parameter<param_desc>>(*this);
760 m_device.on_parameter_created(*m_parameter);
761 add_child_simple(std::make_unique<ossia::phidget_open_node>(m_hdl, m_device, *
this));
763 std::make_unique<ossia::phidget_channel_node>(m_hdl, m_device, *
this));
764 add_child_simple(std::make_unique<ossia::phidget_control_node>(
765 Control_UInt_parameter<rate_desc>{},
"rate", m_hdl, m_device, *
this));
766 m_children[0]->get_parameter()->add_callback([=](
const ossia::value& val) {
767 bool b = ossia::convert<bool>(val);
770 m_children[2]->get_parameter()->push_value();
776class phidget_humidity_sensor_node :
public ossia::phidget_node
781 using handle_type = PhidgetHumiditySensorHandle;
782 inline static const auto Get = PhidgetHumiditySensor_getHumidity;
783 inline static const auto Change = PhidgetHumiditySensor_setOnHumidityChangeHandler;
784 inline static const auto Min = PhidgetHumiditySensor_getMinHumidity;
785 inline static const auto Max = PhidgetHumiditySensor_getMaxHumidity;
790 using handle_type = PhidgetHumiditySensorHandle;
791 inline static const auto Get = PhidgetHumiditySensor_getDataInterval;
792 inline static const auto Set = PhidgetHumiditySensor_setDataInterval;
793 inline static const auto Min = PhidgetHumiditySensor_getMinDataInterval;
794 inline static const auto Max = PhidgetHumiditySensor_getMaxDataInterval;
797 phidget_humidity_sensor_node(
799 : phidget_node{hdl, dev, parent}
805 m_parameter = make_parameter<Double_parameter<param_desc>>(*this);
806 m_device.on_parameter_created(*m_parameter);
807 add_child_simple(std::make_unique<ossia::phidget_open_node>(m_hdl, m_device, *
this));
809 std::make_unique<ossia::phidget_channel_node>(m_hdl, m_device, *
this));
810 add_child_simple(std::make_unique<ossia::phidget_control_node>(
811 Control_UInt_parameter<rate_desc>{},
"rate", m_hdl, m_device, *
this));
812 m_children[0]->get_parameter()->add_callback([=](
const ossia::value& val) {
813 bool b = ossia::convert<bool>(val);
816 m_children[2]->get_parameter()->push_value();
822class phidget_pressure_sensor_node :
public ossia::phidget_node
827 using handle_type = PhidgetPressureSensorHandle;
828 inline static const auto Get = PhidgetPressureSensor_getPressure;
829 inline static const auto Change = PhidgetPressureSensor_setOnPressureChangeHandler;
830 inline static const auto Min = PhidgetPressureSensor_getMinPressure;
831 inline static const auto Max = PhidgetPressureSensor_getMaxPressure;
836 using handle_type = PhidgetPressureSensorHandle;
837 inline static const auto Get = PhidgetPressureSensor_getDataInterval;
838 inline static const auto Set = PhidgetPressureSensor_setDataInterval;
839 inline static const auto Min = PhidgetPressureSensor_getMinDataInterval;
840 inline static const auto Max = PhidgetPressureSensor_getMaxDataInterval;
843 phidget_pressure_sensor_node(
845 : phidget_node{hdl, dev, parent}
851 m_parameter = make_parameter<Double_parameter<param_desc>>(*this);
852 m_device.on_parameter_created(*m_parameter);
853 add_child_simple(std::make_unique<ossia::phidget_open_node>(m_hdl, m_device, *
this));
855 std::make_unique<ossia::phidget_channel_node>(m_hdl, m_device, *
this));
856 add_child_simple(std::make_unique<ossia::phidget_control_node>(
857 Control_UInt_parameter<rate_desc>{},
"rate", m_hdl, m_device, *
this));
858 m_children[0]->get_parameter()->add_callback([=](
const ossia::value& val) {
859 bool b = ossia::convert<bool>(val);
862 m_children[2]->get_parameter()->push_value();
867class phidget_resistance_input_node :
public ossia::phidget_node
872 using handle_type = PhidgetResistanceInputHandle;
873 inline static const auto Get = PhidgetResistanceInput_getResistance;
874 inline static const auto Change
875 = PhidgetResistanceInput_setOnResistanceChangeHandler;
876 inline static const auto Min = PhidgetResistanceInput_getMinResistance;
877 inline static const auto Max = PhidgetResistanceInput_getMaxResistance;
882 using handle_type = PhidgetResistanceInputHandle;
883 inline static const auto Get = PhidgetResistanceInput_getDataInterval;
884 inline static const auto Set = PhidgetResistanceInput_setDataInterval;
885 inline static const auto Min = PhidgetResistanceInput_getMinDataInterval;
886 inline static const auto Max = PhidgetResistanceInput_getMaxDataInterval;
889 phidget_resistance_input_node(
891 : phidget_node{hdl, dev, parent}
897 m_parameter = make_parameter<Double_parameter<param_desc>>(*this);
898 m_device.on_parameter_created(*m_parameter);
899 add_child_simple(std::make_unique<ossia::phidget_open_node>(m_hdl, m_device, *
this));
901 std::make_unique<ossia::phidget_channel_node>(m_hdl, m_device, *
this));
902 add_child_simple(std::make_unique<ossia::phidget_control_node>(
903 Control_UInt_parameter<rate_desc>{},
"rate", m_hdl, m_device, *
this));
904 m_children[0]->get_parameter()->add_callback([=](
const ossia::value& val) {
905 bool b = ossia::convert<bool>(val);
908 m_children[2]->get_parameter()->push_value();
914class phidget_light_sensor_node :
public ossia::phidget_node
919 using handle_type = PhidgetLightSensorHandle;
920 inline static const auto Get = PhidgetLightSensor_getIlluminance;
921 inline static const auto Change = PhidgetLightSensor_setOnIlluminanceChangeHandler;
922 inline static const auto Min = PhidgetLightSensor_getMinIlluminance;
923 inline static const auto Max = PhidgetLightSensor_getMaxIlluminance;
928 using handle_type = PhidgetLightSensorHandle;
929 inline static const auto Get = PhidgetLightSensor_getDataInterval;
930 inline static const auto Set = PhidgetLightSensor_setDataInterval;
931 inline static const auto Min = PhidgetLightSensor_getMinDataInterval;
932 inline static const auto Max = PhidgetLightSensor_getMaxDataInterval;
935 phidget_light_sensor_node(
937 : phidget_node{hdl, dev, parent}
943 m_parameter = make_parameter<Double_parameter<param_desc>>(*this);
944 m_device.on_parameter_created(*m_parameter);
945 add_child_simple(std::make_unique<ossia::phidget_open_node>(m_hdl, m_device, *
this));
947 std::make_unique<ossia::phidget_channel_node>(m_hdl, m_device, *
this));
948 add_child_simple(std::make_unique<ossia::phidget_control_node>(
949 Control_UInt_parameter<rate_desc>{},
"rate", m_hdl, m_device, *
this));
950 m_children[0]->get_parameter()->add_callback([=](
const ossia::value& val) {
951 bool b = ossia::convert<bool>(val);
954 m_children[2]->get_parameter()->push_value();
960class phidget_digital_input_node :
public ossia::phidget_node
965 PhidgetDigitalInputHandle phidget;
970 PhidgetDigitalInput_getState(phidget, &val);
974 void set_value(
bool) { }
978 void enable_callbacks(phidget_generic_parameter<Parameter>& p)
980 PhidgetDigitalInput_setOnStateChangeHandler(
982 [](PhidgetDigitalInputHandle ch,
void* ctx,
const int ratio) {
983 auto& p = *
static_cast<phidget_generic_parameter<Parameter>*
>(ctx);
989 void disable_callbacks()
991 PhidgetDigitalInput_setOnStateChangeHandler(phidget,
nullptr,
nullptr);
995 phidget_digital_input_node(
997 : phidget_node{hdl, dev, parent}
1003 m_parameter = make_parameter<Parameter>(*
this);
1004 m_device.on_parameter_created(*m_parameter);
1005 add_child_simple(std::make_unique<ossia::phidget_open_node>(m_hdl, m_device, *
this));
1007 std::make_unique<ossia::phidget_channel_node>(m_hdl, m_device, *
this));
1011class phidget_digital_output_node :
public ossia::phidget_node
1016 PhidgetDigitalOutputHandle phidget;
1021 PhidgetDigitalOutput_getState(phidget, &val);
1025 void set_value(
bool v) { PhidgetDigitalOutput_setState(phidget, (
int)v); }
1029 void enable_callbacks(phidget_generic_parameter<Parameter>& p) { }
1031 void disable_callbacks() { }
1034 phidget_digital_output_node(
1036 : phidget_node{hdl, dev, parent}
1042 m_parameter = make_parameter<Parameter>(*
this);
1043 m_device.on_parameter_created(*m_parameter);
1044 add_child_simple(std::make_unique<ossia::phidget_open_node>(m_hdl, m_device, *
this));
1046 std::make_unique<ossia::phidget_channel_node>(m_hdl, m_device, *
this));
1050class phidget_magnetometer_node :
public ossia::phidget_node
1055 using handle_type = PhidgetMagnetometerHandle;
1056 inline static const auto Get = PhidgetMagnetometer_getMagneticField;
1057 inline static const auto Change
1058 = PhidgetMagnetometer_setOnMagneticFieldChangeHandler;
1059 inline static const auto Min = PhidgetMagnetometer_getMinMagneticField;
1060 inline static const auto Max = PhidgetMagnetometer_getMaxMagneticField;
1064 using handle_type = PhidgetMagnetometerHandle;
1065 inline static const auto Get = PhidgetMagnetometer_getDataInterval;
1066 inline static const auto Set = PhidgetMagnetometer_setDataInterval;
1067 inline static const auto Min = PhidgetMagnetometer_getMinDataInterval;
1068 inline static const auto Max = PhidgetMagnetometer_getMaxDataInterval;
1071 phidget_magnetometer_node(
1073 : phidget_node{hdl, dev, parent}
1079 m_parameter = make_parameter<Vec3_parameter<param_desc>>(*this);
1080 m_device.on_parameter_created(*m_parameter);
1081 add_child_simple(std::make_unique<ossia::phidget_open_node>(m_hdl, m_device, *
this));
1083 std::make_unique<ossia::phidget_channel_node>(m_hdl, m_device, *
this));
1084 add_child_simple(std::make_unique<ossia::phidget_control_node>(
1085 Control_UInt_parameter<rate_desc>{},
"rate", m_hdl, m_device, *
this));
1086 m_children[0]->get_parameter()->add_callback([=](
const ossia::value& val) {
1087 bool b = ossia::convert<bool>(val);
1090 m_children[2]->get_parameter()->push_value();
1096class phidget_accelerometer_node :
public ossia::phidget_node
1101 using handle_type = PhidgetAccelerometerHandle;
1102 inline static const auto Get = PhidgetAccelerometer_getAcceleration;
1103 inline static const auto Change
1104 = PhidgetAccelerometer_setOnAccelerationChangeHandler;
1105 inline static const auto Min = PhidgetAccelerometer_getMinAcceleration;
1106 inline static const auto Max = PhidgetAccelerometer_getMaxAcceleration;
1111 using handle_type = PhidgetAccelerometerHandle;
1112 inline static const auto Get = PhidgetAccelerometer_getDataInterval;
1113 inline static const auto Set = PhidgetAccelerometer_setDataInterval;
1114 inline static const auto Min = PhidgetAccelerometer_getMinDataInterval;
1115 inline static const auto Max = PhidgetAccelerometer_getMaxDataInterval;
1118 phidget_accelerometer_node(
1120 : phidget_node{hdl, dev, parent}
1126 m_parameter = make_parameter<Vec3_parameter<param_desc>>(*this);
1127 m_device.on_parameter_created(*m_parameter);
1128 add_child_simple(std::make_unique<ossia::phidget_open_node>(m_hdl, m_device, *
this));
1130 std::make_unique<ossia::phidget_channel_node>(m_hdl, m_device, *
this));
1131 add_child_simple(std::make_unique<ossia::phidget_control_node>(
1132 Control_UInt_parameter<rate_desc>{},
"rate", m_hdl, m_device, *
this));
1133 m_children[0]->get_parameter()->add_callback([=](
const ossia::value& val) {
1134 bool b = ossia::convert<bool>(val);
1137 m_children[2]->get_parameter()->push_value();
1143class phidget_gyroscope_node :
public ossia::phidget_node
1148 using handle_type = PhidgetGyroscopeHandle;
1149 inline static const auto Get = PhidgetGyroscope_getAngularRate;
1150 inline static const auto Change = PhidgetGyroscope_setOnAngularRateUpdateHandler;
1151 inline static const auto Min = PhidgetGyroscope_getMinAngularRate;
1152 inline static const auto Max = PhidgetGyroscope_getMaxAngularRate;
1157 using handle_type = PhidgetGyroscopeHandle;
1158 inline static const auto Get = PhidgetGyroscope_getDataInterval;
1159 inline static const auto Set = PhidgetGyroscope_setDataInterval;
1160 inline static const auto Min = PhidgetGyroscope_getMinDataInterval;
1161 inline static const auto Max = PhidgetGyroscope_getMaxDataInterval;
1164 phidget_gyroscope_node(
1166 : phidget_node{hdl, dev, parent}
1172 m_parameter = make_parameter<Vec3_parameter<param_desc>>(*this);
1173 m_device.on_parameter_created(*m_parameter);
1175 add_child_simple(std::make_unique<ossia::phidget_open_node>(m_hdl, m_device, *
this));
1177 std::make_unique<ossia::phidget_channel_node>(m_hdl, m_device, *
this));
1178 add_child_simple(std::make_unique<ossia::phidget_control_node>(
1179 Control_UInt_parameter<rate_desc>{},
"rate", m_hdl, m_device, *
this));
1180 m_children[0]->get_parameter()->add_callback([=](
const ossia::value& val) {
1181 bool b = ossia::convert<bool>(val);
1184 m_children[2]->get_parameter()->push_value();
1190class phidget_hub_node :
public ossia::phidget_node
1195 : phidget_node{hdl, dev, parent}
1201template <
typename T,
typename... Args>
1205 static std::vector<std::future<void>> vec;
1206 auto node =
new T{phid, dev, par_node};
1207 par_node.
add_child(std::unique_ptr<phidget_node>(node));
void send(Args &&... args)
send Trigger all callbacks
Definition callback_container.hpp:190
Root of a device tree.
Definition ossia/network/base/device.hpp:58
The node_base class.
Definition node.hpp:48
node_base * add_child(std::unique_ptr< node_base >)
Adds a new child if it can be added.
Definition node.cpp:140
The parameter_base class.
Definition ossia/network/base/parameter.hpp:48
ossia::value value(ossia::destination_index) const
Returns the sub-value at the index given by destination_index.
Definition ossia/network/base/parameter.cpp:31
The value class.
Definition value.hpp:173
@ Set
Definition ossia-cpp98.hpp:68
@ Get
Definition ossia-cpp98.hpp:67
OSSIA_INLINE constexpr auto min(const T a, const U b) noexcept -> typename std::conditional<(sizeof(T) > sizeof(U)), T, U >::type
min function tailored for values
Definition math.hpp:125
val_type
Enum to represent the types that a value can take.
Definition parameter_properties.hpp:16
bounding_mode
Address behaviors at crossing domain boundaries.
Definition parameter_properties.hpp:56
@ CLIP
The bounds are ignored.
spdlog::logger & logger() noexcept
Where the errors will be logged. Default is stderr.
Definition context.cpp:118
access_mode
Address behaviors at crossing domain boundaries time.
Definition parameter_properties.hpp:46
@ GET
The value can be retrieved and changed.
OSSIA_INLINE constexpr auto max(const T a, const U b) noexcept -> typename std::conditional<(sizeof(T) > sizeof(U)), T, U >::type
max function tailored for values
Definition math.hpp:96
OSSIA_EXPORT void push_value(const ossia::destination &addr, const ossia::value_with_unit &)
Send a value to a given destination.
Definition ossia/network/base/parameter.cpp:151
domain A domain of values
Definition domain_base.hpp:23