Skip to content

Commit 4b0d806

Browse files
fix 3D layer toggles and support demo pin readings
1 parent aa9ae91 commit 4b0d806

File tree

12 files changed

+85
-16
lines changed

12 files changed

+85
-16
lines changed

frontend/demo/lua_runner/__tests__/index_test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,15 @@ describe("runDemoLuaCode()", () => {
14101410
expect(error).not.toHaveBeenCalled();
14111411
expect(console.log).toHaveBeenCalledWith("0");
14121412
expect(info).not.toHaveBeenCalled();
1413+
expect(initSave).toHaveBeenCalledWith("SensorReading", {
1414+
pin: 5,
1415+
mode: 1,
1416+
x: 1,
1417+
y: 2,
1418+
z: 0,
1419+
value: 0,
1420+
read_at: expect.any(String),
1421+
});
14131422
});
14141423

14151424
it("runs move_relative", () => {

frontend/demo/lua_runner/actions.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,18 @@ export const expandActions = (
235235
setCurrent(homeTarget);
236236
});
237237
break;
238+
case "read_pin":
239+
const pin = action.args[0] as number;
240+
expanded.push({
241+
type: "sensor_reading",
242+
args: [
243+
pin,
244+
current.x,
245+
current.y,
246+
current.z,
247+
],
248+
});
249+
break;
238250
default:
239251
expanded.push(action);
240252
break;
@@ -361,6 +373,18 @@ export const runActions = (
361373
payload: action.args[0] as number,
362374
});
363375
};
376+
case "sensor_reading":
377+
return () => {
378+
store.dispatch(initSave("SensorReading", {
379+
pin: action.args[0] as number,
380+
mode: 1,
381+
x: action.args[1] as number,
382+
y: action.args[2] as number,
383+
z: action.args[3] as number,
384+
value: random(0, 1024),
385+
read_at: (new Date()).toISOString(),
386+
}) as unknown as UnknownAction);
387+
};
364388
case "write_pin":
365389
const pin = action.args[0] as number;
366390
const mode = action.args[1] as string;

frontend/demo/lua_runner/interfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export interface Action {
88
| "move"
99
| "_move"
1010
| "toggle_pin"
11+
| "read_pin"
12+
| "sensor_reading"
1113
| "emergency_lock"
1214
| "emergency_unlock"
1315
| "find_home"

frontend/demo/lua_runner/run.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ export const runLua =
536536
jsToLua(L, toolMounted ? 0 : 1);
537537
return 1;
538538
}
539+
actions.push({ type: "read_pin", args: [pin] });
539540
jsToLua(L, 0);
540541
return 1;
541542
});

frontend/devices/__tests__/actions_test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,13 +610,24 @@ describe("pinToggle()", () => {
610610
});
611611

612612
describe("readPin()", () => {
613+
afterEach(() => {
614+
localStorage.removeItem("myBotIs");
615+
});
616+
613617
it("calls readPin", async () => {
614618
await actions.readPin(1, "label", 0);
615619
expect(mockDevice.current.readPin).toHaveBeenCalledWith({
616620
pin_number: 1, label: "label", pin_mode: 0,
617621
});
618622
expect(success).not.toHaveBeenCalled();
619623
});
624+
625+
it("reads demo account pin", async () => {
626+
localStorage.setItem("myBotIs", "online");
627+
await actions.readPin(1, "label", 0);
628+
expect(mockDevice.current.readPin).not.toHaveBeenCalled();
629+
expect(runDemoLuaCode).toHaveBeenCalledWith("read_pin(1)");
630+
});
620631
});
621632

