├── README.md ├── guides └── CheapB - Clean Jessie install on Raspberry PI with Python on AdaFruit WebIDE and CSR 4.0 dongle └── samples ├── c++ ├── .gitignore ├── Makefile └── main.cpp ├── java ├── .gitignore ├── Main.java └── Makefile └── python ├── IFTTT.py └── main.py /README.md: -------------------------------------------------------------------------------- 1 | # Flic SDK for Linux Beta 2 | 3 | ## Deprecated! 4 | 5 | This repository is now deprecated. 6 | 7 | ## New SDK 8 | 9 | We have now released a new SDK for Linux, which can be found here: https://github.com/50ButtonsEach/fliclib-linux-hci 10 | 11 | We will keep this repository available, but won't do any development. 12 | -------------------------------------------------------------------------------- /guides/CheapB - Clean Jessie install on Raspberry PI with Python on AdaFruit WebIDE and CSR 4.0 dongle: -------------------------------------------------------------------------------- 1 | Guide by CheapB 2 | 3 | Header says it all.. A couple of notes before we begin: 4 | 1) I am not an expert by any means, so feel free to comment or improve as you see fit 5 | 2) Do not attach your BT dongle before the instructions call for it. 6 | 7 | 3) It would be great if anyone have info on blueZ binaries pre-complied for RPI/Jessie. It is pretty painful to compile every time there is an update 8 | 9 | Lets get started: 10 | 11 | Download the raspbian jessie (https://downloads.raspberrypi.org/raspbian/images/raspbian-2015-11-24/2015-11-21-raspbian-jessie.zip) and install (https://www.raspberrypi.org/documentation/installation/installing-images/README.md) 12 | 13 | Configure network connection etc - what you normally will do or google it. Do NOT attach your BT dongle yet! :-) 14 | 15 | Install Putty or similar on your regular PC for SSH access to the RPI 16 | 17 | via SSH or on the CLI: 18 | 19 | update all system packages: 20 | sudo apt-get update 21 | 22 | update all installed packages: 23 | sudo apt-get upgrade 24 | 25 | this will take a while 26 | optional: clean out installation files: 27 | sudo apt-get clean 28 | 29 | install Adafruit WebIDE (https://learn.adafruit.com/webide/installation) 30 | 31 | Backup your SD card with Win32DiskImager (for windows) or similar if you are on a different platform. This will save you a lot of time if you want a clean install when the next beta is out 32 | 33 | install needed packages for blueZ: 34 | 35 | sudo apt-get install libglib2.0-dev 36 | sudo apt-get install libdbus-1-dev 37 | sudo apt-get install libudev-dev 38 | sudo apt-get install automake 39 | sudo apt-get install libtool 40 | sudo apt-get install libical-dev 41 | sudo apt-get install libreadline-dev 42 | 43 | Install BlueZ: 44 | git clone git://git.kernel.org/pub/scm/bluetooth/bluez.git 45 | 46 | cd bluez 47 | 48 | git checkout 5.37 49 | 50 | ./bootstrap 51 | 52 | this will take a while 53 | ./configure --enable-experimental --enable-library 54 | 55 | this will take a while 56 | make 57 | 58 | time for coffee 59 | sudo make install 60 | 61 | sudo shutdown -h now 62 | 63 | Insert the BT dongle and restart 64 | 65 | login 66 | 67 | cd bluez/src 68 | 69 | sudo ./bluetoothd -nEd 70 | 71 | This should be kept active 72 | 73 | Open a new SSH session 74 | mkdir flic 75 | cd flic 76 | 77 | sudo wget https://github.com/50ButtonsEach/fliclib-linux-dist/releases/download/1-beta3/fliclib-linux.tar.gz 78 | 79 | This will change based on the release - go and grab the newest link from the release page https://github.com/50ButtonsEach/fliclib-linux-dist/releases 80 | sudo tar -zxvf fliclib-linux.tar.gz 81 | 82 | Check your architecture with uname -m and cd into the corresponding directory. 83 | 84 | sudo ./daemon -l -f flic.sqlite3 85 | 86 | This should be kept active 87 | 88 | Open a new SSH session 89 | 90 | cd flic/armv6l/fliclib-cpp 91 | 92 | sudo hciconfig hci0 up 93 | 94 | ./flic 95 | 96 | If this is the first time you connect your Flic, do the following: 97 | 98 | startScan 99 | press your button and wait for button discovered message 100 | stopScan 101 | 102 | If you already have connected your Flic, it should show up if you enter: 103 | 104 | list 105 | 106 | press and hold the button for 8 sec and then enter 107 | 108 | connect __MAC__ 109 | 110 | This may take a few tries as my button never glows in public mode. You know it was successfull when is says connected and start track button presses.. 111 | 112 | exit flic with ctrl-C 113 | 114 | install Flic Python lib: 115 | 116 | cd ~/flic/armv6l/fliclib-cpp/ffi/python/flic/dist 117 | sudo easy_install flic-0.1-py2.7.egg 118 | 119 | Test: 120 | start your AdaFruit WebIDE 121 | 122 | create a new python file 123 | 124 | copy and paste the attached test into your file and execute 125 | main.txt 126 | 127 | Test by pressing the button 128 | 129 | Have fun! 130 | -------------------------------------------------------------------------------- /samples/c++/.gitignore: -------------------------------------------------------------------------------- 1 | /main 2 | /main.o 3 | -------------------------------------------------------------------------------- /samples/c++/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean 2 | 3 | CC= g++ 4 | CXXFLAGS+= -std=c++11 5 | LDLIBS= -lflic 6 | 7 | all: main 8 | 9 | main: main.o 10 | 11 | clean: 12 | rm -rf main main.o 13 | -------------------------------------------------------------------------------- /samples/c++/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "flic.hpp" 4 | 5 | class ButtonEventListener : public flic::client::button::ButtonEventListener { 6 | public: 7 | virtual std::string getHash() override { 8 | return "main"; 9 | } 10 | 11 | virtual void onButtonUpOrDown(const std::string& deviceId, 12 | const bool& queued, 13 | const int& timeDiff, 14 | const bool& isUp, 15 | const bool& isDown) override { 16 | std::cout << deviceId << (isUp ? " up" : " down") << std::endl; 17 | } 18 | }; 19 | 20 | class ButtonListener : public flic::client::manager::ButtonListener { 21 | private: 22 | std::shared_ptr manager; 23 | public: 24 | ButtonListener(std::shared_ptr manager) : 25 | manager(manager) { 26 | 27 | } 28 | 29 | virtual std::string getHash() override { 30 | return "main"; 31 | } 32 | 33 | virtual void onButtonDiscover(const std::string& deviceId) override { 34 | auto button = manager->getButton(deviceId); 35 | button->addButtonEventListener(std::shared_ptr(new ButtonEventListener())); 36 | } 37 | }; 38 | 39 | int main() { 40 | flic::client::Client client; 41 | 42 | try { 43 | client.start([&client] () { 44 | std::cout << "Initialized" << std::endl; 45 | auto manager = client.getManager(); 46 | 47 | for (auto& button : manager->getButtons()) { 48 | button->addButtonEventListener(std::shared_ptr(new ButtonEventListener())); 49 | } 50 | }, [&client] (const bool& resumable) { 51 | std::cout << "Uninitialized" << std::endl; 52 | }); 53 | client.run(); 54 | } catch (flic::client::ClientNetworkException& e) { 55 | std::cerr << e.what() << std::endl; 56 | } catch (std::exception& e) { 57 | std::cerr << e.what() << std::endl; 58 | } catch (...) { 59 | std::cerr << "Unknown exception" << std::endl; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /samples/java/.gitignore: -------------------------------------------------------------------------------- 1 | *.class -------------------------------------------------------------------------------- /samples/java/Main.java: -------------------------------------------------------------------------------- 1 | import io.flic.lib.client.*; 2 | 3 | public class Main { 4 | private static void addButtonEventListener(Button button) { 5 | button.addButtonEventListener(new ButtonEventListener() { 6 | @Override 7 | public void onButtonUpOrDown(String deviceId, 8 | boolean queued, 9 | int timeDiff, 10 | boolean isUp, 11 | boolean isDown) { 12 | System.out.println(deviceId + (isUp ? " up" : " down")); 13 | } 14 | }); 15 | } 16 | 17 | public static void main(String [] args) { 18 | System.load("/usr/lib/libflicjava.so"); 19 | final Client client = new Client(); 20 | 21 | CallbackVoid initializedCallback = new CallbackVoid() { 22 | public void callback() { 23 | System.out.println("Initialized"); 24 | final Manager manager = client.getManager(); 25 | try { 26 | ButtonVector buttons = manager.getButtons(); 27 | for (int i = 0; i < buttons.size(); ++i) { 28 | Button button = buttons.get(i); 29 | addButtonEventListener(button); 30 | } 31 | manager.addButtonListener(new ButtonListener() { 32 | @Override 33 | public String getHash() { 34 | return "main"; 35 | } 36 | 37 | @Override 38 | public void onButtonDiscover(String deviceId) { 39 | Button button = manager.getButton(deviceId); 40 | addButtonEventListener(button); 41 | } 42 | 43 | @Override 44 | public void onButtonForgotten(String deviceId) { 45 | System.out.println("onButtonForgotten"); 46 | } 47 | }); 48 | } catch (Exception e) { 49 | System.out.println(e); 50 | } 51 | } 52 | }; 53 | CallbackBool uninitializedCallback = new CallbackBool() { 54 | public void callback(boolean recoverable) { 55 | System.out.println("Uninitialized"); 56 | } 57 | }; 58 | client.start(initializedCallback.getCallback(), 59 | uninitializedCallback.getCallback()); 60 | client.run(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /samples/java/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean 2 | 3 | all: 4 | javac Main.java 5 | 6 | clean: 7 | rm *.class 8 | -------------------------------------------------------------------------------- /samples/python/IFTTT.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from flic import flic 3 | 4 | 5 | makerkey = "Enter your key here" 6 | 7 | client = flic.Client() 8 | 9 | class ButtonEventListener(flic.ButtonEventListener): 10 | 11 | def getHash(self): 12 | return "main" 13 | 14 | def onButtonSingleOrDoubleClickOrHold(self, deviceId, queued, timeDiff, isSingleClick, isDoubleClick, isHold): 15 | manager = client.getManager() 16 | button = manager.getButton(deviceId) 17 | if isSingleClick : 18 | r = requests.post("https://maker.ifttt.com/trigger/FlicSingle/with/key/"+makerkey , json={}) 19 | print r.status_code 20 | elif isDoubleClick : 21 | r = requests.post("https://maker.ifttt.com/trigger/FlicDouble/with/key/"+makerkey , json={}) 22 | print r.status_code 23 | else : 24 | r = requests.post("https://maker.ifttt.com/trigger/FlicHold/with/key/"+makerkey , json={}) 25 | print r.status_code 26 | 27 | 28 | buttonEventListener = ButtonEventListener() 29 | 30 | def addButtonEventListener(button): 31 | button.addButtonEventListener(buttonEventListener) 32 | 33 | class ButtonListener(flic.ButtonListener): 34 | def getHash(self): 35 | return "main" 36 | 37 | def onButtonDiscover(self, button): 38 | addButtonEventListener(button) 39 | 40 | buttonListener = ButtonListener() 41 | 42 | class InitializedCallback(flic.CallbackVoid): 43 | def callback(self): 44 | print("Initialized") 45 | manager = client.getManager() 46 | buttons = manager.getButtons() 47 | try: 48 | for button in buttons: 49 | addButtonEventListener(button) 50 | manager.addButtonListener(buttonListener) 51 | except: 52 | pass 53 | 54 | class UninitializedCallback(flic.CallbackBool): 55 | def callback(self): 56 | print("Uninitialized") 57 | 58 | 59 | init = InitializedCallback() 60 | uninit = UninitializedCallback() 61 | client.start(init.getCallback(), uninit.getCallback()) 62 | 63 | client.run() 64 | 65 | -------------------------------------------------------------------------------- /samples/python/main.py: -------------------------------------------------------------------------------- 1 | from flic import flic 2 | 3 | client = flic.Client() 4 | 5 | class ButtonEventListener(flic.ButtonEventListener): 6 | 7 | def getHash(self): 8 | return "main" 9 | 10 | def onButtonUpOrDown(self, deviceId, queued, timeDiff, isUp, isDown): 11 | manager = client.getManager() 12 | button = manager.getButton(deviceId) 13 | print(button.getDeviceId() + (" up" if isUp else " down")) 14 | 15 | buttonEventListener = ButtonEventListener() 16 | 17 | def addButtonEventListener(button): 18 | button.addButtonEventListener(buttonEventListener) 19 | 20 | class ButtonListener(flic.ButtonListener): 21 | def getHash(self): 22 | return "main" 23 | 24 | def onButtonDiscover(self, button): 25 | addButtonEventListener(button) 26 | 27 | buttonListener = ButtonListener() 28 | 29 | class InitializedCallback(flic.CallbackVoid): 30 | def callback(self): 31 | print("Initialized") 32 | manager = client.getManager() 33 | buttons = manager.getButtons() 34 | try: 35 | for button in buttons: 36 | addButtonEventListener(button) 37 | manager.addButtonListener(buttonListener) 38 | except: 39 | pass 40 | 41 | class UninitializedCallback(flic.CallbackBool): 42 | def callback(self): 43 | print("Uninitialized") 44 | 45 | 46 | init = InitializedCallback() 47 | uninit = UninitializedCallback() 48 | client.start(init.getCallback(), uninit.getCallback()) 49 | 50 | client.run() 51 | --------------------------------------------------------------------------------