Switch to full style
Would you like to see changes or additions to BASIC! This is place to make those requests.
Post a reply

Re: Hot summer of code

Mon Mar 20, 2017 1:18 pm

Hi Gregor

I tested the APK and it runs well.

Regards Roy
fileSnap.PNG
fileSnap.PNG (25.85 KiB) Viewed 924 times

Re: Hot summer of code

Fri Mar 24, 2017 5:09 am

Hi All,

Some asked me why I use the underscore so often like

"_Source", "_SourceSamples", "_Data"~
, "_Database", "_App", "_AppPath", "_Alarms", "_Dcim", "_Documents"~
, "_Downloads", "_Movies", "_Music", etc.

The Reason is, with the undersore you now at the first look: "This have to do with the BASIC! system :!: "
Behind this are predeffined functions, constants, expressions etc..

Maybe it is also a good suggestion to use the underscore at the end or a better one at the beginning for your predefined elements.

I like this link, too:
https://blog.codinghorror.com/new-programming-jargon/

Happy coding
Gregor

Re: Hot summer of code

Fri Mar 24, 2017 9:04 am

aFox wrote:I like this link, too:
https://blog.codinghorror.com/new-programming-jargon/
Gregor

So do I; thanks for that!

Mike.

Re: Hot summer of code

Mon Mar 27, 2017 12:30 pm

BUG BUG BUG

If you use the command DEBUG.DUMP.BUNDLE my version will crash :!:

I hope, I am able to publish the fix soon.
I have to upgrade three Bundle commands, too.
Now I am testing

/ Gregor

Re: Hot summer of code

Tue Mar 28, 2017 11:14 am

Hi All

I fixed the issue above.

13. FILE.EXISTS accepts string expressions and values. See description.
Now are no changes in older programs and libs needed.
14. BUNDLE.GET and DEBUG.DUMP.BUNDLE convert Java Objects to strings.
If possible!
15. BUNDLE.TYPE modified

The new version link:
https://github.com/RFO-BASIC/Basic/files/876323/OliBasicXVII.zip

Here is an example how to reseive system network broadcast messages
(In this case ACCESS_NETWORK_STATE permission is nedded)
and Bundle enhancements:

Code:
REM Start of BASIC! Program NetworkBroadcasts.bas


FN.DEF bprint(bundle, msg$)
PRINT msg$

BUNDLE.KEYS bundle, list
LIST.SIZE list, size
IF size = 0
  PRINT "Empty bundle"
  PRINT " "
  FN.RTN 0
ENDIF

FOR i = 1 TO size
  LIST.GET list, i, key$
  !  Print key$

  BUNDLE.TYPE bundle, key$, type$
    Print "type$ "; type$

  IF type$ = "N"
   BUNDLE.GET bundle, key$, value
   PRINT key$, value
  ELSE
   BUNDLE.GET bundle, key$, value$
   PRINT key$, value$
  ENDIF

NEXT i

PRINT " "
FN.RTN 1
FN.END
DEBUG.ON
Counter = 0

ARRAY.LOAD actions$[],"android.net.wifi.STATE_CHANGE",~
"android.net.wifi.WIFI_STATE_CHANGED",~
"android.net.conn.CONNECTIVITY_CHANGE",~
"android.net.conn.INET_CONDITION_ACTION"
BROADCAST.INIT actions$[]
DIALOG.MESSAGE "Stop and Restart your WiFi Connection", "GoOn?", selection, "OK"

DO
UNTIL 0

BROADCAST.CLOSE
END

ONBROADCAST:
PRINT "Received Broadcast! .: "
BROADCAST.IN retAction$, retData$, retBundleIndex
PRINT "retAction$ ",retAction$
PRINT "retData$ ",retData$
Counter ++
x = bprint(retBundleIndex, INT$(Counter))
DEBUG.DUMP.BUNDLE retBundleIndex
BROADCAST.RESUME


Example APK:

