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 }) =>
+ 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 }) =>+ Please refer to docs.turtlerover.com to find proper range values for your addon. +