'version 1.5 'Adds content from USB to SD, content of USB stick 'add logic to check for zero files fond on sd 'add card reformat if multiple failures to open or findfiles Sub Main() EnableZoneSupport(true) debug=false listsize = 250 '250 files tmr = createobject("roMessagePort") brightsign = createPlayer(debug,listsize,tmr) mdl = createobject("roDeviceInfo") brightsign.sTime = createobject("roSystemTime") brightsign.iTimer = CreateObject("roTimer") brightsign.uTimer = CreateObject("roTimer") brightsign.version$ = mdl.GetVersion() + " script 1.5" start: brightsign.SetUSBTimer() if brightsign.GetSDListSucceeds() then brightsign.SortMediaFiles() brightsign.player.StopDisplay() 'stop image brightsign.vplayer.StopClear() 'stop video brightsign.videoplaying=false brightsign.StopImageTimer() 'stop image display timer playnext: if brightsign.debug brightsign.printdebug("Playing next") brightsign.PlayNext() loop: if debug brightsign.printdebug("Waiting..") msg = wait(0, tmr) if type(msg) = "roVideoEvent" then if msg.GetInt()=8 then brightsign.videoPlaying=false goto playnext endif else if type(msg) = "roTimerEvent" then if brightsign.iTimer.GetIdentity() = msg.GetSourceIdentity() then goto playnext else if brightsign.uTimer.GetIdentity() = msg.GetSourceIdentity() then if brightsign.CheckIfUsbAttached() then if brightsign.UsbRemovedSinceListDetection then brightsign.onscreen("USB detected") brightsign.GetUSBList() goto start else brightsign.SetUSBTimer() endif else brightsign.SetUSBTimer() brightsign.UsbRemovedSinceListDetection=true endif endif endif goto loop else brightsign.PrintDebug ("No Files found on SD") brightsign.onscreen("No Files on SD. Attach USB To Update") brightsign.SetUSBTimer() goto loop endif End Sub Function createPlayer (debug as Boolean, listsize as Integer, mp as Object) as Object o = createobject("roAssociativeArray") o.player = createobject("roImagePlayer") o.vplayer = createobject("roVideoPlayer") o.vplayer.SetPort(mp) o.GetSDListSucceeds = GetSDListSucceeds 'bool o.ClearSD = ClearSD o.GetUSBList = GetUSBList o.SortMediaFiles = SortMediaFiles o.CheckIfUsbAttached = CheckIfUsbAttached 'bool o.ItsAJpeg = ItsAJpeg 'bool o.ItsAVideo = ItsAVideo 'bool o.ItsAnImage = ItsAnImage 'bool o.PlayNext = PlayNext o.PrintDebug = PrintDebug o.Onscreen = Onscreen o.HideOnscreenMessage = HideOnscreenMessage o.SetImageTimer = SetImageTimer o.StopImageTimer = StopImageTimer o.SetUSBTimer = SetUSBTimer o.mp=mp o.listlength=0 o.currentposition=0 o.debug = debug o.UsbRemovedSinceListDetection = true o.videoPlaying=false o.insertfiles=false o.removefiles=false o.version$="version 1.7" o.usbpath$="USB1:" o.validator$="1234" o.loglist = createobject("roList") DIM tempArray[listsize] o.myfiles=tempArray o.player.SetDefaultMode(1) 'scale to fit o.vplayer.SetViewMode(2) 'scale to fit return o End Function Function GetSDListSucceeds() as Boolean 'retrieves list of files from the flash card if m.debug m.printdebug("GetSDListSucceeds() function") m.listlength=0 m.currentposition=0 count=0 l=matchfiles("SD:", "*") for i=1 to l.Count() file = l.RemoveHead() if m.ItsAnImage(file) or m.ItsAVideo(file) then m.myfiles[count]=file if m.debug m.printdebug(m.myfiles[count]+" added to playlist") count = count + 1 endif next m.listlength=count if m.debug then m.printdebug(str(m.listlength)+" files found on SD") m.onscreen(str(m.listlength)+" files found on SD") endif return (m.listlength > 0) end Function Function CheckIfUsbAttached() as Boolean if m.debug m.printdebug("Checking for USB") tusbpath$=m.usbpath$ if m.usbremovedsincelistdetection then for k = 1 to 9 usbplace$=right(str(k),1) tusbpath$="USB"+usbplace$+":" tusblist = matchfiles(tusbpath$, "*") if tusblist.Count() > 0 then exit for next else tusblist = matchfiles(tusbpath$, "*") endif m.usbpath$=tusbpath$ m.usblist=createobject("roList") for each file in tusblist if m.ItsAnImage(file) or m.ItsAVideo(file) then m.usblist.AddHead(file) if m.debug m.printdebug("Image or Video found: "+file) else if m.debug m.printdebug("Not and Image or Video") endif next tusblist=invalid return (m.usblist.count() > 0) end function Sub GetUSBList() 'retrieves list of files from the flash card if m.debug m.printdebug("GetUSBList() function") sdpath="SD:" failcount=0 tempcount=0 scriptfound=false m.UsbRemovedSinceListDetection=false 'm.ClearSD() 'deletes all content from the sd - disabled in this version 'if m.insertfiles = false then m.ClearSD() 'not active for each file in m.usblist If m.ItsAnImage(file) or m.ItsAVideo(file) then if type(createobject("roReadFile", m.usbpath$+file)) = "roReadFile" then ok = copyfile(m.usbpath$+file, sdpath+file) if ok then tempcount = tempcount+1 message$=m.usbpath$+" Successfully copied "+file if m.debug m.printdebug(message$) m.onscreen(message$) m.loglist.AddTail(message$) else message$="Failed to copy "+file if m.debug m.printdebug(message$) failcount = failcount+1 m.onscreen(message$) m.loglist.AddTail(message$) endif else m.onscreen(file+" : File Not Found") failcount=failcount+1 endif sleep(250) endif next if copyfile(m.usbpath$+"/script/autorun.brs", sdpath+"autorun.brs") then DeleteFile(m.usbpath$+"/script/autorun.brs") m.loglist.AddTail("Script Updated") m.onscreen("Script Updated") 'if type(CreateObject("roReadFile", m.usbpath$+"USBUpdatelog.txt"))="roReadFile" then scriptfound=true endif if copyfile(m.usbpath$+"/boot/autorun.brs", sdpath+"boot.brs") then DeleteFile(m.usbpath$+"/boot/autorun.brs") mfg=CreateObject("roMfgTest") if type(mfg) = "roMfgTest" then if mfg.WriteBootFile("", "autorun.brs") then ok = mfg.WriteBootFile("SD:boot.brs", "autorun.brs") if not ok m.onscreen("Failed to write to boot location") if not ok m.loglist.AddTail("Failed to write to boot location") if ok then DeleteFile("SD:autorun.brs") DeleteFile("SD:boot.brs") m.loglist.AddTail("Script Loaded to Memory") m.onscreen("Script Loaded to Memory") scriptfound=true endif sleep(5000) else m.onscreen("failed to write to boot location") sleep(5000) endif mfg=0 endif endif message$=str(tempcount)+" Copied /"+str(failcount)+" Failed "+". Remove USB Stick" m.loglist.AddTail(message$) 'if type(CreateObject("roReadFile", m.usbpath$+"USBUpdatelog.txt"))="roReadFile" then 'prevents flush to USB if USB has been prematurely removed m.loglist.AddTail("USB Update " + m.version$) 'write log if usb present m.newFile = CreateObject("roCreateFile", m.usbpath$+"USBUpdatelog.txt") if type(m.newfile) = "roCreateFile" then For each entry in m.loglist m.newfile.sendline(entry) next m.newfile.Flush() else m.onscreen("Failed to Write Log to USB") endif sleep(10000) m.onscreen(str(tempcount)+" Copied /"+str(failcount)+" Failed "+". Remove USB Stick") sleep(5000) if scriptfound then RebootSystem() if instr(1,m.usbpath$,"4") > 0 then m.onscreen("Maintenance: Rebooting System") sleep(5000) RebootSystem() endif m.tw=invalid end Sub Function ItsAJpeg(file as String) as Boolean return(right(ucase(file),4) = ".JPG") end function Sub PrintDebug (Error as String) print(Error) end Sub Sub PlayNext () sdpath$="SD:" currentfile=m.myfiles[m.currentposition] if m.debug m.printdebug("PlayNext() - "+currentfile+" "+str(m.currentposition)) if ItsAVideo(currentfile) then m.StopImageTimer() m.vplayer.PlayFile(sdpath$+currentfile) m.player.StopDisplay() m.videoPlaying=true else m.SetImageTimer() m.player.DisplayFile(sdpath$+currentfile) m.videoPlaying=false m.vplayer.StopClear() endif if m.listlength = 0 then m.onscreen("No Images or Videos Found on SD") if m.currentposition < m.listlength-1 then m.currentposition = m.currentposition+1 else m.currentposition = 0 endif 'nextfile = m.myfiles[m.currentposition] 'if ItsAnImage(nextfile) then m.player.PreloadFile(sdpath$+nextfile) End Sub Sub Onscreen(message as String) if type(m.tw) <> "roTextWidget" then videoMode = CreateObject("roVideoMode") resX = videoMode.GetResX() resY = videoMode.GetResY() videoMode = invalid r=CreateObject("roRectangle",0,resY/2-resY/64,resX,resy/20) twParams = CreateObject("roAssociativeArray") twParams.LineCount = 1 twParams.TextMode = 2 twParams.Rotation = 0 twParams.Alignment = 1 m.tw=CreateObject("roTextWidget",r,1,2,twParams) endif m.tw.Show() m.tw.PushString(message) end sub Sub ClearSD () 'write log usb message$="Deleting Files" m.onscreen("Deleting Files from SD Card") sleep(1500) count=0 l=Matchfiles("SD:","*") for i=1 to l.Count() file = l.RemoveHead() if m.ItsAnImage(file) or m.ItsAVideo(file) then ok = DeleteFile("SD:"+file) if ok then m.onscreen("Deleted "+file) m.loglist.AddTail("Deleted "+file) sleep(200) count=count+1 else m.onscreen("Failed to Delete "+file) sleep(500) m.loglist.AddTail("Failed to Delete"+file) endif endif next message$=str(count)+" files deleted." m.onscreen(message$) m.loglist.AddTail(message$) 'if type(CreateObject("roReadFile", m.usbpath$+"USBUpdatelog.txt"))="roReadFile" then end Sub Function ItsAnImage(file as String) as Boolean return(right(ucase(file),4) = ".JPG" or right(ucase(file),4) = ".PNG" or right(ucase(file),4) = ".BMP") end function Function ItsAVideo(file as String) as Boolean if right(ucase(file),3) = ".TS" then return TRUE return(right(ucase(file),4) = ".MPG" or right(ucase(file),4) = ".VOB" or right(ucase(file),4) = ".MP4" or right(ucase(file),4) = ".MOV" or right(ucase(file),4) = ".WMV") end function Sub HideOnscreenMessage() m.tw.Hide() end sub 'from autoplay script 3.2.0.4 Sub SortMediaFiles() numberOfFiles% = m.myfiles.Count() if numberOfFiles% > 0 then for i% = numberOfFiles% - 1 to 1 step -1 for j% = 0 to i%-1 if m.myfiles[j%] > m.myfiles[j%+1] then tmp = m.myfiles[j%] m.myfiles[j%] = m.myfiles[j%+1] m.myfiles[j%+1] = tmp endif next next endif End Sub Sub setImagetimer() if m.debug m.printdebug("Setting Image Timer") newTimeout = m.sTime.GetLocalDateTime() newTimeout.AddMilliseconds(4367) m.iTimer.SetDateTime(newTimeout) m.iTimer.SetPort(m.mp) m.iTimer.Start() end sub Sub StopImagetimer() if type(m.iTimer) = "roTimer" then m.iTimer.Stop() end sub Sub setUSBtimer() if m.debug m.printdebug("Setting USB Timer") newTimeout = m.sTime.GetLocalDateTime() newTimeout.AddMilliseconds(11000) m.uTimer.SetDateTime(newTimeout) m.uTimer.SetPort(m.mp) m.uTimer.Start() end sub