https://github.com/RFO-BASIC/Basic/files/876467/NetworkBroadcasts.zip

Happy coding
Gregor

Re: Hot summer of code

Tue Mar 28, 2017 12:24 pm

Excellent work Gregor

13. FILE.EXISTS accepts string expressions and values. See description.
Now are no changes in older programs and libs needed.

Alway good to be backward compatible ;)

Demo works well.

Regards Roy

Re: Hot summer of code

Tue May 02, 2017 12:41 pm

Hi all,

Here a workaround for the CONSOLE.TOFRONT issue.

This code based on an idea from Janusz Chmiel.
His idea was to recall the program after some minutes again and again, so it is allways in front.
Yes, Wakelock is also an option :geek:
The second wish was to switch off the audio output if the phone rings until the answered incoming call is finished.
Normally you have to do nothing, but in this case the ringtone is mixed with the audio output.

For audio files you have instead to use Audio.pause.

Code:
FN.DEF ReorderToFront()
PROGRAM.INFO b
BUNDLE.GET b, "PackageName", pN$
LIST.CREATE S, commandListPointer
LIST.ADD commandListPointer~
"new Intent(Intent.ACTION_MAIN);" ~
"setPackage("+ CHR$(34) + pN$ + CHR$(34) +");" ~
"EOCL"
BUNDLE.PL appVarPointer,"_CommandList",commandListPointer
APP.SAR appVarPointer
FN.RTN appVarPointer
FN.END


action1$="android.intent.action.PHONE_STATE"
ARRAY.LOAD actions$[], action1$
BROADCAST.INIT actions$[]

LIST.CREATE s, stationListPointer
LIST.ADD stationListPointer ~
"http://icecast8.play.cz/cro1-128.mp3" ~
"http://icecast6.play.cz/cro2-128.mp3" ~
"http://icecast5.play.cz/cro3-128.mp3"
t = 1

minutes = 10
TIMER.SET 1000*60*minutes

WIFILOCK 3
PHONE.RCV.INIT
PHONE.RCV.NEXT e,r$
phone_state = e
? "ČRo Radiožurnál"
? "ČRo Dvojka"
? "ČRo Vltava"

DO
UNTIL 0

ONCONSOLETOUCH:
CONSOLE.LINE.TOUCHED t
LIST.GET stationListPointer, t, a$
POPUP "LOADING"
AUDIO.STOP: AUDIO.LOAD n,a$: AUDIO.PLAY n
CONSOLETOUCH.RESUME

ONLOWMEMORY:
LOWMEMORY.RESUME

ONTIMER:
myVarPointer = ReorderToFront()
t = TIME() % Get the time in millisconds from 1970-01-01
TIME t, Year$, Month$, Day$, Hour$, Minute$, Second$, WeekDay, isDST
z$ = Hour$ + ":" + Minute$ + ":" + Second$
POPUP z$
TIMER.RESUME

ONBROADCAST:
BROADCAST.IN retAction$, retData$, retBundleIndex

IF retAction$ = action1$
PHONE.RCV.NEXT e,r$
phone_state = e
POPUP "PhoneState has changed \nto: " + INT$(e) + "\n " + r$
IF e <> 0
  AUDIO.STOP
ELSE
  myVarPointer = ReorderToFront()
  LIST.GET stationListPointer, t, a$
  POPUP "LOADING"
  AUDIO.STOP: AUDIO.LOAD n,a$: AUDIO.PLAY n
ENDIF
ENDIF
BROADCAST.RESUME


Happy coding
Gregor

Re: Hot summer of code

Wed May 10, 2017 3:27 pm

Hi All,

Unfortunately Nicolas has left BASIC!, but the show must go on!

Added following enhancements To OliBasicXVIII:

BigDecimal implemented
ROUND() rounding option "Legacy int()"
Some fixes

https://github.com/RFO-BASIC/Basic/files/991295/OliBasicXVIII.zip

Here is also a new example for a BENCHMARK against X11Basic

A big thank you to Marcus Hoffmann the developer of X11Basic for the idea and the fantastic Atom clock digits.

Code:
! This example shows the different effects
!
FN.DEF putstring(bundleP, bitmap_ms, object_ptr0, x, y, z$, scale, start)
! locals.on % From here all variables are local
GR.BITMAP.DRAWINTO.START bitmap_ms % We want to draw into an existing bitmap
LET xM=0 % Starting on the left. LET because we are in a loop, it is a little faster.
FOR i = 1 TO LEN(z$) % For charter
  LET b$ = MID$(z$,i,1) % Extract each character seperatly
  BUNDLE.CONTAIN bundleP, b$ , contains % Is the character member of the bundle keys?
  IF contains = 0 THEN b$ = ":" % If not, use the colon
  BUNDLE.GP bundleP, b$, map_ptrx % Load the character picture from the bundle

  GR.BITMAP.DRAW object_ptr, map_ptrx, xM , 0 % Draw the character into the parent bitmap
  GR.BITMAP.SIZE map_ptrx, width, height % Detect the width of the current character
  LET xM = xM + width % Add the with, so we get the right place for the next character
NEXT i
GR.BITMAP.DRAWINTO.END % Draw into finished
! ? "hagen"; hagen % If hagen is print as 0 it is local otherwise global with 3
IF start = 1 % If the bitmaps have been drawn on the screen.
  GR.MODIFY object_ptr0, "bitmap", bitmap_ms % Rewrite only the bitmap contens
ELSE
  GR.STATUSBAR sHeight % Detecting the status bar higth
  ! Draw bitmap object on the screen
  GR.BITMAP.DRAW object_ptr0, bitmap_ms, x*scale , y*scale+sHeight
ENDIF
!? object_ptr, object_ptr0
! FN.RTN object_ptr % Returns an object pointer
! locals.off % From here all variables are global if GLOBALS set to all
FN.END
FN.DEF putNumbers(bundleP, scale, bitmap_ms1, bitmap_ms2, bitmap_ms3, object_ptr1, object_ptr2, object_ptr3, mStart)
! locals.on % From here all variables are local
LET t = TIME() % Get the time in millisconds from 1970-01-01
! Convert the time value to a String with seconds, decimal point and milliseconds
! LET z$ = INT$(t/1000) + "." + LEFT$(INT$((t*1000 - INT(t*1000))/1000),3) % exponential shifting hack
BIGD.MOVEPOINTLEFT INT$(t),3, z$ % BigDecimal, moving the decimal point three steps to the left
! Put the String z$ in the bitmap with the pointer bitmap_ms1
! bundleP contains the characters
! 0, 0 are the coordinates to draw the bitmap
putstring(bundleP, bitmap_ms1, object_ptr1, 0, 0, z$, scale, mStart)
! Retruns sperated time values
TIME t, Year$, Month$, Day$, Hour$, Minute$, Second$, WeekDay, isDST
LET z$ = Hour$ + ":" + Minute$ + ":" + Second$
! Put the String z$ in the bitmap with the pointer bitmap_ms2
putstring(bundleP, bitmap_ms2, object_ptr2, 10, 50, z$, scale, mStart)
LET z$ = Day$ + ":" + Month$ + ":" + Year$
! Put the String z$ in the bitmap with the pointer bitmap_ms3
putstring(bundleP, bitmap_ms3, object_ptr3, 100, 100, z$, scale, mStart)
GR.RENDER
! LET mStart = 1   % Now all three bitmaps have to be drawn
! ? "kurt"; kurt % If kurt is print as 0 it is local otherwise global with 44
! locals.off % From here all variables are global if GLOBALS set to all
FN.END

