From 51cccb4eb48d5bf929ded157bb69de1a930e697a Mon Sep 17 00:00:00 2001 From: mtg137 Date: Thu, 31 Mar 2022 02:34:27 -0400 Subject: [PATCH 1/5] switch to gravity sensor --- app/widgets/StabilityTracker/index.js | 40 +++++++++++++++++---------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/app/widgets/StabilityTracker/index.js b/app/widgets/StabilityTracker/index.js index c842191eb..6a31b4ba6 100644 --- a/app/widgets/StabilityTracker/index.js +++ b/app/widgets/StabilityTracker/index.js @@ -1,9 +1,9 @@ import React, { useState, useEffect, useRef, useCallback } from 'react'; import PropTypes from 'prop-types'; -import { View, Text, StyleSheet } from 'react-native'; +import { View, Text, StyleSheet, RecyclerViewBackedScrollViewBase } from 'react-native'; import { connect } from 'react-redux'; import Svg, { Circle, Rect } from 'react-native-svg'; -import { magnetometer } from "react-native-sensors"; +import { gravity } from "react-native-sensors"; import { useAnimationFrame } from '../../services/hooks'; import { showToast } from '../../state/app/app.thunks'; @@ -104,7 +104,7 @@ const StabilityTrackerScreen = ({ onChange, config, isCurrent, maxLambda, applet const trialNumber = useRef(0); const responses = useRef([]); const controlBar = useRef(true); - const magnRef = useRef(), baseAcc = useRef(); + const gravRef = useRef(), baseGrav = useRef(), prevGrav = useRef(); const lastCrashTime = useRef(0); const lambdaLimit = configObj.phaseType == 'challenge-phase' ? 0 : maxLambda * 0.3; @@ -127,22 +127,32 @@ const StabilityTrackerScreen = ({ onChange, config, isCurrent, maxLambda, applet useEffect(() => { if (configObj.userInputType == 'gyroscope') { if (moving) { - magnRef.current = magnetometer.subscribe(({ x, y, z }) => { - let yRot = Math.asin(x / Math.sqrt(x*x + z*z)); - let xRot = Math.asin(y / Math.sqrt(y*y + z*z + x*x)); + gravRef.current = gravity.subscribe(({ x, y, z, timestamp }) => { + let xRot = Math.asin(z / Math.sqrt(y*y + z*z + x*x)); + let yRot = -Math.asin(x / Math.sqrt(x*x + z*z)); if (y < 0) { - yRot += Math.PI; + xRot = Math.PI - xRot; } - if (!baseAcc.current) { - baseAcc.current = [xRot, yRot]; + if (!baseGrav.current) { + baseGrav.current = [xRot, yRot]; } else { - const x = center + (yRot - baseAcc.current[1]) / configObj.maxRad * panelRadius; - const y = center - (xRot - baseAcc.current[0]) / configObj.maxRad * panelRadius; + if (Math.abs(prevGrav.current[0] - xRot) > Math.PI) { + if (prevGrav.current[0] > xRot) { + xRot += 2 * Math.PI; + } else { + xRot -= 2 * Math.PI; + } + } + + const x = center + (yRot - baseGrav.current[1]) / configObj.maxRad * panelRadius; + const y = center - (xRot - baseGrav.current[0]) / configObj.maxRad * panelRadius; userPos.current = [x, y]; } + + prevGrav.current = [xRot, yRot]; }, (e) => { showToast({ text: e, @@ -153,15 +163,15 @@ const StabilityTrackerScreen = ({ onChange, config, isCurrent, maxLambda, applet configObj.userInputType = 'touch' }) } else { - if (magnRef.current) { - magnRef.current.unsubscribe(); + if (gravRef.current) { + gravRef.current.unsubscribe(); } } } return () => { - if (magnRef.current) { - magnRef.current.unsubscribe(); + if (gravRef.current) { + gravRef.current.unsubscribe(); } } }, [moving]) From bf53a42e90417cf2f0c104792c4b71f953451726 Mon Sep 17 00:00:00 2001 From: mtg137 Date: Tue, 5 Apr 2022 02:00:49 -0400 Subject: [PATCH 2/5] switch to orientation sensor --- app/widgets/StabilityTracker/index.js | 39 ++++++++------------------- package.json | 2 +- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/app/widgets/StabilityTracker/index.js b/app/widgets/StabilityTracker/index.js index 6a31b4ba6..95ea9b5fb 100644 --- a/app/widgets/StabilityTracker/index.js +++ b/app/widgets/StabilityTracker/index.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import { View, Text, StyleSheet, RecyclerViewBackedScrollViewBase } from 'react-native'; import { connect } from 'react-redux'; import Svg, { Circle, Rect } from 'react-native-svg'; -import { gravity } from "react-native-sensors"; +import { orientation } from "react-native-sensors"; import { useAnimationFrame } from '../../services/hooks'; import { showToast } from '../../state/app/app.thunks'; @@ -104,7 +104,7 @@ const StabilityTrackerScreen = ({ onChange, config, isCurrent, maxLambda, applet const trialNumber = useRef(0); const responses = useRef([]); const controlBar = useRef(true); - const gravRef = useRef(), baseGrav = useRef(), prevGrav = useRef(); + const oriRef = useRef(), baseOri = useRef(); const lastCrashTime = useRef(0); const lambdaLimit = configObj.phaseType == 'challenge-phase' ? 0 : maxLambda * 0.3; @@ -127,32 +127,15 @@ const StabilityTrackerScreen = ({ onChange, config, isCurrent, maxLambda, applet useEffect(() => { if (configObj.userInputType == 'gyroscope') { if (moving) { - gravRef.current = gravity.subscribe(({ x, y, z, timestamp }) => { - let xRot = Math.asin(z / Math.sqrt(y*y + z*z + x*x)); - let yRot = -Math.asin(x / Math.sqrt(x*x + z*z)); - - if (y < 0) { - xRot = Math.PI - xRot; - } - - if (!baseGrav.current) { - baseGrav.current = [xRot, yRot]; + oriRef.current = orientation.subscribe(({ pitch, yaw, roll, timestamp }) => { + if (!baseOri.current) { + baseOri.current = [roll, pitch]; } else { - if (Math.abs(prevGrav.current[0] - xRot) > Math.PI) { - if (prevGrav.current[0] > xRot) { - xRot += 2 * Math.PI; - } else { - xRot -= 2 * Math.PI; - } - } - - const x = center + (yRot - baseGrav.current[1]) / configObj.maxRad * panelRadius; - const y = center - (xRot - baseGrav.current[0]) / configObj.maxRad * panelRadius; + const x = center + (roll - baseOri.current[0]) / configObj.maxRad * panelRadius; + const y = center - (pitch - baseOri.current[1]) / configObj.maxRad * panelRadius; userPos.current = [x, y]; } - - prevGrav.current = [xRot, yRot]; }, (e) => { showToast({ text: e, @@ -163,15 +146,15 @@ const StabilityTrackerScreen = ({ onChange, config, isCurrent, maxLambda, applet configObj.userInputType = 'touch' }) } else { - if (gravRef.current) { - gravRef.current.unsubscribe(); + if (oriRef.current) { + oriRef.current.unsubscribe(); } } } return () => { - if (gravRef.current) { - gravRef.current.unsubscribe(); + if (oriRef.current) { + oriRef.current.unsubscribe(); } } }, [moving]) diff --git a/package.json b/package.json index 7d34e88fc..659d74a73 100644 --- a/package.json +++ b/package.json @@ -114,7 +114,7 @@ "react-native-router-flux": "4.2.0", "react-native-screens": "^1.0.0-alpha.23", "react-native-select-dropdown": "^1.0.9", - "react-native-sensors": "^7.3.3", + "react-native-sensors": "^7.3.5", "react-native-slider": "^0.11.0", "react-native-sound-player": "^0.10.5", "react-native-svg": "^12.1.0", From 1449dff5d680db8b1cc1b1828c620aaf07cb0c73 Mon Sep 17 00:00:00 2001 From: mtg137 Date: Tue, 5 Apr 2022 02:20:53 -0400 Subject: [PATCH 3/5] fix submitting cumulative response --- app/state/responses/responses.thunks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/state/responses/responses.thunks.js b/app/state/responses/responses.thunks.js index 4110b4ca8..45e5555f0 100644 --- a/app/state/responses/responses.thunks.js +++ b/app/state/responses/responses.thunks.js @@ -539,7 +539,7 @@ export const completeResponse = (isTimeout = false) => (dispatch, getState) => { const { cumActivities, nonHiddenCumActivities } = evaluateCumulatives(inProgressResponse.responses, activity); const cumulativeActivities = state.activities.cumulativeActivities; - if (cumActivities.length || nonHiddenCumActivities.length) { + if (cumActivities.length || nonHiddenCumActivities && nonHiddenCumActivities.length) { let archieved = [...cumulativeActivities[applet.id].archieved]; let available = [...cumulativeActivities[applet.id].available]; const activityId = activity.id.split('/').pop(); From 47158e8b072d868b2fb09db53e35ce2393af80e4 Mon Sep 17 00:00:00 2001 From: mtg137 Date: Tue, 5 Apr 2022 09:30:10 -0400 Subject: [PATCH 4/5] update version --- CHANGELOG.md | 3 +++ README.md | 2 +- android/app/build.gradle | 4 ++-- ios/MDCApp/Info.plist | 4 ++-- package.json | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2f5ab6c3..803212cc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.19.12] - 2022-04-5 +- Fix tilt version of stability tracker + ## [0.19.11] - 2022-04-4 - Fix an issue with variable name - Fix an issue with Sthare Report button diff --git a/README.md b/README.md index 278a65954..b04196dff 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# MindLogger 0.19.11 +# MindLogger 0.19.12 _Note: v0.1 is deprecated as of June 12, 2019._ diff --git a/android/app/build.gradle b/android/app/build.gradle index 80cc6bbe8..96ea53ed2 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -130,8 +130,8 @@ android { applicationId "lab.childmindinstitute.data" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 524 - versionName "0.19.11" + versionCode 525 + versionName "0.19.12" missingDimensionStrategy 'react-native-camera', 'general' multiDexEnabled true } diff --git a/ios/MDCApp/Info.plist b/ios/MDCApp/Info.plist index 69decea8f..0c3ef6247 100644 --- a/ios/MDCApp/Info.plist +++ b/ios/MDCApp/Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.19.11 + 0.19.12 CFBundleSignature ???? CFBundleVersion - 524 + 525 ITSAppUsesNonExemptEncryption LSApplicationCategoryType diff --git a/package.json b/package.json index 659d74a73..d689da78d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "MindLogger", - "version": "0.19.11", + "version": "0.19.12", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", From 10673e2941b2e1cebe8cec23431784165a709d30 Mon Sep 17 00:00:00 2001 From: mtg137 Date: Thu, 7 Apr 2022 14:08:08 -0400 Subject: [PATCH 5/5] fix moving direction for stimulus disc --- app/widgets/StabilityTracker/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/widgets/StabilityTracker/index.js b/app/widgets/StabilityTracker/index.js index 95ea9b5fb..7f477be6c 100644 --- a/app/widgets/StabilityTracker/index.js +++ b/app/widgets/StabilityTracker/index.js @@ -1,6 +1,6 @@ import React, { useState, useEffect, useRef, useCallback } from 'react'; import PropTypes from 'prop-types'; -import { View, Text, StyleSheet, RecyclerViewBackedScrollViewBase } from 'react-native'; +import { View, Text, StyleSheet, Platform } from 'react-native'; import { connect } from 'react-redux'; import Svg, { Circle, Rect } from 'react-native-svg'; import { orientation } from "react-native-sensors"; @@ -132,7 +132,8 @@ const StabilityTrackerScreen = ({ onChange, config, isCurrent, maxLambda, applet baseOri.current = [roll, pitch]; } else { const x = center + (roll - baseOri.current[0]) / configObj.maxRad * panelRadius; - const y = center - (pitch - baseOri.current[1]) / configObj.maxRad * panelRadius; + + const y = center + (Platform.OS == 'ios' ? 1 : -1) * (pitch - baseOri.current[1]) / configObj.maxRad * panelRadius; userPos.current = [x, y]; }