622633
describe("writePin()", () => {

frontend/devices/actions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,10 @@ export function readPin(
447447
pin_number: number, label: string, pin_mode: ALLOWED_PIN_MODES,
448448
) {
449449
const noun = t("Read pin");
450-
maybeNoop();
450+
if (forceOnline()) {
451+
runDemoLuaCode(`read_pin(${pin_number})`);
452+
return;
453+
}
451454
return getDevice()
452455
.readPin({ pin_number, label, pin_mode })
453456
.then(maybeNoop, commandErr(noun));

frontend/farm_designer/map/legend/garden_map_legend.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ interface LayerTogglesProps extends GardenMapLegendProps { }
129129
const LayerToggles = (props: LayerTogglesProps) => {
130130
const { toggle, getConfigValue, dispatch, firmwareConfig } = props;
131131
const subMenuProps = { dispatch, getConfigValue, firmwareConfig };
132-
const only2DClass =
133-
getConfigValue(BooleanSetting.three_d_garden) ? "disabled" : "";
132+
const is3D = getConfigValue(BooleanSetting.three_d_garden);
133+
const only2DClass = is3D ? "disabled" : "";
134134
return <div className="toggle-buttons">
135135
<LayerToggle
136136
settingName={BooleanSetting.show_plants}
@@ -144,12 +144,12 @@ const LayerToggles = (props: LayerTogglesProps) => {
144144
value={props.showPoints}
145145
label={DeviceSetting.showPoints}
146146
onClick={toggle(BooleanSetting.show_points)} />
147-
<LayerToggle
148-
className={only2DClass}
149-
settingName={BooleanSetting.show_soil_interpolation_map}
150-
value={props.showSoilInterpolationMap}
151-
label={DeviceSetting.showSoil}
152-
onClick={toggle(BooleanSetting.show_soil_interpolation_map)} />
147+
{!is3D &&
148+
<LayerToggle
149+
settingName={BooleanSetting.show_soil_interpolation_map}
150+
value={props.showSoilInterpolationMap}
151+
label={DeviceSetting.showSoil}
152+
onClick={toggle(BooleanSetting.show_soil_interpolation_map)} />}
153153
<LayerToggle
154154
settingName={BooleanSetting.show_weeds}
155155
value={props.showWeeds}
@@ -205,7 +205,6 @@ const LayerToggles = (props: LayerTogglesProps) => {
205205
onClick={toggle(BooleanSetting.show_zones)} />
206206
{props.hasSensorReadings &&
207207
<LayerToggle
208-
className={only2DClass}
209208
settingName={BooleanSetting.show_sensor_readings}
210209
value={props.showSensorReadings}
211210
label={DeviceSetting.showReadings}

frontend/three_d_garden/bed/__tests__/bed_test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ describe("<Bed />", () => {
104104
getZ: () => 0,
105105
showMoistureMap: true,
106106
sensorReadings: [],
107+
showMoistureReadings: true,
107108
});
108109

109110
it("renders bed", () => {

frontend/three_d_garden/bed/bed.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export interface BedProps {
110110
soilSurfaceGeometry: BufferGeometry;
111111
moistureSurfaceGeometry: BufferGeometry;
112112
showMoistureMap: boolean;
113+
showMoistureReadings: boolean;
113114
sensorReadings: TaggedSensorReading[];
114115
}
115116

@@ -249,9 +250,11 @@ export const Bed = (props: BedProps) => {
249250
<MoistureTexture
250251
config={props.config}
251252
sensorReadings={props.sensorReadings}
253+
showMoistureReadings={props.showMoistureReadings}
252254
geometry={props.moistureSurfaceGeometry} />, [
253255
props.config,
254256
props.sensorReadings,
257+
props.showMoistureReadings,
255258
props.moistureSurfaceGeometry,
256259
]);
257260

@@ -393,6 +396,7 @@ export const Bed = (props: BedProps) => {
393396
<MoistureSurface
394397
geometry={props.moistureSurfaceGeometry}
395398
sensorReadings={props.sensorReadings}
399+
showMoistureReadings={true}
396400
config={props.config}
397401
color={"black"}
398402
radius={50}

frontend/three_d_garden/garden/__tests__/moisture_texture_test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@ describe("<MoistureTexture />", () => {
1010
config: clone(INITIAL),
1111
geometry: new BufferGeometry(),
1212
sensorReadings: [],
13+
showMoistureReadings: true,
1314
});
1415

1516
it("renders", () => {
1617
const { container } = render(<MoistureTexture {...fakeProps()} />);
1718
expect(container).toContainHTML("render-texture");
1819
});
20+
21+
it("renders without readings", () => {
22+
const p = fakeProps();
23+
p.showMoistureReadings = false;
24+
const { container } = render(<MoistureTexture {...p} />);
25+
expect(container).toContainHTML("render-texture");
26+
});
1927
});

0 commit comments

Comments
 (0)