puck.ReadTemp( OnRead );
puck.Send( "console.log('BAT|'+NRF.getBattery());\n" );
puck.SetOnReceive( OnRead )
puck.Send( "console.log(NRF.getBattery());\n" );in the OnRead function show a popup.
*/
//////// sample code ////////
app.LoadPlugin( "PuckJS" );
function OnStart()
{
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
// the output from cosole.log will be sent to
// this app
var code = "console.log('Hello Folks');\n";
txt = app.CreateTextEdit( code, 0.9, 0.8, "MultiLine" );
lay.AddChild( txt );
app.AddLayout( lay );
btnSend = app.CreateButton( "Send", 0.3, 0.1 );
btnSend.SetOnTouch( btnSend_OnTouch );
lay.AddChild( btnSend );
puck = app.CreatePuckJS();
puck.Scan( "Puck" );
// This tells the app to call function OnRead
// when data received from puck
puck.SetOnReceive( OnRead )
}
// called when data received
function OnRead(result)
{
app.ShowPopup( result );
}
// called when send button pressed
function btnSend_OnTouch()
{
puck.SendCode( txt.GetText() );
}
If you type the code below into the TextEdit
of the code I posted, then press the Send button, do you get the battery reading?
console.log('BAT|'+NRF.getBattery());
I don't have a device that shows the problem and would like confirmation that it does not work before trying something else.