BBC BASIC
« Battery State »

Welcome Guest. Please Login or Register.
Mar 31st, 2018, 10:58pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Cross-platform BBC BASIC (Windows, Linux x86, Mac OS-X, Android, iOS, Raspberry Pi)
BBC BASIC Resources
BBC BASIC Help Documentation
BBC BASIC for Windows Home Page
BBC BASIC Programmers' Reference
BBC BASIC Beginners' Tutorial
BBC BASIC for SDL 2.0 Home Page
BBC BASIC Discussion Group

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 hotthread  Author  Topic: Battery State  (Read 232 times)
roy
New Member
Image


member is offline

Avatar




PM


Posts: 44
xx Re: Battery State
« Reply #9 on: Mar 18th, 2018, 8:14pm »

Hi All

Here is the app.
There doesn't seem to be a way to include a zip file or a screen shot so posted code

Thanks for help

Regards roy

Code:
   20 on error if err=17 then proc_CleanUp else mode 3 : print report$; " At line " erl : wait 100 : end   30 on close proc_CleanUp   40   50 rem Battery State   60 rem Using BBC Basic for Android   70 rem Virsion 0.01   80 rem March 2018   90 rem Author: Roy Shepherd  100 rem Thanks to Richard and vbi for help  110  120 mode 6  130  140 proc_Init  150 repeat  160   *refresh off  170   cls  180   proc_GetBatteryState  190   proc_DrawBattery  200   *refresh on  210   wait 100  220   mouse mx%, my%, b%  230 until b%  240 proc_CleanUp  250 end  260  270 !------------------------------------------------  280 rem Do once at first run of app  290 !------------------------------------------------  300 defproc_Init  310 rem SDL_POWERSTATE Constants  320 SDL_POWERSTATE_UNKNOWN = 0  330 SDL_POWERSTATE_ON_BATTERY = 1  340 SDL_POWERSTATE_NO_BATTERY = 2  350 SDL_POWERSTATE_CHARGING = 3  360 SDL_POWERSTATE_CHARGED = 4  370 VERSION$ = "0.01 (SDL)"  380 sys "SDL_SetWindowTitle", @hwnd%, "Battey State v"+VERSION$  390 proc_GetScreenWidthHeight(screenW%, screenH%)  400 off : colour 0, 50, 50, 50 : cls  410 endproc  420  430 !------------------------------------------------  440 rem Get batter state and print it  450 !------------------------------------------------  460 defproc_GetBatteryState  470 sys "SDL_GetPowerInfo", ^secs%, ^pct% to status%  480 print tab(13,0)"Battery State"  490 case status% of  500   when SDL_POWERSTATE_UNKNOWN    : print "Battery Status Unknown"  510   when SDL_POWERSTATE_ON_BATTERY : print "Running On Battery"  520   when SDL_POWERSTATE_NO_BATTERY : print "No Battery Present"  530   when SDL_POWERSTATE_CHARGING   : print "Battery is Charging"  540   when SDL_POWERSTATE_CHARGED    : print "Battery is Charged"  550   otherwise print "Battery Status Unrecognised"  560 endcase  570  580 if status% = SDL_POWERSTATE_ON_BATTERY or status% = SDL_POWERSTATE_CHARGING then  590   print "Battery is draining: "  600 endif  610 if secs% = -1 then  620   print "unknown time left"  630 else  640   print "Minutes left: ";secs% div 60  650 endif  660  670 if pct% = -1 then  680   print "unknown percentage left"  690 else  700   print "percent left: "+str$pct%  710 endif  720 endproc  730  740 !------------------------------------------------  750 rem Draw the battery and showing how full it is  760 !------------------------------------------------  770 defproc_DrawBattery  780 gcol 7 : rectangle screenW%, 50, 400, 800  790 gcol 3 : rectangle fill screenW% + 150, 850, 100, 50  800 if pct% < 10 then gcol 1 else gcol 2  810 rectangle fill screenW% + 2, 52, 396, pct% * 8  820 endproc  830  840 !------------------------------------------------  850 rem Get the screen width and height  860 !------------------------------------------------  870 defproc_GetScreenWidthHeight(return sx%, return sy%)  880 vdu 26  890 if pos rem SDL thread sync  900 sx% = @vdu%!208 : sy% = @vdu%!212  910 endproc  920  930 !------------------------------------------------  940 rem Set things back to default and close  950 !------------------------------------------------  960 defproc_CleanUp  970 *refresh on  980 on  990 quit 1000 endproc 1010 1020 


User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
xx Re: Battery State
« Reply #10 on: Mar 18th, 2018, 10:30pm »

on Mar 18th, 2018, 8:14pm, roy wrote:
There doesn't seem to be a way to include a zip file or a screen shot so posted code

Zip file: include a hyperlink in your post (it's the button with a picture of the earth, second from the left in the second row of buttons when posting).

Screen shot: insert an image into your post (it's the button showing a framed picture, fourth from the left in the second row of buttons when posting).

Of course for both you need somewhere with public access to host the files, but these days with free cloud services like Dropbox this isn't the issue it once was.

Richard.
User IP Logged

roy
New Member
Image


member is offline

Avatar




PM


Posts: 44
xx Re: Battery State
« Reply #11 on: Mar 19th, 2018, 07:33am »

Thanks for the info Richard. Dropbox I'll look into that

Regards Roy
User IP Logged

roy
New Member
Image


member is offline

Avatar




PM


Posts: 44
xx Re: Battery State
« Reply #12 on: Mar 19th, 2018, 08:41am »

Hi Richard

I've installed Dropbox and put the BatteryState.bbc and the screen shot in it.
https://www.dropbox.com/s/jetorcxjc9rand2/BatterState.PNG?dl=0" alt="User Image" border="0">

https://www.dropbox.com/s/f0eble3utd71svu/BatterState.bbc?dl=0
" target="_blank">
https://www.dropbox.com/s/f0eble3utd71svu/BatterState.bbc?dl=0


The link under target blank works. I don't why there is two links with the first one not working

I couldn't get the image link to work, and the link look a mess.

Help !!
Regards Roy
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
xx Re: Battery State
« Reply #13 on: Mar 19th, 2018, 1:29pm »

on Mar 19th, 2018, 08:41am, roy wrote:
I couldn't get the image link to work... Help !!

I don't really know, but I wonder if it's because Dropbox public URLs are secure (https://) whereas Conforums' aren't.

Richard.
User IP Logged

roy
New Member
Image


member is offline

Avatar




PM


Posts: 44
xx Re: Battery State
« Reply #14 on: Mar 19th, 2018, 6:22pm »

Thanks Richard

I'll keep trying smiley

Regards Roy

User IP Logged

roy
New Member
Image


member is offline

Avatar




PM


Posts: 44
xx Re: Battery State
« Reply #15 on: Mar 19th, 2018, 6:57pm »

Hi All

Screen Shot of Battery State
https://www.dropbox.com/s/jetorcxjc9rand2/BatterState.PNG?dl=0

BatteryState.bbc
https://www.dropbox.com/s/f0eble3utd71svu/BatterState.bbc?dl=0

I've see links on here where there is a word underlined and when you click on it. It leads of to a web site or something
If you know how to do this then please tell wink

Regards Roy
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
xx Re: Battery State
« Reply #16 on: Mar 19th, 2018, 9:06pm »

on Mar 19th, 2018, 6:57pm, roy wrote:
If you know how to do this then please tell wink

It's the 'Insert hyperlink' option that I mentioned before. The syntax is: [url=target_url]link text[/url] or if you particularly want it underlined: [url=target_url][u]link text[/u][/url]

Richard.
« Last Edit: Mar 19th, 2018, 9:07pm by Richard Russell » User IP Logged

roy
New Member
Image


member is offline

Avatar




PM


Posts: 44
xx Re: Battery State
« Reply #17 on: Mar 19th, 2018, 10:05pm »

Click for BatteryState.bbc file

Thanks Richard. Is there a way to get a picture to show. Not having much luck with [img][/img]. Most likely doing it wrong rolleyes

Roy
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
xx Re: Battery State
« Reply #18 on: Mar 20th, 2018, 09:33am »

on Mar 19th, 2018, 10:05pm, roy wrote:
Most likely doing it wrong

No, as I said I suspect the issue is that Dropbox uses secure addresses (https://). Try it with a regular http:// site instead, if you have one - your ISP may well give you a little web space as part of the package. Or you can try one of the free (supported-by-advertising) image hosting sites, of which there are many.

Richard.
User IP Logged

roy
New Member
Image


member is offline

Avatar




PM


Posts: 44
xx Re: Battery State
« Reply #19 on: Mar 20th, 2018, 2:55pm »


Thanks Richard.

I'll look into that

Regards Roy
User IP Logged

roy
New Member
Image


member is offline

Avatar




PM


Posts: 44
xx Re: Battery State
« Reply #20 on: Mar 20th, 2018, 5:06pm »

Hi Richard

Screen shot of BatteryState.bbc
Tried Tumbir.com and uploaded screen shot but couldn't get it work on hare

Tried ImageShack and the result is belowsmiley
I think with ImageShack it's only free for a month

Thanks for Help

Regards Roy

User Image


User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls