CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Float on USB

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Kova



Joined: 06 May 2007
Posts: 35

View user's profile Send private message

Float on USB
PostPosted: Wed May 23, 2007 1:48 am     Reply with quote

Hi,
sorry for my english Smile
I have this code for send a float value to usb port:
printf(usb_cdc_putc,"%3.1f\n", temperature);

On the terminal I receive this value (for example):
29.1
It's possible to send the float rappresentation with the comma and not with the point? (for example):
29,1

Thanks for the help Wink
Bye
Ttelmah
Guest







PostPosted: Wed May 23, 2007 2:41 am     Reply with quote

Really, you would have to do it yourself.
Use 'sprintf', to send the data to a string, and then use the string functions to look for '.', and change this to the required ',', then print the string to the output.
A 'silly' (but effective) way of doing this without having to fiddle like this, is:
Code:

#define DECIMAL_SEPARATOR (',')

void send_char_filtered(int8 chr) {
   if (chr=='.') chr=DECIMAL_SEPARATOR;
   usb_cdc_putc(chr);
}


Then:
Code:

printf(send_char_filtered,"%3.1f\n", temperature);


The neat thing here, is that if you want to use '.', you only need to have the line:
#define DECIMAL_SEPARATOR ('.')

and the same code will then print using the '.', while with the separator defined as ',', these will be substituted.
The obvious 'limitiation', is that you should only use this output routine for numeric values, otherwise full stops in text, will also be substituted...
I use this approach, in a couple of instruments, where a language selection is made during initialisation, and the numeric outputs all route through a filter like this.
The setup for localisation is now present in the compiler, and with the move towards ANSI compliance, a fully operational 'locale' ability will probably appear, but at present, 'DIY', is the way to go.

Best Wishes
Kova



Joined: 06 May 2007
Posts: 35

View user's profile Send private message

PostPosted: Wed May 23, 2007 8:35 am     Reply with quote

Thanks a lot ;)
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group