'Activity module
Sub Process_Globals
Dim yoyo As IOIO
Dim Timer1 As Timer 'connection timeout
Dim Timer2 As Timer
Dim led As PwmOutput 'use onboard led, pin 0, to show connection
End Sub
Sub Globals
Dim serial1 As Serial
Dim trouble As Exception
Dim BtnBT, btnConn As ToggleButton
Dim conn_attemps As Int
Dim Label1 As Label
Dim Pulse As Button
Dim Reset As Button
Dim In As PulseInput
Dim P As Double
'this goes here, right? anything else that need to be with it?
In = yoyo.OpenPulseInput (18,In.IP_PULL_DOWN,In.RATE_16MHZ,In.NEGATIVE , True)
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("layout1")
Timer1.Initialize("timer1",5000) 'time between connection attempts
Timer2.Initialize("Timer2",1)
Timer2.Enabled = True
yoyo.connect ("yoyo", BtnBT.Checked, 0)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then 'disconnect IOIO if app closed
led.Close
yoyo.disconnect()
End If
End Sub
Sub btnConn_CheckedChange(Checked As Boolean)
'connect IOIO
If Checked Then
conn_attemps=0
Timer1.Enabled=True
yoyo.connect ("yoyo", BtnBT.Checked, 0)
Else
Timer1.Enabled=False
yoyo.disconnect()
ToastMessageShow("IOIO Disconnected",True)
'Button4_Click
End If
End Sub
Sub YOYO_connected(noerror As Boolean)
'connected event, if noerror than connection made
If noerror Then
Timer1.Enabled=False
ToastMessageShow("IOIO Connected",True)
End If
'Button4_Click
If yoyo.IsInitialized Then
If yoyo.State="CONNECTED" Then
led=yoyo.OpenPwmOutput(0,led.OP_NORMAL,10) 'this led is active LOW
End If
Else
Dim trouble As Exception
trouble=LastException
ToastMessageShow(trouble.Message&CRLF&"IOIO State: "&yoyo.State, True)
End If
End Sub
Sub timer1_tick 'connection timeout timer
'still waiting to connect
Timer1.Enabled=False
'cancel attempt to connect
If yoyo.IsInitialized Then yoyo.Disconnect
If conn_attemps > 5 Then
ToastMessageShow("Connection Failed",True)
btnConn.Checked=False
Return
Else
conn_attemps=conn_attemps+1
ToastMessageShow("Connection attempt: "&conn_attemps, True)
End If
conn_attemps=conn_attemps+1
'try new connection
yoyo.connect("yoyo",BtnBT.Checked,1)
Timer1.Enabled=True
End Sub
Sub Timer2_Tick
In.F
'really not sure????????
End Sub
'End Sub
Sub Pulse_click
Label1.Text = Label1.Text + 1
End Sub
Sub Reset_click
Label1.Text = ""
End Sub