diff --git a/client/src/js/actions/index.js b/client/src/js/actions/index.js index ffa1cb6..2439c87 100644 --- a/client/src/js/actions/index.js +++ b/client/src/js/actions/index.js @@ -74,12 +74,12 @@ const actions = { log: (value) => console.log(value), system: null, - preprogram: { - start: function start({ blocks, motors }) { - console.log(motors); - - const waitFor = (ms) => new Promise(r => setTimeout(r, ms)); + start1: ({ blocks, motors, preprogram }) => (state) => { + const waitFor = (ms) => new Promise(r => { + state.sid = setTimeout(r, ms); + return state.sid; + }); const asyncForEach = async (array, callback) => { for (let index = 0; index < array.length; index++) { // eslint-disable-next-line no-await-in-loop @@ -102,28 +102,30 @@ const actions = { }; const run = async () => { await asyncForEach(blocks, async (block) => { - const iid = setInterval(() => { + state.iid = setInterval(() => { console.log('[pre-program]:', block.speed, motors); motors.set(block.speed, convertToArrOfDirections(block.direction)); }, 100); await waitFor(block.time * 1000); - clearInterval(iid); + clearInterval(state.iid); }); - motors.stop(); + preprogram.stop({ motors }); console.log('[pre-program]: Done'); }; + console.log(run()); + // return { running: !state.running }; + }, - run(); + stop: ({ motors }) => state => { + motors.stop(); + clearInterval(state.iid); + clearTimeout(state.sid); + return { running: !state.running }; }, - add: () => state => ({ - next: { - direction: 'fw', - speed: 0, - time: 0, - step: 1, - }, - blocks: state.blocks.concat(state.next), - }), + setRunningFlag: () => state => ({ running: !state.running }), + + add: () => state => ({ blocks: state.blocks.concat(state.next) }), + remove: (index) => state => ({ blocks: state.blocks.filter(block => state.blocks.indexOf(block) !== index) }), next: { setDirection: dir => state => ({ direction: dir }), diff --git a/client/src/js/core/index.js b/client/src/js/core/index.js index 3c2960c..77ac63d 100644 --- a/client/src/js/core/index.js +++ b/client/src/js/core/index.js @@ -26,7 +26,7 @@ const core = (actions) => { keyboard(actions.motors); - telemetry(actions, sockets); + // telemetry(actions, sockets); }; export default core; diff --git a/client/src/js/core/stream.js b/client/src/js/core/stream.js index e7919c0..fbf8f07 100644 --- a/client/src/js/core/stream.js +++ b/client/src/js/core/stream.js @@ -1,4 +1,4 @@ -export const Stream = function() { +export const Stream = function () { this.protocol = location.protocol === "https:" ? "wss:" : "ws:"; this.hostname = document.location.hostname; this.port = 8090; diff --git a/client/src/js/core/system.js b/client/src/js/core/system.js index 094ca87..3bed7a8 100644 --- a/client/src/js/core/system.js +++ b/client/src/js/core/system.js @@ -7,3 +7,9 @@ System.prototype.shutdown = function shutdown() { this.sockets.io.emit('shutdown'); } }; + +System.prototype.reboot = function reboot() { + if (this.sockets.io.connected) { + this.sockets.io.emit('reboot'); + } +}; diff --git a/client/src/js/state/index.js b/client/src/js/state/index.js index e0e8238..304df52 100644 --- a/client/src/js/state/index.js +++ b/client/src/js/state/index.js @@ -41,15 +41,13 @@ const state = { default: {}, preprogram: { + running: false, + iid: 0, + sid: 0, blocks: [{ direction: 'fw', - speed: 70, - time: 3, - }, - { - direction: 'l', - speed: 20, - time: 15, + speed: 1, + time: 1, }], next: { direction: 'fw', diff --git a/client/src/js/view/components/settings/index.js b/client/src/js/view/components/settings/index.js index dffaf44..7e6ef46 100644 --- a/client/src/js/view/components/settings/index.js +++ b/client/src/js/view/components/settings/index.js @@ -15,7 +15,7 @@ export const Settings = ({ state, actions }) =>
actions.settings.setVisibleCategory('manipulator')}>Manipulator
actions.settings.setVisibleCategory('preprogram')}>Pre-program
{/*
  • actions.settings.setVisibleCategory('debug')}>Debug
  • */} -
    actions.settings.setVisibleCategory('clupi')}>Close-UP Imager
    +
    actions.settings.setVisibleCategory('clupi')}>Experimental
    actions.settings.setVisibleCategory('about')}>About
    diff --git a/client/src/js/view/components/settings/settings-about.js b/client/src/js/view/components/settings/settings-about.js index 81578fc..9a51f11 100644 --- a/client/src/js/view/components/settings/settings-about.js +++ b/client/src/js/view/components/settings/settings-about.js @@ -10,6 +10,14 @@ export const SettingsAbout = ({ state }) => state.system_info.video_devices.map(device => ()) } +

    + Please refer to docs.turtlerover.com to know more about the control options and the Rover maintenance. + Feel free to contact us if you have any issue. We're constantly improving the UI, but it's still a long way to go. + We'd love to have you participate in the project and get any feedback! +

    + Turtle Team + contact@turtlerover.com + www.turtlerover.com ; const VideoDevice = ({ device }) => diff --git a/client/src/js/view/components/settings/settings-general.js b/client/src/js/view/components/settings/settings-general.js index ba590ee..7751431 100644 --- a/client/src/js/view/components/settings/settings-general.js +++ b/client/src/js/view/components/settings/settings-general.js @@ -4,4 +4,6 @@ import { ButtonHold } from '../elements/button-hold'; export const SettingsGeneral = ({ actions }) =>
    actions.system.shutdown()} /> + actions.system.reboot()} /> + actions.stream.start()} />
    ; diff --git a/client/src/js/view/components/settings/settings-manipulator.js b/client/src/js/view/components/settings/settings-manipulator.js index b06fb85..200a709 100644 --- a/client/src/js/view/components/settings/settings-manipulator.js +++ b/client/src/js/view/components/settings/settings-manipulator.js @@ -4,6 +4,9 @@ import { Button } from '../elements/button'; export const SettingsManipulator = ({ state, actions }) =>
    +

    + Please refer to docs.turtlerover.com to find proper range values for your addon. +

    inc={actions.manipulator.gripper.incMin} dec={actions.manipulator.gripper.decMin} /> -
    ; diff --git a/client/src/js/view/components/settings/settings-preprogram.js b/client/src/js/view/components/settings/settings-preprogram.js index fda5e66..7fa9afa 100644 --- a/client/src/js/view/components/settings/settings-preprogram.js +++ b/client/src/js/view/components/settings/settings-preprogram.js @@ -7,8 +7,7 @@ export const SettingsPreprogram = ({ actions, state }) =>
    - {/*
    { @@ -33,5 +32,20 @@ export const SettingsPreprogram = ({ actions, state }) => const startMotors = function startMotors(state, actions) { const blocks = state.preprogram.blocks; const motors = actions.motors; - actions.preprogram.start({ blocks, motors }); + const preprogram = actions.preprogram; + actions.preprogram.setRunningFlag(); + actions.preprogram.start1({ blocks, motors, preprogram }); +}; + +const stopMotors = function stopMotors(state, actions) { + const motors = actions.motors; + actions.preprogram.stop({ motors }); +}; + +const StartStopButton = ({ state, actions }) => { + if (state.preprogram.running) { + return