Skip to content

Instantly share code, notes, and snippets.

@jsinai
Last active April 16, 2022 17:39
Show Gist options
  • Select an option

  • Save jsinai/26ec467dc910fa3ce31b1c3350799e47 to your computer and use it in GitHub Desktop.

Select an option

Save jsinai/26ec467dc910fa3ce31b1c3350799e47 to your computer and use it in GitHub Desktop.

Revisions

  1. jsinai revised this gist Jul 24, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion canonical.brs
    Original file line number Diff line number Diff line change
    @@ -63,10 +63,10 @@ Sub CreateHtmlWidget(url$ as String)
    user_stylesheet: "sd:/canonical.css"
    mouse_enabled: true
    hwz_default: "on"
    port: gaa.mp
    url: url$
    }
    gaa.htmlWidget = CreateObject("roHtmlWidget", rect, config)
    gaa.htmlWidget.setPort(gaa.mp)

    End Sub
    Sub HandleEvents()
  2. jsinai revised this gist Jun 14, 2018. 1 changed file with 19 additions and 19 deletions.
    38 changes: 19 additions & 19 deletions canonical.brs
    Original file line number Diff line number Diff line change
    @@ -48,25 +48,25 @@ Function DoCanonicalInit()
    End Function
    Sub CreateHtmlWidget(url$ as String)

    gaa = GetGlobalAA()
    width=gaa.vm.GetResX()
    height=gaa.vm.GetResY()
    rect=CreateObject("roRectangle", 0, 0, width, height)

    config = {
    ' Uncomment if using node.js features
    ' nodejs_enabled: true
    inspector_server: { port: 2999 }
    ' Uncomment if communicating with BrightScript http server
    ' security_params: { websecurity: false }
    brightsign_js_objects_enabled: true
    user_stylesheet: "sd:/canonical.css"
    mouse_enabled: true
    hwz_default: "on"
    url: url$
    }
    gaa.htmlWidget = CreateObject("roHtmlWidget", rect, config)
    gaa.htmlWidget.setPort(gaa.mp)
    gaa = GetGlobalAA()
    width=gaa.vm.GetResX()
    height=gaa.vm.GetResY()
    rect=CreateObject("roRectangle", 0, 0, width, height)

    config = {
    ' Uncomment if using node.js features
    ' nodejs_enabled: true
    inspector_server: { port: 2999 }
    ' Uncomment if communicating with BrightScript http server
    ' security_params: { websecurity: false }
    brightsign_js_objects_enabled: true
    user_stylesheet: "sd:/canonical.css"
    mouse_enabled: true
    hwz_default: "on"
    url: url$
    }
    gaa.htmlWidget = CreateObject("roHtmlWidget", rect, config)
    gaa.htmlWidget.setPort(gaa.mp)

    End Sub
    Sub HandleEvents()
  3. jsinai revised this gist Apr 30, 2018. No changes.
  4. jsinai revised this gist Apr 30, 2018. 1 changed file with 13 additions and 9 deletions.
    22 changes: 13 additions & 9 deletions canonical.brs
    Original file line number Diff line number Diff line change
    @@ -53,15 +53,19 @@ Sub CreateHtmlWidget(url$ as String)
    height=gaa.vm.GetResY()
    rect=CreateObject("roRectangle", 0, 0, width, height)

    gaa.htmlWidget = CreateObject("roHtmlWidget", rect)
    gaa.htmlWidget.EnableSecurity(false)
    gaa.htmlWidget.SetUserStylesheet("sd:/autorun.css")
    gaa.htmlWidget.SetUrl(url$)
    gaa.htmlWidget.EnableJavascript(true)
    gaa.htmlWidget.StartInspectorServer(2999)
    gaa.htmlWidget.EnableMouseEvents(true)
    gaa.htmlWidget.AllowJavaScriptUrls({ all: "*" })
    gaa.htmlWidget.SetHWZDefault("on")
    config = {
    ' Uncomment if using node.js features
    ' nodejs_enabled: true
    inspector_server: { port: 2999 }
    ' Uncomment if communicating with BrightScript http server
    ' security_params: { websecurity: false }
    brightsign_js_objects_enabled: true
    user_stylesheet: "sd:/canonical.css"
    mouse_enabled: true
    hwz_default: "on"
    url: url$
    }
    gaa.htmlWidget = CreateObject("roHtmlWidget", rect, config)
    gaa.htmlWidget.setPort(gaa.mp)

    End Sub
  5. jsinai created this gist May 15, 2017.
    115 changes: 115 additions & 0 deletions canonical.brs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,115 @@
    Sub Main(args)

    url$ = "file:///index.html"
    if args <> invalid and args.Count() > 0 then
    url$ = args[0]
    end if
    print "url = ";url$

    DoCanonicalInit()

    CreateHtmlWidget(url$)

    HandleEvents()
    End Sub
    Function DoCanonicalInit()

    gaa = GetGlobalAA()

    EnableZoneSupport(1)

    ' Enable mouse cursor
    gaa.touchScreen = CreateObject("roTouchScreen")
    gaa.touchScreen.EnableCursor(true)

    gaa.mp = CreateObject("roMessagePort")

    gaa.gpioPort = CreateObject("roGpioControlPort")
    gaa.gpioPort.SetPort(gaa.mp)

    gaa.vm = CreateObject("roVideoMode")
    gaa.vm.setMode("auto")

    ' set DWS on device
    nc = CreateObject("roNetworkConfiguration", 0)
    if type(nc) <> "roNetworkConfiguration" then
    nc = CreateObject("roNetworkConfiguration", 1)
    endif
    if type(nc) = "roNetworkConfiguration" then
    dwsAA = CreateObject("roAssociativeArray")
    dwsAA["port"] = "80"
    nc.SetupDWS(dwsAA)
    nc.Apply()
    endif

    gaa.hp = CreateObject("roNetworkHotplug")
    gaa.hp.setPort(gaa.mp)

    End Function
    Sub CreateHtmlWidget(url$ as String)

    gaa = GetGlobalAA()
    width=gaa.vm.GetResX()
    height=gaa.vm.GetResY()
    rect=CreateObject("roRectangle", 0, 0, width, height)

    gaa.htmlWidget = CreateObject("roHtmlWidget", rect)
    gaa.htmlWidget.EnableSecurity(false)
    gaa.htmlWidget.SetUserStylesheet("sd:/autorun.css")
    gaa.htmlWidget.SetUrl(url$)
    gaa.htmlWidget.EnableJavascript(true)
    gaa.htmlWidget.StartInspectorServer(2999)
    gaa.htmlWidget.EnableMouseEvents(true)
    gaa.htmlWidget.AllowJavaScriptUrls({ all: "*" })
    gaa.htmlWidget.SetHWZDefault("on")
    gaa.htmlWidget.setPort(gaa.mp)

    End Sub
    Sub HandleEvents()

    gaa = GetGlobalAA()
    receivedIpAddr = false
    nc = CreateObject("roNetworkConfiguration", 0)
    currentConfig = nc.GetCurrentConfig()
    if currentConfig.ip4_address <> "" then
    ' We already have an IP addr
    receivedIpAddr = true
    print "=== BS: already have an IP addr: ";currentConfig.ip4_address
    end if

    receivedLoadFinished = false
    while true
    ev = wait(0, gaa.mp)
    print "=== BS: Received event ";type(ev)
    if type(ev) = "roNetworkAttached" then
    print "=== BS: Received roNetworkAttached"
    receivedIpAddr = true
    else if type(ev) = "roHtmlWidgetEvent" then
    eventData = ev.GetData()
    if type(eventData) = "roAssociativeArray" and type(eventData.reason) = "roString" then
    if eventData.reason = "load-error" then
    print "=== BS: HTML load error: "; eventData.message
    else if eventData.reason = "load-finished" then
    print "=== BS: Received load finished"
    receivedLoadFinished = true
    else if eventData.reason = "message" then
    ' To use this: msgPort.PostBSMessage({text: "my message"});
    endif
    else
    print "=== BS: Unknown eventData: "; type(eventData)
    endif
    else if type(ev) = "roGpioButton" then
    if ev.GetInt() = 12 then stop
    else
    print "=== BS: Unhandled event: "; type(ev)
    end if
    if receivedIpAddr and receivedLoadFinished then
    print "=== BS: OK to show HTML, showing widget now"
    gaa.htmlWidget.Show()
    gaa.htmlWidget.PostJSMessage({msgtype:"htmlloaded"})
    receivedIpAddr = false
    receivedLoadFinished = false
    endif
    endwhile

    End Sub
    3 changes: 3 additions & 0 deletions canonical.css
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    body {
    background-color: white;
    }