sprintf() - General Discussion and Assistance - CHDK Forum

sprintf()

  • 18 Replies
  • 12509 Views
*

Offline m2tk

  • **
  • 50
  • Sheet happens ...
sprintf()
« on: 13 / April / 2008, 15:12:39 »
Advertisements
hi,
how to convince sprintf func to print "3,23 RAD" from long l = 3234?

sprintf(osd_buf, "%ld,%02ld RAD", v/1000, v%1000); prints "3,234 RAD"

can we use floats in sprinf?
thx.
S5IS 1.01bc

*

Offline GrAnd

  • ****
  • 916
  • [A610, S3IS]
    • CHDK
Re: sprintf()
« Reply #1 on: 13 / April / 2008, 16:15:31 »
sprintf(osd_buf, "%ld,%ld RAD", v/1000, v%1000/10);
or
sprintf(osd_buf, "%ld,%ld RAD", v/1000, v/10%100);


can we use floats in sprinf?

Yes, but it is not recommended to use floating point operations, because they are emulated (CPU does not have FP-coprocessor).
« Last Edit: 13 / April / 2008, 16:18:33 by GrAnd »
CHDK Developer.

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: sprintf()
« Reply #2 on: 13 / April / 2008, 17:58:01 »
And since nobody asked: yes, I too think it would be better if the battery voltage reading was 2,43V instead of 2,432 :)

*

Offline m2tk

  • **
  • 50
  • Sheet happens ...
Re: sprintf()
« Reply #3 on: 14 / April / 2008, 07:07:12 »
And since nobody asked: yes, I too think it would be better if the battery voltage reading was 2,43V instead of 2,432 :)

yes, i'm going to leave only 2,34 ;) but that's not only for that
S5IS 1.01bc

Re: sprintf()
« Reply #4 on: 14 / April / 2008, 07:36:52 »
Deleted
« Last Edit: 22 / April / 2008, 17:43:15 by Barney Fife »
[acseven/admin commented out: please refrain from more direct offensive language to any user. FW complaints to me] I felt it imperative to withdraw my TOTAL participation. Nobody has my permission, nor the right, to reinstate MY posts. Make-do with my quoted text in others' replies only. Bye

*

Offline m2tk

  • **
  • 50
  • Sheet happens ...
Re: sprintf()
« Reply #5 on: 14 / April / 2008, 12:54:04 »
as i can see, those measures are not ideal, discharge is not linear and batteries also vary between changings so i don't think you can relay on them. think 2 digit fraction precision is right in place if not too precise...

but don't worry i'm not going to put it into trunk, though it is only changing 3 numbers in source code ;)
i'm thinking about sth else with that sprintf()...
S5IS 1.01bc

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: sprintf()
« Reply #6 on: 14 / April / 2008, 14:31:45 »
I only keep the voltage on display, no icon to waste space. Any percentages the software can calculate can be rude guesses at best and that goes for the icon as well. Battery voltage varies primary with load as much as with capacity. I'm pretty familiar with how batteries behave so for me the voltage is way more clear indicator than an icon or percentage...

That's why I'd like the SI unit "V" letter there, to keep my brain clear that this is the battery voltage and not a part of DoF or anything else. And to put in that extra letter, one digit should be removed to prevent clutter... When a feature really does something for battery load, the voltage sinks significantly at least fast for my camera. The voltage measurement obviously isn't accurate to 4 digits either but that's not an issue here as absolute voltages aren't important, changes are and they are supposedly fairly accurate unless the last digit is all noise.

Moreover, I'd be thrilled if someone found a way to disable Canon's own low battery icon blink. It messes up my precious CHDK displays when it appears and is actually doing this half the time as it seems to be tuned for alkaline batteries instead of the (Eneloop) NiMH cells I use.

But I really don't feel strongly about this, I can perfectly well patch me a build for myself if people think the last digit is important. Maybe it is for cameras with lithium battery packs.


*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: sprintf()
« Reply #7 on: 14 / April / 2008, 14:55:00 »
by the way, can the v value be used for some kind of benchmarks?
my s3is shuts down on about 4230 left. does this value depend on something? is it camera dependent? what values work for your s3is, barney? sorry this partly being offtopic.

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: sprintf()
« Reply #8 on: 14 / April / 2008, 15:04:38 »
by the way, can the v value be used for some kind of benchmarks?
my s3is shuts down on about 4230 left. does this value depend on something? is it camera dependent? what values work for your s3is, barney? sorry this partly being offtopic.

It's definitely camera model dependent since the battery voltages are highly different for different technologies. Mine shuts down at about 2,0 V I suppose, but it's easy to be mistaken and think it's 2,2 V because using playback mode on empty batteries will give me more than a 2,2 V reading and the camera may shut down instantly if I do the battery-hogging switch to rec mode.

*

Offline m2tk

  • **
  • 50
  • Sheet happens ...
Re: sprintf()
« Reply #9 on: 14 / April / 2008, 18:18:38 »
for my s5 it is also sth like 4250mV..

btw sprintf(): i have modified a little file browser with minor changes (filesize in b,kb,mb,gb, selected filesize sum, trunk long paths, 10 rows and some fixes to gui)
if you want to try...

edit: added patch file
« Last Edit: 16 / April / 2008, 03:03:29 by m2tk »
S5IS 1.01bc

 

SimplePortal © 2008-2014, SimplePortal