{"id":13481056,"url":"https://github.com/Nilhcem/mpr121-androidthings","last_synced_at":"2025-03-27T11:31:41.520Z","repository":{"id":141783974,"uuid":"82445280","full_name":"Nilhcem/mpr121-androidthings","owner":"Nilhcem","description":"MPR121 driver for Android Things","archived":false,"fork":false,"pushed_at":"2018-05-10T15:56:56.000Z","size":286,"stargazers_count":11,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-30T14:43:13.929Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nilhcem.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-02-19T08:23:55.000Z","updated_at":"2018-10-28T16:20:27.000Z","dependencies_parsed_at":"2023-05-13T06:45:50.722Z","dependency_job_id":null,"html_url":"https://github.com/Nilhcem/mpr121-androidthings","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nilhcem%2Fmpr121-androidthings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nilhcem%2Fmpr121-androidthings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nilhcem%2Fmpr121-androidthings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nilhcem%2Fmpr121-androidthings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nilhcem","download_url":"https://codeload.github.com/Nilhcem/mpr121-androidthings/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245836196,"owners_count":20680332,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:00:48.179Z","updated_at":"2025-03-27T11:31:41.142Z","avatar_url":"https://github.com/Nilhcem.png","language":"Java","funding_links":[],"categories":["Useful links"],"sub_categories":["Drivers"],"readme":"# MPR121 capacitive touch sensor driver for Android Things\n\nA port of the [Adafruit MPR121][adafruit-mpr121] Arduino library for Android Things.\n\n\n## Download\n\n```groovy\ndependencies {\n    compile 'com.nilhcem.androidthings:driver-mpr121:0.0.3'\n}\n```\n\n## Usage\n\n### Registering with the system\n\n```java\nint[] keyCodes = new int[] { KevEvent.KEYCODE_1, KevEvent.KEYCODE_2, ... KevEvent.KEYCODE_12 };\n\nMpr121InputDriver inputDriver;\n\nHandlerThread handlerThread = new HandlerThread(\"Mpr121Thread\");\nhandlerThread.start();\nhandler = new Handler(handlerThread.getLooper());\n\ntry {\n    inputDriver = new Mpr121InputDriver(i2cBusName, handler, keyCodes);\n    mInputDriver.register();\n} catch (IOException e) {\n    // couldn't configure the input driver...\n}\n\n// Override key event callbacks in your Activity:\n@Override\npublic boolean onKeyDown(int keyCode, KeyEvent event) {\n    switch (keyCode) {\n        case KeyEvent.KEYCODE_1:\n            doSomethingAwesome();\n            return true; // handle keypress\n        // other cases...\n    }\n    return super.onKeyDown(keyCode, event);\n}\n\n// Unregister and close the input driver when finished:\nmInputDriver.unregister;\ntry {\n    mInputDriver.close();\n} catch (IOException e) {\n    // error closing input driver\n}\n```\n\nAlso, don't forget to add the required permission to your app's manifest file:\n\n```xml\n\u003cuses-permission android:name=\"com.google.android.things.permission.MANAGE_INPUT_DRIVERS\" /\u003e\n```\n\n### Calling the driver manually\n\nYou can call the `Mpr121` class directly if you prefer not to receive events from the system:\n\n```java\n// Instantiate the driver\nMpr121 peripheralDevice = new Mpr121(i2cName);\n\n// Get the current state of each electrode\nint data = peripheralDevice.getTouched();\n\n// Loop to check the state of these electrodes\n// Ideally, place this code in a thread to check continuously and add a listener when a state changes\nboolean[] inputStatus = new boolean[Mpr121.NB_ELECTRODES];\nfor (int i = 0; i \u003c Mpr121.NB_ELECTRODES; i++) {\n    if ((data \u0026 (1 \u003c\u003c i)) != 0) {\n        if (!inputStatus[i]) {\n            Log.d(TAG, \"#\" + i + \" touched\");\n            inputStatus[i] = true;\n        }\n    } else {\n        if (inputStatus[i]) {\n            Log.d(TAG, \"#\" + i + \" released\");\n            inputStatus[i] = false;\n        }\n    }\n}\n\n// Finally, close the driver\nperipheralDevice.close();\n```\n\n## Sample project\n\nThe sample project uses a passive buzzer to play a sound when an electrode is touched.\n\n### Schematic:\n\n![schematic][]\n\nIf you prefer playing a real sound file instead (e.g.: wav/mp3), use the `SoundPoolHelper` instead of the `PassiveBuzzerHelper` in the `MainActivity`, and place your assets in `res/raw` (from: `res/raw/sound0.mp3` to: `res/raw/sound11.mp3`)\n\n[adafruit-mpr121]: https://github.com/adafruit/Adafruit_MPR121/\n[schematic]: https://raw.githubusercontent.com/Nilhcem/mpr121-androidthings/master/assets/schematic.png\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNilhcem%2Fmpr121-androidthings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNilhcem%2Fmpr121-androidthings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNilhcem%2Fmpr121-androidthings/lists"}