You probably have seen these nifty little IoT Flic buttons around. They are a fun and relative cheap BLE button that allows you to do something when the button is clicked, doubleclicked or hold.
Demo video:
How to use:
1. Install the Flic app from the Google Play.
2. On their developer page, create a new app: you get a key and a secret.
3. Copy the ABFlicB4A library jar and xml to your library folder and select it in B4A
Example usage code:
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private flic As ABFlic
Private Button2 As Button
Private Button3 As Button
Private Button4 As Button
Private Label1 As Label
Private Button1 As Button
Private MyFlicID As String
Private FlicResults As List
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Log("created")
Activity.LoadLayout("1")
FlicResults.Initialize
FlicResults.Add("RESULTACTION_HOLD")
FlicResults.Add("RESULTACTION_SINGLECLICK")
FlicResults.Add("RESULTACTION_DOUBLECLICK")
End Sub
Sub Activity_Resume
' your key and secret
flic.Initialize("Flic", "d60d36a0-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "db5c2b3d-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "ABFlicTest")
End Sub
Sub Button1_Click
flic.ForgetButton(MyFlicID)
End Sub
Sub Button2_Click
flic.GrabButton
End Sub
Sub Button3_Click
flic.StartListening
End Sub
Sub Button4_Click
flic.StopListening
End Sub
Sub flic_Added(buttonID As String, Name As String)
MyFlicID = buttonID
Log("Added: " & buttonID)
Label1.Text = "Added: " & buttonID & CRLF & Label1.Text
End Sub
Sub flic_Clicked(buttonID As String, wasQueued As Boolean, timeDiff As Int)
MyFlicID = buttonID
Log("Clicked: " & buttonID)
Label1.Text = "Clicked: " & buttonID & CRLF & Label1.Text
End Sub
Sub flic_DoubleClicked(buttonID As String, wasQueued As Boolean, timeDiff As Int)
MyFlicID = buttonID
Log("DoubleClicked: " & buttonID)
Label1.Text = "DoubleClicked: " & buttonID & CRLF & Label1.Text
End Sub
Sub flic_Holded(buttonID As String, wasQueued As Boolean, timeDiff As Int)
MyFlicID = buttonID
Log("Holded: " & buttonID)
Label1.Text = "Holded: " & buttonID & CRLF & Label1.Text
End Sub
Sub flic_Removed(buttonID As String)
MyFlicID = ""
Log("Removed: " & buttonID)
Label1.Text = "Removed: " & buttonID & CRLF & Label1.Text
End Sub
Sub flic_Error(err As Int)
Log("Error: " & err)
Label1.Text = "Error: " & err & CRLF & Label1.Text
End Sub
I'm currently working on a Desktop/Raspberry Pi version of this library, which I will share in the B4J forum later.