2013/02/25

Compass Functions Test

This is a test program of electronic compass function.

This can not use in iPod touch because iPod touch does not have electric compass.
This is the difference between iPhone and iPod touch except phone function.
//----------------------------------------------------------------------------------------------
// compass test
//----------------------------------------------------------------------------------------------

print "version Motion=";versionXBiOSMotion$()

font("Cochin",6):// Function Key's Font
setFunctionKey(0,"end"   ,'!')
setFunctionKey(1,"pause" ,'p')
setFunctionKey(2,"start" ,'s')
setFunctionKey(3,"clear" ,'c')
displayFunctionKey(YES,0,3)
kBackgroundAlpha(0.9)
font("IPAGothic")

if compassStart(10) then {
 print localizedString("方位取得は使えません","Can't use compass.")
 end
}

float degree,magnetic
int ky,cnt,i

while YES
 if not kbhit() then {
  i=0
  cnt=compassCount()
  if cnt>0 then locate(0,1):print "cnt=";cnt
  while cnt>0
   degree=compassGetData(magnetic)
   locate(0,2+i)
   if isLocalizeJapan() then {
    print using "極北からの角度=###.####,磁北からの角度=###.####";degree,magnetic
   } else {
    print using "true=###.####,magnetic=###.####";degree,magnetic
   }
   cnt=cnt-1
   i=i+1
   if kbhit() then break
  endwhile
 } else {
  ky=inkey()
  switch ky
   case 'p'
    compassPause(YES)
    print "Pause"
    break
   case 's'
    compassPause(NO)
    print "Start"
    break
   case 'c'
    cls()
    compassClear()
    break
   default:
    // just in case
    beep()
    break
  endswitch
  if ky='!' then break
 }
endwhile
compassEnd()
end

//----------------------------------------------------------------------------------------------

func str localizedString(js;str,es;str)
 if isLocalizeJapan() then return(js)
 return (es)
endfunc

//----------------------------------------------------------------------------------------------

Zip archive file : XBtests.zip

No comments:

Post a Comment