{"id":13481035,"url":"https://github.com/vishal-android-freak/HC-SR04-AndroidThings-Library","last_synced_at":"2025-03-27T11:31:31.229Z","repository":{"id":75872575,"uuid":"76754416","full_name":"vishal-android-freak/HC-SR04-AndroidThings-Library","owner":"vishal-android-freak","description":"HC-SR04 Ultrasonic UserSensor library for Android Things","archived":false,"fork":false,"pushed_at":"2018-10-09T14:04:12.000Z","size":99,"stargazers_count":16,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-01T17:24:32.326Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vishal-android-freak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2016-12-18T00:14:40.000Z","updated_at":"2022-04-28T09:26:04.000Z","dependencies_parsed_at":"2023-02-24T18:15:41.475Z","dependency_job_id":null,"html_url":"https://github.com/vishal-android-freak/HC-SR04-AndroidThings-Library","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vishal-android-freak%2FHC-SR04-AndroidThings-Library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vishal-android-freak%2FHC-SR04-AndroidThings-Library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vishal-android-freak%2FHC-SR04-AndroidThings-Library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vishal-android-freak%2FHC-SR04-AndroidThings-Library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vishal-android-freak","download_url":"https://codeload.github.com/vishal-android-freak/HC-SR04-AndroidThings-Library/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222239499,"owners_count":16953961,"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:47.931Z","updated_at":"2024-10-30T14:31:13.803Z","avatar_url":"https://github.com/vishal-android-freak.png","language":"Java","funding_links":[],"categories":["Useful links"],"sub_categories":["Drivers"],"readme":"# HC-SR04-AndroidThings-Library\nHC-SR04 Ultrasonic UserSensor library for Android Things\n\n![](HC-SR04-Ultrasonic-Sensor.jpg?raw=true \"Sensor\")\n\nThis is WIP. Expect things to work in a different way or not to work at all. Pull requests for betterments and fixes are welcome.\n\n##How to use the library\n\n1. Clone the repository `git clone https://github.com/vishal-android-freak/HC-SR04-AndroidThings-Library.git`\n2. Clone the sample project template `https://github.com/androidthings/new-project-template.git` for android things or create your own project in Android studio following https://developer.android.com/things.\n3. In Android Studio, go to File \u003e New \u003e Import Module.\n4. Browse for the **HC-SR04-AndroidThings-Library** cloned folder.\n5. In the 'Module name' section type `:hcsr04`.\n6. Right click on the **app** folder and select 'Open Module Settings'.\n7. Go to the 'Dependencies' section and click on the '+' and select 'Module dependency'.\n8. Select ':hcsr04' and click Ok. Done!\n\n##Sample Usage\n\n```java\n\nimport vaf.vishal.Hcsr04;\n\n.....\n\n// Access the environmental sensor directly:\n\nHcsr04 hcsr04;\n\ntry {\n    hcsr04 = new Hcsr04(\"BCM23\", \"BCM25\");\n} catch(IOException e) {\n  // couldn't configure the device...\n}\n\n//Read ultrasonic sensor values in centimeters.\n\ntry {\n    float[] values = hcsr04.getProximityDistance();\n    float distanceInCm = values[0];\n} catch(IOException e) {\n  //error reading values.\n}\n\n//close the ultrasonic sensor after finished.\ntry {\n    hcsr04.close();\n} catch(IOException e) {\n  //error closing sensor.\n}\n\n```\n\nIf you need to read sensor values continuously, you can register the Hcsr04 with the system and listen for sensor values using the [Sensor APIs](https://developer.android.com/guide/topics/sensors/sensors_overview.html)\n\n```java\n\nSensorManager mSensorManager = getSystemService(Context.SENSOR_SERVICE);\nSensorEventListener mListener = ...;\nHcsr04UltrasonicDriver mSensorDriver;\n\nmSensorManager.registerDynamicSensorCallback(new SensorManager.DynamicSensorCallback() {\n    @Override\n    public void onDynamicSensorConnected(Sensor sensor) {\n        if (sensor.getType() == Sensor.TYPE_PROXIMITY) {\n            mSensorManager.registerListener(mListener, sensor,\n                    SensorManager.SENSOR_DELAY_NORMAL);\n        }\n    }\n});\n\ntry {\n    mSensorDriver = new Hcsr04UltrasonicDriver(\"BCM23\", \"BCM25\");\n    mSensorDriver.register();\n} catch (IOException e) {\n    // Error configuring sensor\n}\n\n// Unregister and close the driver when finished:\n\nmSensorManager.unregisterListener(mListener);\nmSensorDriver.unregister();\ntry {\n    mSensorDriver.close();\n} catch (IOException e) {\n    // error closing sensor\n}\n\n```\n\n#License\n\nMIT License\n\nCopyright (c) 2017 Vishal Dubey\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvishal-android-freak%2FHC-SR04-AndroidThings-Library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvishal-android-freak%2FHC-SR04-AndroidThings-Library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvishal-android-freak%2FHC-SR04-AndroidThings-Library/lists"}