<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: passing a class method pointer as a function pointer</title>
		<link>http://forums.leaflabs.com/topic.php?id=11679</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:14:04 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=11679" rel="self" type="application/rss+xml" />

		<item>
			<title>bubulindo on "passing a class method pointer as a function pointer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=11679#post-26047</link>
			<pubDate>Thu, 16 May 2013 06:56:46 +0000</pubDate>
			<dc:creator>bubulindo</dc:creator>
			<guid isPermaLink="false">26047@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Yes, that seems to be the solution. &#60;/p&#62;
&#60;p&#62;I'll leave the revolution counting bit out of the library for now. &#60;/p&#62;
&#60;p&#62;I should have a working version in two weeks (after my vacation). :)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mlundinse on "passing a class method pointer as a function pointer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=11679#post-26046</link>
			<pubDate>Thu, 16 May 2013 05:53:59 +0000</pubDate>
			<dc:creator>mlundinse</dc:creator>
			<guid isPermaLink="false">26046@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Use a global that is set somewhere, you can even let the timer handler switch the&#60;br /&#62;
current Encoder to the next object of an array of objects:&#60;/p&#62;
&#60;p&#62;gCurrentEncoder * Encoder;&#60;/p&#62;
&#60;p&#62;And then let your interrupthandler be:&#60;/p&#62;
&#60;p&#62;void my_timer_handler()&#60;br /&#62;
{&#60;br /&#62;
    gCurrentEncoder-&#38;gt;timer_interrupt_handler();&#60;br /&#62;
    /* Determine whitch Encoder object to call next ?? */&#60;br /&#62;
}
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bubulindo on "passing a class method pointer as a function pointer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=11679#post-26045</link>
			<pubDate>Thu, 16 May 2013 05:24:13 +0000</pubDate>
			<dc:creator>bubulindo</dc:creator>
			<guid isPermaLink="false">26045@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Ok... &#60;/p&#62;
&#60;p&#62;Thanks for the help. Guess the revolution counter will have to be done somewhere else then. :(
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mlundinse on "passing a class method pointer as a function pointer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=11679#post-26044</link>
			<pubDate>Thu, 16 May 2013 05:10:51 +0000</pubDate>
			<dc:creator>mlundinse</dc:creator>
			<guid isPermaLink="false">26044@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;if the C function can call to a memeber, the that call is even less possible from inside the timer interrupt handler. There is no current Encoder object &#34;this&#34; in the interrupt handler context, so your approach doesnt work. &#60;/p&#62;
&#60;p&#62;Your mtehod must be called like&#60;/p&#62;
&#60;p&#62;anEncoderObject.timer_interrupt_handler()&#60;/p&#62;
&#60;p&#62;and there is no way to pass the encoder object instance to the timer interrupt handler.&#60;/p&#62;
&#60;p&#62;If you have several encoder objects, how should the handler know which to select ?&#60;br /&#62;
If you only got one then use a C adapter class.&#60;/p&#62;
&#60;p&#62;The error message simply says that your class method is not possible to use as a C void func void.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bubulindo on "passing a class method pointer as a function pointer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=11679#post-26043</link>
			<pubDate>Thu, 16 May 2013 03:33:15 +0000</pubDate>
			<dc:creator>bubulindo</dc:creator>
			<guid isPermaLink="false">26043@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@mlundinse&#60;/p&#62;
&#60;p&#62;Not sure that is possible. The C function can't call a method that hasn't been instantiated... Since this is a general library, that may be a problem as I can't instantiate all timers as encoders. &#60;/p&#62;
&#60;p&#62;I think the solution might be a two level approach where the C++ code is just a wrapper of the C functions. :\ I really hate doing it like this as it defeats the purpose. :(&#60;/p&#62;
&#60;p&#62;Edit: &#60;/p&#62;
&#60;p&#62;Thinking a bit more about it and a two level approach isn't efficient as I would increment/decrement one variable in a C file, but I can use 4 (on a Maple) timers as encoders. That would mess the whole thing up, or creating one of each for the possibility of the timers being used as an encoder is not great either. :\ &#60;/p&#62;
&#60;p&#62;Crap. :(
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bubulindo on "passing a class method pointer as a function pointer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=11679#post-26042</link>
			<pubDate>Thu, 16 May 2013 03:26:28 +0000</pubDate>
			<dc:creator>bubulindo</dc:creator>
			<guid isPermaLink="false">26042@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello again, &#60;/p&#62;
&#60;p&#62;my timer interrupt is this: &#60;/p&#62;
&#60;p&#62;void Encoder::timer_interrupt_handler(){&#60;br /&#62;
	if (this-&#38;gt;Direction() == POSITIVE) _revolutions++;&#60;br /&#62;
	if (this-&#38;gt;Direction() == NEGATIVE) _revolutions--;&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;And I try to attach it to the timer as this: &#60;/p&#62;
&#60;p&#62;timer_attach_interrupt(_TIMER, TIMER_UPDATE_INTERRUPT, timer_interrupt_handler);&#60;/p&#62;
&#60;p&#62;I get this error: &#60;/p&#62;
&#60;p&#62;Also note that because of preprocessing, line numbers won't match up exactly.  We're working on a fix.&#60;br /&#62;
/Users/bubulindo/Documents/MapleIDE/libraries/Encoder/encoder.cpp: In constructor 'Encoder::Encoder(timer_dev*, unsigned char, unsigned int, unsigned int)':&#60;br /&#62;
/Users/bubulindo/Documents/MapleIDE/libraries/Encoder/encoder.cpp:104: error: argument of type 'void (Encoder::)()' does not match 'void (*)()'&#60;/p&#62;
&#60;p&#62;Casting gives me a similar error, if I try this: &#60;/p&#62;
&#60;p&#62;timer_attach_interrupt(_TIMER, TIMER_UPDATE_INTERRUPT, (voidFuncPtr)timer_interrupt_handler);&#60;/p&#62;
&#60;p&#62;I get this error: &#60;/p&#62;
&#60;p&#62;Also note that because of preprocessing, line numbers won't match up exactly.  We're working on a fix.&#60;br /&#62;
/Users/bubulindo/Documents/MapleIDE/libraries/Encoder/encoder.cpp: In constructor 'Encoder::Encoder(timer_dev*, unsigned char, unsigned int, unsigned int)':&#60;br /&#62;
/Users/bubulindo/Documents/MapleIDE/libraries/Encoder/encoder.cpp:104: error: invalid use of member (did you forget the '&#38;amp;' ?&#60;/p&#62;
&#60;p&#62;Any thoughts?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mlundinse on "passing a class method pointer as a function pointer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=11679#post-26029</link>
			<pubDate>Wed, 15 May 2013 13:28:41 +0000</pubDate>
			<dc:creator>mlundinse</dc:creator>
			<guid isPermaLink="false">26029@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The timer_attach_interupt expects a 'normal C' function pointer to a void function of a void argument. &#60;/p&#62;
&#60;p&#62;Now a C++ class methods is a diferent creature, that sometimes can be called directly and sometimes looked up in Vtables from the class or parent classes.&#60;/p&#62;
&#60;p&#62;Your best bet is to write a small void function of void, C function, and pass this to the timer_attach_interrupt and then call your Encoder class method from inside this function.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "passing a class method pointer as a function pointer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=11679#post-26028</link>
			<pubDate>Wed, 15 May 2013 11:34:14 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">26028@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;bubulindo - Please post the text of the error messages and code for the things you have tried. (Preferably for the minimal case.)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bubulindo on "passing a class method pointer as a function pointer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=11679#post-26026</link>
			<pubDate>Wed, 15 May 2013 10:03:44 +0000</pubDate>
			<dc:creator>bubulindo</dc:creator>
			<guid isPermaLink="false">26026@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello, &#60;/p&#62;
&#60;p&#62;I'm developing a class to use a timer as an encoder and am struggling with the timer interrupt.&#60;br /&#62;
Basically I want the timer interrupt to increment/decrement a variable that will be the number of turns on the encoder.&#60;br /&#62;
So inside the Encoder class I created a private method to do that (since the number of turns variable is private to the class), but when trying to pass a pointer of that method to the timer_attach_interrupt() it gives me an error that I can't seem to cast away (is this a pun?). &#60;/p&#62;
&#60;p&#62;Any ideas on how to solve this?
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
