User data for mpr_sig_new

11 views
Skip to first unread message

Mathias Bredholt

unread,
Jun 12, 2020, 3:14:52 AM6/12/20
to dot_mapper
Hi all,

I'm using the new API and I'm trying to attach a user data pointer to a newly created signal for usage in the update handler. In the old API we had the user_data argument.
         
mapper_signal mapper_device_add_signal (mapper_device dev,


mapper_direction dir,


int num_instances,


const char * name,


int length,


char type,


const char * unit,


const void * minimum,


const void * maximum,


mapper_signal_update_handler * handler,


const void * user_data

)

In the new API it's not there.
mpr_sig_new(mpr_dev parent, mpr_dir dir, const char *name, int len, mpr_type type, const char *unit, const void *min, const void *max, int *num_inst, mpr_sig_handler *handler, int events)

Global variables are not really an option. Do you have any suggestions?

Cheers,
Mathias

Joseph Malloch

unread,
Jun 12, 2020, 7:48:29 AM6/12/20
to dot_m...@googlegroups.com
Hi Mathias, try this:

void handler(mpr_sig sig, mpr_sig_evt evt, mpr_id inst, int len,
             mpr_type type, const void *val, mpr_time t)
{
    void *data = mpr_obj_get_prop_as_ptr((mpr_obj)sig, MPR_PROP_DATA, 0);
}

int main()
{
    mpr_dev dev = mpr_dev_new("my_device", 0);
    
    float mn = 20.f, mx = 20000.f;
    mpr_sig sig = mpr_sig_new(dev, MPR_DIR_IN, "frequency", 1, MPR_FLT, "Hz",
                              &mn, &mx, NULL, handler, MPR_SIG_UPDATE);
                              
    void *data = ...;
    mpr_obj_set_prop((mpr_obj)sig, MPR_PROP_DATA, NULL, 1, MPR_PTR, &data);
}


--
You received this message because you are subscribed to the Google Groups "dot_mapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dot_mapper+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dot_mapper/674b8028-e6e6-4cfe-90e8-5290dfe6194do%40googlegroups.com.

Mathias Bredholt

unread,
Jun 16, 2020, 6:41:47 PM6/16/20
to dot_mapper
Hi Joe,

Great presentation today and thank you for your help on this. Sorry for the late reply, this got it working, I wasn't using the mpr_obj_set correctly and I didn't know that there was a MPR_PROP_DATA property type. This makes a lot of sense, thank you!

Cheers,
Mathias
Hi Mathias, try this:

To unsubscribe from this group and stop receiving emails from it, send an email to dot_m...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages