Author |
Topic: Battery State (Read 231 times) |
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: Battery State
« Reply #5 on: Mar 18th, 2018, 3:01pm » |
|
on Mar 18th, 2018, 1:18pm, roy wrote:| Some Constants have been set up ie SDL_POWERSTATE_ON_BATTERY = 1. How do you know what value to give them? |
|
In this particular case the constants come from the SDL_PowerState enumeration. Unless otherwise stated, the first item in an enumeration has the value zero and the others correspond to consecutively increasing integers. Note that vbi has an incorrect value for SDL_POWERSTATE_UNKNOWN in his listing, it should be zero, not -1:
Code: REM SDL_PowerState Constants SDL_POWERSTATE_UNKNOWN = 0 Quote:| some apps have popups with a short message. I have searched on how to do this but can fined anything. Any body any ideas. |
|
Message popups are easily created using SDL_ShowSimpleMessageBox:
Code: SDL_MESSAGEBOX_INFORMATION = 2 SYS "SDL_ShowSimpleMessageBox", SDL_MESSAGEBOX_INFORMATION, "My popup", "My message", @hwnd% Richard.
|
|
Logged
|
|
|
|
roy
New Member
member is offline


Posts: 44
|
 |
Re: Battery State
« Reply #6 on: Mar 18th, 2018, 3:24pm » |
|
Thanks for that, Richard
|
|
Logged
|
|
|
|
roy
New Member
member is offline


Posts: 44
|
 |
Re: Battery State
« Reply #7 on: Mar 18th, 2018, 3:35pm » |
|
I was wounding if a popup box could popup without the OK button and show the message for a few second and then disappear.
Regards Roy
|
|
Logged
|
|
|
|
vbi
Guest
|
 |
Re: Battery State
« Reply #8 on: Mar 18th, 2018, 7:00pm » |
|
on Mar 18th, 2018, 3:01pm, Richard Russell wrote:Note that vbi has an incorrect value for SDL_POWERSTATE_UNKNOWN in his listing, it should be zero, not -1 |
|
Whoops, thanks for the correction. That will teach me to pontificate on things that are above my pay grade.
|
|
Logged
|
|
|
|
roy
New Member
member is offline


Posts: 44
|
 |
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
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
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.
|
|
Logged
|
|
|
|
roy
New Member
member is offline


Posts: 44
|
 |
Re: Battery State
« Reply #11 on: Mar 19th, 2018, 07:33am » |
|
Thanks for the info Richard. Dropbox I'll look into that
Regards Roy
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
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.
|
|
Logged
|
|
|
|
roy
New Member
member is offline


Posts: 44
|
 |
Re: Battery State
« Reply #14 on: Mar 19th, 2018, 6:22pm » |
|
Thanks Richard
I'll keep trying
Regards Roy
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
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 |
|
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.
|
|
|
|
roy
New Member
member is offline


Posts: 44
|
 |
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 
Roy
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
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.
|
|
Logged
|
|
|
|
roy
New Member
member is offline


Posts: 44
|
 |
Re: Battery State
« Reply #19 on: Mar 20th, 2018, 2:55pm » |
|
Thanks Richard.
I'll look into that
Regards Roy
|
|
Logged
|
|
|
|
|