{"id":13742029,"url":"https://github.com/AlexGustafsson/fuse-motion","last_synced_at":"2025-05-08T22:33:04.833Z","repository":{"id":83002361,"uuid":"65994566","full_name":"AlexGustafsson/fuse-motion","owner":"AlexGustafsson","description":"iOS accelerometer, gyroscope and magnetometer readings for Fuse","archived":true,"fork":false,"pushed_at":"2017-07-10T15:35:18.000Z","size":1808,"stargazers_count":14,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-15T12:37:21.734Z","etag":null,"topics":["accelerometer","fuse","fusetools","gyroscope","magnetometer","motion","sensors","uno"],"latest_commit_sha":null,"homepage":null,"language":"Objective-C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlexGustafsson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2016-08-18T12:17:57.000Z","updated_at":"2023-01-28T08:20:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"b1a65753-40a1-4bc3-9923-4194179a1a79","html_url":"https://github.com/AlexGustafsson/fuse-motion","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/AlexGustafsson%2Ffuse-motion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexGustafsson%2Ffuse-motion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexGustafsson%2Ffuse-motion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexGustafsson%2Ffuse-motion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexGustafsson","download_url":"https://codeload.github.com/AlexGustafsson/fuse-motion/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253158692,"owners_count":21863359,"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":["accelerometer","fuse","fusetools","gyroscope","magnetometer","motion","sensors","uno"],"created_at":"2024-08-03T04:01:05.561Z","updated_at":"2025-05-08T22:33:04.011Z","avatar_url":"https://github.com/AlexGustafsson.png","language":"Objective-C++","funding_links":[],"categories":["Open Source"],"sub_categories":[],"readme":"Motion  - iOS accelerometer, gyroscope, magnetometer readings and more for Fuse\n======\n\n\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"App preview\" src=\"https://github.com/AlexGustafsson/fuse-motion/raw/master/assets/preview.gif\"\u003e\n\u003cp\u003e\n\nMotion is an easy to use integration of all iOS's sensors reflecting motion, made for [Fuse](https://fusetools.com). It enables easy creation of compasses, motion trackers, activity trackers and so on.\n\n# Quickstart\n\u003ca name=\"quickstart\"\u003e\u003c/a\u003e\n\n#### Install Motion\nRight now a manual installation is required. Requires Fuse 0.30.0 or above.\n\nCopy the following files to your project:\n- Motion.js\n- Motion.hh\n- Motion.mm\n- Motion.uno\n\nUpdate your `.unoproj` to reflect the following changes:\n```json\n\"Packages\": [\n  \"Fuse\",\n  \"FuseJS\",\n  \"Fuse.Scripting\"\n],\n\"Includes\": [\n  \"Motion.hh:ObjCHeader:iOS\",\n  \"Motion.mm:ObjCSource:iOS\",\n  \"*\"\n],\n\"iOS\": {\n  \"PList\": {\n    \"NSMotionUsageDescription\": \"Motion access motivation\"\n  }\n}\n```\n\n_note, the user is only asked to allow motion usage when subscribing to `activity`_\n\n#### Implementing Motion\n\nSubscribe to sensor updates:\n```javascript\n\n\u003cJavaScript\u003e\n  var Motion = require(\"Motion\");\n  Motion.Subscribe(\"accelerometer magnetometer gyroscope motion activity\", 0.2);\n\u003c/JavaScript\u003e\n```\n_Optional:_\nInclude Motion in your App's `MainView.ux` to export all measurements as observables:\n```xml\n\u003cJavaScript File=\"MotionJS.js\"/\u003e\n```\n\n# Table of contents\n\n[Quickstart](#quickstart)\u003cbr/\u003e\n[Using Motion](#how)\u003cbr/\u003e\n[Examples](#examples)\u003cbr/\u003e\n[Contributing](#contributing)\u003cbr/\u003e\n[Disclaimer](#disclaimer)\n\n# Using Motion\n\u003ca name=\"how\"\u003e\u003c/a\u003e\n\n~~Note: API is due to change, stay updated. Until then, *use the source, Luke*.~~\u003cbr /\u003e\nThe API is pretty final. If you've got any feedback, please make your voice heard.\n\n#### Implementing observables\n\nInclude Motion in your App's `MainView.ux`:\n```xml\n\u003cJavaScript File=\"MotionJS.js\"/\u003e\n```\n\nAccess the values using the same names as the JS API. See the \"values\" example for all available values.\n\n```xml\n\u003cText Value=\"{magnetometer.magneticField.x}\" FontSize=\"20\"/\u003e\n```\n\n#### Subscribing to updates\nTo save resources when they are not needed, subscription is used to only grab values from the device when needed. Subscribe only to the events you need and when you need them.\n\n```javascript\n\n\u003cJavaScript\u003e\n  //Global module with a static instance - can be used anywhere\n  var Motion = require(\"Motion\");\n\n  //Subscribe to changes from all available sensors with an interval of 0.2 seconds\n  Motion.Subscribe(\"accelerometer magnetometer gyroscope motion activity\", 0.2);\n\u003c/JavaScript\u003e\n```\n\nTo release resources when they are no longer needed, unsubscribe to updates whenever possible.\n\n```javascript\n  //Unsubscribe to all changes\n  Motion.Unsubscribe(\"accelerometer magnetometer gyroscope motion activity\");\n```\n\nSee the [Apple webpage](https://developer.apple.com/library/content/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/motion_event_basics/motion_event_basics.html) on selecting a proper interval.\n\n| Interval (s)  | Usage  |\n|---|---|\n| 0.1 - 0.05  | Suitable for determining a device’s current orientation vector.  |\n| 0.03 – 0.017  | Suitable for games and other apps that use the accelerometer for real-time user input.  |\n| 0.014 – 0.01  |  Suitable for apps that need to detect high-frequency motion. For example, you might use this interval to detect the user hitting the device or shaking it very quickly. |\n\n#### Listening for updates\nTo retrieve the actual values, events are used.\n\n~~**Note**: In their current state, Fuse `NativeEvents` don't allow for more than one \"listener\". As such you can only subscribe to the events once. Subscribing again will override any previous subscriptions. Since Motion already listens to the updates in order to share the values to UX, listening for the updates will disable that feature.~~\u003cbr /\u003e\nFuse 0.30.0 came with an overhauled event system. As such proper events are now implemented in Motion.\n\n```javascript\n\u003cJavaScript\u003e\n  Motion.on(\"accelerometerChanged\", function(values){\n    values = JSON.parse(values);\n\n    if(!values.error)\n      console.log(\"Accelerometer values:\", values);\n  });\n\n  Motion.on(\"gyroscopeChanged\", function(values){\n    values = JSON.parse(values);\n\n    if(!values.error)\n      console.log(\"Gyroscope values:\", values);\n  });\n\n  Motion.on(\"motionChanged\", function(values){\n    values = JSON.parse(values);\n\n    if(!values.error)\n      console.log(\"Motion values:\", values);\n  });\n\n  Motion.on(\"magnetometerChanged\", function(values){\n    values = JSON.parse(values);\n\n    if(!values.error)\n      console.log(\"Magnetometer values:\", values);\n  });\n\n  Motion.on(\"activityChanged\", function(values){\n    values = JSON.parse(values);\n\n    if(!values.error)\n      console.log(\"Activity values:\", values);\n  });\n\u003c/JavaScript\u003e\n```\n\n#### Accessing values directly in UX\nMotion exposes several values directly to UX Markup.\n\n~~**Note**: In their current state, Fuse `NativeEvents` don't allow for more than one \"listener\". As such you can only subscribe to the events once. Subscribing again will override any previous subscriptions. Since Motion already listens to the updates in order to share the values to UX, listening for the updates will disable this feature.~~\u003cbr /\u003e\nFuse 0.30.0 came with an overhauled event system. As such proper events are now implemented in Motion.\n\nThe following values are exposed:\n\n```javascript\nvar accelerometer = Observable({\n  acceleration: {x: 0, y: 0, z: 0}\n}),\ngyroscope = Observable({\n  rotationRate: {x: 0, y: 0, z: 0}\n}),\nmagnetometer = Observable({\n  magneticField: {x: 0, y: 0, z: 0}\n}),\nmotion = Observable({\n  attitude: {yaw: 0, pitch: 0, roll: 0},\n  rotationRate: {x: 0, y: 0, z: 0},\n  gravity: {x: 0, y: 0, z: 0},\n  magneticField: {accuracy: -1, x: 0, y: 0, z: 0},\n  userAcceleration: {x: 0, y: 0, z: 0}\n}),\nactivity = Observable({\n  unknown: true,\n  stationary: false,\n  walking: false,\n  running: false,\n  automotive: false,\n  cycling: false,\n  confidence: \"low\"\n});\n```\n\nIf you are unsure how to use values exposed from javascript through `Observables` check out the [Fuse documentation](https://www.fusetools.com/docs/fusejs/observable) and [this example](https://github.com/alexgustafsson/fuse-motion/tree/master/examples/values).\n\n# Examples\n\u003ca name=\"examples\"\u003e\u003c/a\u003e\n\n#### Demo app\nWhen built, this project will act as an app showcasing all the examples.\n\n#### [Values](https://github.com/alexgustafsson/fuse-motion/tree/master/examples/values)\nDisplays all available values.\n\n#### [Gravity](https://github.com/alexgustafsson/fuse-motion/tree/master/examples/gravity)\nUses the magnetometer to apply a gravity effect to a dropshadow.\n\n#### [Shock](https://github.com/alexgustafsson/fuse-motion/tree/master/examples/shock)\nUses the accelerometer to detect when the phone is hit.\n\n#### [Swipe](https://github.com/alexgustafsson/fuse-motion/tree/master/examples/swipe)\nNo more phone thumb from \"swiping right\"! Train your wrist by using the gyroscope to enable a swipe like feature.\n\n# Contributing\n\u003ca name=\"contributing\"\u003e\u003c/a\u003e\n\nAny help with the project is more than welcome. This is my first take on Uno and Objective-C so some things might not be following best practices or be incorrectly implemented all together.\n\n#### TODO:\n\n- Integrate Motion in UX via `animators`\n- ~~Implement `activity updates`~~\n- ~~[Make multiple event listeners possible](https://www.fusetools.com/community/forums/howto_discussions/multiple_listeners_to_nativeevents?page=1)~~\n- ~~Make API more developer-friendly~~\n- ~~Improve documentation~~\n- Add more examples\n- Make compatible with [fusepm](https://github.com/bolav/fusepm)\n\n# Disclaimer\n\u003ca name=\"disclaimer\"\u003e\u003c/a\u003e\n\n_Although the project is very capable, it is not built with production in mind. Therefore there might be complications when trying to use Motion for large-scale projects meant for the public. Motion was created to easily integrate sensor readings on iOS and as such it might not promote best practices nor be performant._\n\n_Built with Fuse 0.30.0 (build 8529) and Xcode Version 8.1 (8B62), tested on iPhone 6 iOS 10.2 and 10.2.1. Tested with Fuse 1.1.0 (build 13808)._\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAlexGustafsson%2Ffuse-motion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAlexGustafsson%2Ffuse-motion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAlexGustafsson%2Ffuse-motion/lists"}