Hi All as object thread i have:
Raspberry 3 Android 8.1.0 ( API 27) + Android Things Build OIM1.18 OEM Version 16
All work in DIRECTION_OUT_INITIALLY_LOW, but if i add DIRECTION_IN i have an infinite loop True - False. In summary Statechanged changes continuously to False / True.
I have an infinite loop on this code:
This is complete code:
This is Manifest:
Note: In manifst also change in android:targetSdkVersion=27 and without AddPermission(com.google.android.things.permission.MANAGE_INPUT_DRIVERS) but dont change nothing
As in this movie:
Note:
1. If i press the button it executes the instruction (as in the movie), but if i release the button it starts the infinite loop true / false ( as if it didn't memorize the state )
2. If i replace the button with an LED (and of course I change the instruction in DIRECTION_OUT_INITIALLY_LOW) it works without any problem.
Any idea ??
Thanks
Marco
Raspberry 3 Android 8.1.0 ( API 27) + Android Things Build OIM1.18 OEM Version 16
All work in DIRECTION_OUT_INITIALLY_LOW, but if i add DIRECTION_IN i have an infinite loop True - False. In summary Statechanged changes continuously to False / True.
I have an infinite loop on this code:
B4X:
pin11 = pm.OpenGpio("BCM11")
pin11.Direction = pin11.DIRECTION_IN
pin11.AddListener("pin11")
....
Sub pin11_StateChanged (Value As Boolean)
Dim clr As Int
Log(Value)
'True
If Value Then
clr = Colors.Red
Else
'False
clr = Colors.Green
End If
Activity.Color = clr
End Sub
This is complete code:
B4X:
#Region Project Attributes
#ApplicationLabel: AndroidThings
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: landscape
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
#AdditionalJar: androidthings, ReferenceOnly
Sub Process_Globals
Private pm As PeripheralManager
Private pin4 As Gpio 'led
Private pin13 As Gpio 'led
Private pin23 As Gpio 'led
Private pin21 As Gpio 'led
Private pin11 As Gpio 'button
End Sub
Sub Globals
Private ToggleButton1 As ToggleButton
Private Label1 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
pm.Initialize
Log(pm.GpioList)
pin4 = pm.OpenGpio("BCM4")
pin4.Direction = pin4.DIRECTION_OUT_INITIALLY_LOW
pin13 = pm.OpenGpio("BCM13")
pin13.Direction = pin13.DIRECTION_OUT_INITIALLY_LOW
pin23 = pm.OpenGpio("BCM23")
pin23.Direction = pin23.DIRECTION_OUT_INITIALLY_LOW
pin21 = pm.OpenGpio("BCM21")
pin21.Direction = pin21.DIRECTION_OUT_INITIALLY_LOW
pin11 = pm.OpenGpio("BCM11")
pin11.Direction = pin11.DIRECTION_IN
pin11.AddListener("pin11")
End If
Activity.LoadLayout("1")
End Sub
Sub pin11_StateChanged (Value As Boolean)
Dim clr As Int
Log(Value)
'True
If Value Then
clr = Colors.Red
Else
'False
clr = Colors.Green
End If
Activity.Color = clr
End Sub
Sub ToggleButton1_CheckedChange(Checked As Boolean)
pin4.Value = Checked 'turn on or off the led
pin13.Value = Checked 'turn on or off the led
pin21.Value = Checked 'turn on or off the led
pin23.Value = Checked 'turn on or off the led
End Sub
This is Manifest:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="19"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.
'PER ANDROID THINGS
AddApplicationText(<uses-library android:name="com.google.android.things"/>)
''Launch activity automatically on boot (can remove if not needed)
AddActivityText(Main,
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
)
AddPermission(com.google.android.things.permission.USE_PERIPHERAL_IO)
AddPermission(com.google.android.things.permission.MANAGE_INPUT_DRIVERS)
Note: In manifst also change in android:targetSdkVersion=27 and without AddPermission(com.google.android.things.permission.MANAGE_INPUT_DRIVERS) but dont change nothing
As in this movie:
Note:
1. If i press the button it executes the instruction (as in the movie), but if i release the button it starts the infinite loop true / false ( as if it didn't memorize the state )
2. If i replace the button with an LED (and of course I change the instruction in DIRECTION_OUT_INITIALLY_LOW) it works without any problem.
Any idea ??
Thanks
Marco
Last edited: