]> sigrok.org Git - libsigrok.git/blobdiff - bindings/cxx/classes.cpp
saleae-logic-pro: Detect and abort on capture errors
[libsigrok.git] / bindings / cxx / classes.cpp
index 03a4ce115ca06e4f10567defbf74b48e220fca4e..a0b161a62a35aee683894cfe87b0b8c521d8d42a 100644 (file)
@@ -305,7 +305,7 @@ shared_ptr<Packet> Context::create_logic_packet(
 
 shared_ptr<Packet> Context::create_analog_packet(
        vector<shared_ptr<Channel> > channels,
-       float *data_pointer, unsigned int num_samples, const Quantity *mq,
+       const float *data_pointer, unsigned int num_samples, const Quantity *mq,
        const Unit *unit, vector<const QuantityFlag *> mqflags)
 {
        auto analog = g_new0(struct sr_datafeed_analog, 1);
@@ -343,7 +343,7 @@ shared_ptr<Packet> Context::create_analog_packet(
        spec->spec_digits = 0;
 
        analog->num_samples = num_samples;
-       analog->data = data_pointer;
+       analog->data = (float*)data_pointer;
        auto packet = g_new(struct sr_datafeed_packet, 1);
        packet->type = SR_DF_ANALOG;
        packet->payload = analog;
@@ -1287,6 +1287,48 @@ vector<const QuantityFlag *> Analog::mq_flags() const
        return QuantityFlag::flags_from_mask(_structure->meaning->mqflags);
 }
 
+shared_ptr<Logic> Analog::get_logic_via_threshold(float threshold,
+       uint8_t *data_ptr) const
+{
+       auto datafeed = g_new(struct sr_datafeed_logic, 1);
+       datafeed->length = num_samples();
+       datafeed->unitsize = 1;
+
+       if (data_ptr)
+               datafeed->data = data_ptr;
+       else
+               datafeed->data = g_malloc(datafeed->length);
+
+       shared_ptr<Logic> logic =
+               shared_ptr<Logic>{new Logic{datafeed}, default_delete<Logic>{}};
+
+       check(sr_a2l_threshold(_structure, threshold,
+               (uint8_t*)datafeed->data, datafeed->length));
+
+       return logic;
+}
+
+shared_ptr<Logic> Analog::get_logic_via_schmitt_trigger(float lo_thr,
+       float hi_thr, uint8_t *state, uint8_t *data_ptr) const
+{
+       auto datafeed = g_new(struct sr_datafeed_logic, 1);
+       datafeed->length = num_samples();
+       datafeed->unitsize = 1;
+
+       if (data_ptr)
+               datafeed->data = data_ptr;
+       else
+               datafeed->data = g_malloc(datafeed->length);
+
+       shared_ptr<Logic> logic =
+               shared_ptr<Logic>{new Logic{datafeed}, default_delete<Logic>{}};
+
+       check(sr_a2l_schmitt_trigger(_structure, lo_thr, hi_thr, state,
+               (uint8_t*)datafeed->data, datafeed->length));
+
+       return logic;
+}
+
 Rational::Rational(const struct sr_rational *structure) :
        _structure(structure)
 {