Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wake locks #88

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions feedingwebapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"styled-components": "^5.3.9",
"web-vitals": "^2.1.4",
"webpack": "^5.82.1",
"nosleep.js" : "^0.12.0",
"zustand": "^4.0.0-rc.1"
},
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion feedingwebapp/src/Pages/Home/MealStates/BiteSelection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { View } from 'react-native'
// PropTypes is used to validate that the used props are in fact passed to this
// Component
import PropTypes from 'prop-types'

// Local Imports
import '../Home.css'
import { useROS, createROSActionClient, callROSAction, destroyActionClient } from '../../../ros/ros_helpers'
Expand Down
9 changes: 8 additions & 1 deletion feedingwebapp/src/Pages/Home/MealStates/RobotMotion.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Button from 'react-bootstrap/Button'
import { View } from 'react-native'
// PropTypes is used to validate that the used props are in fact passed to this Component
import PropTypes from 'prop-types'
// External Library Imports
import NoSleep from 'nosleep.js'
// Local Imports
import { useROS, createROSActionClient, callROSAction, cancelROSAction, destroyActionClient } from '../../../ros/ros_helpers'
import Footer from '../../Footer/Footer'
Expand Down Expand Up @@ -69,6 +71,8 @@ const RobotMotion = (props) => {
let waitingTextFontSize = isPortrait ? '4.5vh' : '9vh'
// Motion text font size
let motionTextFontSize = isPortrait ? '3vh' : '6vh'
// NoSleep object creation
let noSleep = useMemo(() => new NoSleep(), [])

/**
* Create the ROS Action Client. This is re-created every time props.mealState
Expand Down Expand Up @@ -182,15 +186,18 @@ const RobotMotion = (props) => {
*/
useEffect(() => {
callRobotMotionAction(feedbackCallback, responseCallback)
noSleep.enable() // keep the screen on!
/**
* In practice, because the values passed in in the second argument of
* useEffect will not change on re-renders, this return statement will
* only be called when the component unmounts.
*/
return () => {
destroyActionClient(robotMotionAction)
noSleep.disable() // let the screen turn off.
setActionStatus({ actionStatus: ROS_ACTION_STATUS_ABORT })
}
}, [callRobotMotionAction, robotMotionAction, feedbackCallback, responseCallback])
}, [callRobotMotionAction, robotMotionAction, feedbackCallback, responseCallback, noSleep])

/**
* Callback function for when the resume button is pressed. It calls the
Expand Down