Skip to content

Commit bfb5ca1

Browse files
author
stsdc
committed
Merge branch 'dev'
2 parents 9908f4a + 601fd97 commit bfb5ca1

File tree

13 files changed

+74
-35
lines changed

13 files changed

+74
-35
lines changed

client/src/js/actions/index.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ const actions = {
7474
log: (value) => console.log(value),
7575

7676
system: null,
77-
7877
preprogram: {
79-
start: function start({ blocks, motors }) {
80-
console.log(motors);
81-
82-
const waitFor = (ms) => new Promise(r => setTimeout(r, ms));
78+
start1: ({ blocks, motors, preprogram }) => (state) => {
79+
const waitFor = (ms) => new Promise(r => {
80+
state.sid = setTimeout(r, ms);
81+
return state.sid;
82+
});
8383
const asyncForEach = async (array, callback) => {
8484
for (let index = 0; index < array.length; index++) {
8585
// eslint-disable-next-line no-await-in-loop
@@ -102,28 +102,30 @@ const actions = {
102102
};
103103
const run = async () => {
104104
await asyncForEach(blocks, async (block) => {
105-
const iid = setInterval(() => {
105+
state.iid = setInterval(() => {
106106
console.log('[pre-program]:', block.speed, motors);
107107
motors.set(block.speed, convertToArrOfDirections(block.direction));
108108
}, 100);
109109
await waitFor(block.time * 1000);
110-
clearInterval(iid);
110+
clearInterval(state.iid);
111111
});
112-
motors.stop();
112+
preprogram.stop({ motors });
113113
console.log('[pre-program]: Done');
114114
};
115+
console.log(run());
116+
// return { running: !state.running };
117+
},
115118

116-
run();
119+
stop: ({ motors }) => state => {
120+
motors.stop();
121+
clearInterval(state.iid);
122+
clearTimeout(state.sid);
123+
return { running: !state.running };
117124
},
118-
add: () => state => ({
119-
next: {
120-
direction: 'fw',
121-
speed: 0,
122-
time: 0,
123-
step: 1,
124-
},
125-
blocks: state.blocks.concat(state.next),
126-
}),
125+
setRunningFlag: () => state => ({ running: !state.running }),
126+
127+
add: () => state => ({ blocks: state.blocks.concat(state.next) }),
128+
127129
remove: (index) => state => ({ blocks: state.blocks.filter(block => state.blocks.indexOf(block) !== index) }),
128130
next: {
129131
setDirection: dir => state => ({ direction: dir }),

client/src/js/core/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const core = (actions) => {
2626

2727
keyboard(actions.motors);
2828

29-
telemetry(actions, sockets);
29+
// telemetry(actions, sockets);
3030
};
3131

3232
export default core;

client/src/js/core/stream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const Stream = function() {
1+
export const Stream = function () {
22
this.protocol = location.protocol === "https:" ? "wss:" : "ws:";
33
this.hostname = document.location.hostname;
44
this.port = 8090;

client/src/js/core/system.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ System.prototype.shutdown = function shutdown() {
77
this.sockets.io.emit('shutdown');
88
}
99
};
10+
11+
System.prototype.reboot = function reboot() {
12+
if (this.sockets.io.connected) {
13+
this.sockets.io.emit('reboot');
14+
}
15+
};

client/src/js/state/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ const state = {
4141

4242
default: {},
4343
preprogram: {
44+
running: false,
45+
iid: 0,
46+
sid: 0,
4447
blocks: [{
4548
direction: 'fw',
46-
speed: 70,
47-
time: 3,
48-
},
49-
{
50-
direction: 'l',
51-
speed: 20,
52-
time: 15,
49+
speed: 1,
50+
time: 1,
5351
}],
5452
next: {
5553
direction: 'fw',

client/src/js/view/components/settings/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const Settings = ({ state, actions }) =>
1515
<div role='button' class={categoryClass(state.settings.category, 'manipulator')} onmousedown={() => actions.settings.setVisibleCategory('manipulator')}>Manipulator</div>
1616
<div role='button' class={categoryClass(state.settings.category, 'preprogram')} onmousedown={() => actions.settings.setVisibleCategory('preprogram')}>Pre-program</div>
1717
{/* <li class={categoryClass(state.settings.category, 'debug')} onmousedown={() => actions.settings.setVisibleCategory('debug')}>Debug</li> */}
18-
<div role='button' class={categoryClass(state.settings.category, 'clupi')} onmousedown={() => actions.settings.setVisibleCategory('clupi')}>Close-UP Imager</div>
18+
<div role='button' class={categoryClass(state.settings.category, 'clupi')} onmousedown={() => actions.settings.setVisibleCategory('clupi')}>Experimental</div>
1919
<div role='button' class={categoryClass(state.settings.category, 'about')} onmousedown={() => actions.settings.setVisibleCategory('about')}>About</div>
2020
</div>
2121
<SettingsContent state={state} actions={actions} />

client/src/js/view/components/settings/settings-about.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ export const SettingsAbout = ({ state }) =>
1010
state.system_info.video_devices.map(device => (<VideoDevice device={device} />))
1111
}
1212
</div>
13+
<p>
14+
Please refer to docs.turtlerover.com to know more about the control options and the Rover maintenance.
15+
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.
16+
We'd love to have you participate in the project and get any feedback!
17+
</p>
18+
<span>Turtle Team</span>
19+
<span>[email protected]</span>
20+
<span>www.turtlerover.com</span>
1321
</div>;
1422

1523
const VideoDevice = ({ device }) =>

client/src/js/view/components/settings/settings-general.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ import { ButtonHold } from '../elements/button-hold';
44
export const SettingsGeneral = ({ actions }) =>
55
<div class="settings_content">
66
<ButtonHold text='SHUTDOWN' setValue={() => actions.system.shutdown()} />
7+
<ButtonHold text='REBOOT' setValue={() => actions.system.reboot()} />
8+
<ButtonHold text='Restart stream' setValue={() => actions.stream.start()} />
79
</div>;

client/src/js/view/components/settings/settings-manipulator.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { Button } from '../elements/button';
44

55
export const SettingsManipulator = ({ state, actions }) =>
66
<div class="settings_content">
7+
<p>
8+
Please refer to docs.turtlerover.com to find proper range values for your addon.
9+
</p>
710
<InputNumber
811
label='Axis 1 max value'
912
value={state.manipulator.axis1.max}
@@ -46,6 +49,6 @@ export const SettingsManipulator = ({ state, actions }) =>
4649
inc={actions.manipulator.gripper.incMin}
4750
dec={actions.manipulator.gripper.decMin} />
4851

49-
<Button text='Reset' setValue={() => actions.manipulator.reset(state.default.manipulator)} />
52+
<Button text='Reset' value={state.default.manipulator} onclick={actions.manipulator.reset} />
5053

5154
</div>;

client/src/js/view/components/settings/settings-preprogram.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ export const SettingsPreprogram = ({ actions, state }) =>
77
<div class="settings_content">
88
<div class="preprogram_content">
99
<div>
10-
{/* <Button text='Start' setValue={() => console.log(actions.motors)} /> */}
11-
<Button text='Start' onclick={() => startMotors(state, actions)} />
10+
<StartStopButton state={state} actions={actions} />
1211
</div>
1312
<div class="preprogram_content__blocks">
1413
{
@@ -33,5 +32,20 @@ export const SettingsPreprogram = ({ actions, state }) =>
3332
const startMotors = function startMotors(state, actions) {
3433
const blocks = state.preprogram.blocks;
3534
const motors = actions.motors;
36-
actions.preprogram.start({ blocks, motors });
35+
const preprogram = actions.preprogram;
36+
actions.preprogram.setRunningFlag();
37+
actions.preprogram.start1({ blocks, motors, preprogram });
38+
};
39+
40+
const stopMotors = function stopMotors(state, actions) {
41+
const motors = actions.motors;
42+
actions.preprogram.stop({ motors });
43+
};
44+
45+
const StartStopButton = ({ state, actions }) => {
46+
if (state.preprogram.running) {
47+
return <Button text='Stop' onclick={() => stopMotors(state, actions)} />;
48+
} else {
49+
return <Button text='Start' onclick={() => startMotors(state, actions)} />;
50+
}
3751
};

0 commit comments

Comments
 (0)