! *** Main Program ***
GR.OPEN 255, 0, 0, 0, 1 % Open the Graphic screen. Statusbar is set to on.
GR.ORIENTATION -1 % Orientation Landscape and Portraid
GR.SCREEN w,h % Detecting the screen size
GR.STATUSBAR sHeight % Detecting the status bar higth
w = MIN(w,h-sHeight) % The smalest width in Landscape and Portraid
kurt = 44 % Value for testing Globals and Locals
hagen = 3 % Value for testing Globals and Locals

GR.BITMAP.LOAD bp, "Digits2.png" % Loading the bitmap with 11 different characters
scale = w/14/23 % Scale factor  width / max. 14 characters / max. char. width is 23
FOR i = 1 TO 10 %For digit 0 to 9
GR.BITMAP.CROP bitmap_ptr, bp, (i-1)*23, 0, 23, 32 % Crop the digit from the bitmap
GR.BITMAP.SCALE new_bitmap_ptr, bitmap_ptr, 23*scale, 32*scale % Scale the digit
BUNDLE.PP bundleP, INT$(i-1), new_bitmap_ptr % Put the digit as a picture in a bundle
GR.BITMAP.DELETE bitmap_ptr % Delete an unused bitmap as soon as possible
NEXT i
GR.BITMAP.CROP bitmap_ptr, bp, (i-1)*23, 0, 10, 32 % Crop the colon from the bitmap
GR.BITMAP.SCALE new_bitmap_ptr, bitmap_ptr, 10*scale, 32*scale % Scale the colon
BUNDLE.PP bundleP, ":", new_bitmap_ptr % Put the colon as a picture in the same bundle
GR.BITMAP.DELETE bitmap_ptr % Delete an unused bitmap as soon as possible

GR.BITMAP.CREATE bitmap_ms1, 14*23*scale, 32*scale % Creates an empty bitmap
GR.BITMAP.CREATE bitmap_ms2,  7*23*scale, 32*scale
GR.BITMAP.CREATE bitmap_ms3,  9*23*scale, 32*scale

object_ptr1 = 1 % Creates a fixed object pointer
object_ptr2 = 2
object_ptr3 = 3


mStart = 0 % Creates a start variable

!GLOBALS.ALL
! *** Main Loop ***
! Call the drawing function for all three bitmaps with current date and time
! bundleP contains the characters
! scale is the scale factor
! bitmap_ms1, bitmap_ms2, bitmap_ms3 are the bitmap pointer
DO
putNumbers(bundleP, scale, bitmap_ms1, bitmap_ms2, bitmap_ms3, object_ptr1, object_ptr2, object_ptr3, mStart)
mStart=1
UNTIL 0
!GLOBALS.NONE

exit

!!
So now you can play with GLOBALS.ALL and LOCALS.ON
!!



The X11Basic code:
https://github.com/RFO-BASIC/Basic/files/991309/fancy-digits.X11.zip

The OliBasic code:
https://github.com/RFO-BASIC/Basic/files/991358/fanci_digits.Oli.zip

Someone said some posts before: "Bundles are slow!"
But I think in this case absolutely not.

X11BASIC:
Image

OliBasic:
Image


Try and a little feedback would be nice.

Happy coding

Gregor
Last edited by aFox on Thu May 11, 2017 2:05 am, edited 2 times in total.

Re: Hot summer of code

Wed May 10, 2017 4:25 pm

Runs well Gregor
clock.PNG
clock.PNG (188.59 KiB) Viewed 221 times

Regards Roy

Re: Hot summer of code

Thu May 11, 2017 1:12 am

aFox wrote:A big thank you to Marcus Hofmann the developer of X11Basic for the idea and the fantastic Atom clock digits.

I haven't (yet) tried the code...

But the Nixie-tube display caught my eye. This is because in my early years in electronics I was into gas-discharge tubes. As my apprenticeship project I was lead of a two-man team designing and building a digital clock which used dekatrons in the counting circuits and a home-made 5x7 matrix of 35 neon bulbs for each digit of the clock display. No digital circuits at all; no integrated circuits were available. (So no actual Nixie tubes, but they were used a lot in instruments at the time.)

Mike.
Post a reply