Bluetooth send float
-
- Posts: 220
- Joined: 23 Jan 2012, 17:07
- Location: Round Rock, TX
Bluetooth send float
I would like to be able to send a float from an NXT up to the PC using Bluetooth. If someone would tell me where to find the implementation of SendResponseNumber is located, I can implement SendResponseFloat and provide the code for others.
Re: Bluetooth send float
Here's the underlying implementation from NXTDefs.h:
You can use something like this:
The existing SendResponseString could also be used like this:
These are completely untested.
John Hansen
Code: Select all
#define __sendResponseNumber(_queue, _val, _result) \
acquire __MWMutex \
add __MWArgs.QueueID, _queue, 10 \
mov __SRNTmpVal, _val \
flatten __MWArgs.Message, __SRNTmpVal \
syscall MessageWrite, __MWArgs \
mov _result, __MWArgs.Result \
release __MWMutex
#define __sendResponseString(_queue, _msg, _result) \
acquire __MWMutex \
add __MWArgs.QueueID, _queue, 10 \
mov __MWArgs.Message, _msg \
syscall MessageWrite, __MWArgs \
mov _result, __MWArgs.Result \
release __MWMutex
Code: Select all
#define SendResponseFloat(_queue, _val) \
asm { \
acquire __MWMutex \
add __MWArgs.QueueID, _queue, 10 \
flatten __MWArgs.Message, _val \
syscall MessageWrite, __MWArgs \
mov __RETVAL__, __MWArgs.Result \
release __MWMutex \
}
Code: Select all
inline char SendResponseFloat(byte queue, float val)
{
string tmp = FlattenVar(val);
return SendResponseString(queue, tmp);
}
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
-
- Posts: 220
- Joined: 23 Jan 2012, 17:07
- Location: Round Rock, TX
Re: Bluetooth send float
After crawling through the code dribbled out to the .sym file, I finally came up with a couple of functions:
These may not be as good as yours (I'm still trying to come to grips with NBC), but they are working for me.
I've been writing code for 50 years; however, I can always find new ways to "bother" a computer and its various languages.
Code: Select all
char SendResponseFloat(byte queue, float val)
{
byte _local_buffer[5];
byte _local_queue = queue + 10;
asm
{
flatten _local_buffer, val
}
_local_buffer[4] = 0;
return(SendMessage (_local_queue, _local_buffer));
}
char ReceiveRemoteFloat(byte queue, bool clear, float & val)
{
byte _local_buffer[5];
bool bErr;
float _local_default = 5;
char cError;
cError = ReceiveMessage (queue, clear, _local_buffer);
asm
{
unflatten val, bErr, _local_buffer, _local_default
}
return(cError);
}
I've been writing code for 50 years; however, I can always find new ways to "bother" a computer and its various languages.
McSummation aka James
http://www.mcsummation.com/Mindstorms/
http://www.mcsummation.com/Mindstorms/
Re: Bluetooth send float
You can see the NBC code generated by the compiler if you are using BricxCC without resorting to the .sym file by simply pressing F12.
John Hansen
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
-
- Posts: 220
- Joined: 23 Jan 2012, 17:07
- Location: Round Rock, TX
Re: Bluetooth send float
Since the .sym file has line numbers in it, I find it easier to dig through.
I just started on BricxCC, NBC, and NXC last week, so I've still got a LOT to learn. Although, all of these bear striking resemblance to tools/assemblers/compilers I've used in the past.
I just started on BricxCC, NBC, and NXC last week, so I've still got a LOT to learn. Although, all of these bear striking resemblance to tools/assemblers/compilers I've used in the past.
McSummation aka James
http://www.mcsummation.com/Mindstorms/
http://www.mcsummation.com/Mindstorms/
-
- Posts: 220
- Joined: 23 Jan 2012, 17:07
- Location: Round Rock, TX
Re: Bluetooth send float
A problem I ran into was that, using opt=2 in the NXC compiler, caused the brick to hang. I had to use opt=1 (or 0) to get the code to run. Is there some glitch with opt=2? Or did I do some foolish thing?
Edit: Should have included that I'm using BricxCC 3.3.8.9, 1.31 (from Lego) FW, and compiler options of: Use Internal Compiler, Enhanced Firmware, not Ignore system include files, NXT 2.0 compatible firmware, Automatic firmware version, and RICScript.
Edit: Should have included that I'm using BricxCC 3.3.8.9, 1.31 (from Lego) FW, and compiler options of: Use Internal Compiler, Enhanced Firmware, not Ignore system include files, NXT 2.0 compatible firmware, Automatic firmware version, and RICScript.
McSummation aka James
http://www.mcsummation.com/Mindstorms/
http://www.mcsummation.com/Mindstorms/
Re: Bluetooth send float
using NXC it's always better to download the latest enhanced firmware, I would suggest to change this at first.
-
- Posts: 220
- Joined: 23 Jan 2012, 17:07
- Location: Round Rock, TX
Re: Bluetooth send float
I downloaded the current "test release" from http://bricxcc.sourceforge.net/test_releases/ and my code works for all opt levels of the NXC compiler.
Thanks for nudging me in the direction of loading a "test release" on my brick + BricxCC.
Thanks for nudging me in the direction of loading a "test release" on my brick + BricxCC.
McSummation aka James
http://www.mcsummation.com/Mindstorms/
http://www.mcsummation.com/Mindstorms/
Re: Bluetooth send float
you're welcom!
:)
I guess "nudging " is something meant to be taken nicely or so although I actually have no idea what that means (even Google translate doesn't) ^^
:)
I guess "nudging " is something meant to be taken nicely or so although I actually have no idea what that means (even Google translate doesn't) ^^
-
- Posts: 220
- Joined: 23 Jan 2012, 17:07
- Location: Round Rock, TX
Re: Bluetooth send float
to nudge: verb
Prod (someone) gently, typically with one's elbow, in order to draw their attention to something.
Yes, it's meant in a friendly way.
Prod (someone) gently, typically with one's elbow, in order to draw their attention to something.
Yes, it's meant in a friendly way.
McSummation aka James
http://www.mcsummation.com/Mindstorms/
http://www.mcsummation.com/Mindstorms/
Who is online
Users browsing this forum: Semrush [Bot] and 3 guests