fraser125 / m2tklib

Automatically exported from code.google.com/p/m2tklib
0 stars 0 forks source link

Add U8NUMFN and U32NUMFN #40

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
points to a callback procedure instead of address of variable

uint32_t u32fn(uint8_t msg, uint32_t arg);
uint8_t u8fn(uint8_t msg, uint8_t arg);

msg = M2_NUM_MSG_GET   /* returns value from procedure */
msg = M2_NUM_MSG_SET   /* provides value in "arg" */

Original issue reported on code.google.com by olikr...@gmail.com on 26 Jan 2012 at 11:25

GoogleCodeExporter commented 9 years ago
This is badly needed!

Original comment by sammyl...@gmail.com on 26 Jan 2012 at 2:04

GoogleCodeExporter commented 9 years ago
implementation started:

uint8_t u8_x = 2;

uint8_t u8_cb(m2_el_fnarg_p fnarg, uint8_t msg, uint8_t val)
{
  if ( msg == M2_U8_MSG_SET_VALUE )
    u8_x = val;
  return u8_x;
}

#define M2_U8_MSG_GET_VALUE 0
#define M2_U8_MSG_SET_VALUE 1

M2_U8NUMFN(el,fmt,min,max,fn)

documentation: SET_VALUE is only called, if value has really changed

Original comment by olikr...@gmail.com on 26 Jan 2012 at 10:34

GoogleCodeExporter commented 9 years ago
changed first arg to the element pointer (to be consistent between u8 and u32)
started with u32 (testing needed)

Original comment by olikr...@gmail.com on 27 Jan 2012 at 5:53

GoogleCodeExporter commented 9 years ago
- write u32 test case, check the code 
- rewrite u8 procedure, remove el_data, use runtime object type identification 
as in u32 code

Original comment by olikr...@gmail.com on 27 Jan 2012 at 8:16

GoogleCodeExporter commented 9 years ago
implemented, documentation needs to be done

Original comment by olikr...@gmail.com on 27 Jan 2012 at 9:33

GoogleCodeExporter commented 9 years ago
done

Original comment by olikr...@gmail.com on 28 Jan 2012 at 8:26

GoogleCodeExporter commented 9 years ago
Seem to make problems with classes - get error: "a pointer to a bound function 
my only be used to call the function"

This works:

uint8_t u8_cb(m2_rom_void_p element, uint8_t msg, uint8_t val)
{
  if ( msg == M2_U8_MSG_SET_VALUE )
    global_value = val;
  return global_value;
}
M2_U8NUMFN(el_Frost_aktiv_num,"c2", 1, 20, u8_cb );

This does not work:

class testclass {

public:
    uint8_t u8_cb(m2_rom_void_p element, uint8_t msg, uint8_t val);
};

uint8_t testclass::u8_cb(m2_rom_void_p element, uint8_t msg, uint8_t val)
{
  if ( msg == M2_U8_MSG_SET_VALUE )
    global_value = val;
  return global_value;
}

testclass test;

M2_U8NUMFN(el_Frost_aktiv_num,"c2", 1, 20, test.u8_cb );

Any ideas?

Original comment by sammyl...@gmail.com on 30 Jan 2012 at 2:14

GoogleCodeExporter commented 9 years ago
This is not possible:
http://www.parashift.com/c++-faq-lite/pointers-to-members.html

Original comment by olikr...@gmail.com on 30 Jan 2012 at 3:54

GoogleCodeExporter commented 9 years ago
This will not work. Member functions be not be passed directly (see also the 
C++ FAQ)

Original comment by olikr...@gmail.com on 30 Jan 2012 at 4:02

GoogleCodeExporter commented 9 years ago
OK I got it - Thanks

Original comment by sammyl...@gmail.com on 30 Jan 2012 at 4:18