Skip to content

Commit

Permalink
feat: add RTC blocks (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverben authored Jul 10, 2024
1 parent 3e276a4 commit dbbd6b2
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@fortawesome/free-solid-svg-icons": "^6.5.2",
"@leaphy-robotics/avrdude-webassembly": "^1.6.1",
"@leaphy-robotics/dfu-util-wasm": "^1.0.2",
"@leaphy-robotics/leaphy-blocks": "^3.1.1",
"@leaphy-robotics/leaphy-blocks": "3.2.0",
"@leaphy-robotics/picotool-wasm": "1.0.3",
"@leaphy-robotics/webusb-ftdi": "1.0.1",
"@sentry/svelte": "8.0.0-beta.5",
Expand Down
2 changes: 1 addition & 1 deletion src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ body {
box-sizing: content-box;
}

.blocklyFlyout {
.injectionDiv > .blocklyFlyout {
transform: translate(80px, 0) !important;
}

Expand Down
45 changes: 36 additions & 9 deletions src/lib/components/core/popups/popups/SerialMonitor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import {
faArrowDown,
faBars,
faChartLine,
faClock,
faTrash,
faX,
} from "@fortawesome/free-solid-svg-icons";
import { format } from "date-fns";
import { tick } from "svelte";
import Fa from "svelte-fa";
import { _ } from "svelte-i18n";
import { get } from "svelte/store";
import Windowed from "../Windowed.svelte";
Expand All @@ -22,6 +24,7 @@ enum Mode {
}
let mode = $state(Mode.TEXT);
let input = $state<HTMLInputElement>();
let element = $state<HTMLDivElement>();
function formatDate(date: Date) {
Expand Down Expand Up @@ -76,6 +79,11 @@ function switchMode() {
if (mode === Mode.CHART) mode = Mode.TEXT;
else mode = Mode.CHART;
}
function insertDate() {
value += format(new Date(), "yyMMddiHHmmss");
if (input) input.focus();
}
</script>

{#snippet actions()}
Expand Down Expand Up @@ -106,14 +114,20 @@ function switchMode() {
<Chart />
{/if}
{#if $port}
<form onsubmit={send}>
<TextInput
placeholder={$_("SERIAL_PROMPT_PLACEHOLDER")}
bind:value
mode={"primary"}
rounded={false}
/>
</form>
<div class="send">
<div class="suggestions">
<Button mode={"accent"} name={format(new Date(), 'yyMMddiHHmmss')} icon={faClock} inline onclick={insertDate} />
</div>
<form onsubmit={send}>
<TextInput
placeholder={$_("SERIAL_PROMPT_PLACEHOLDER")}
bind:value
bind:input
mode={"primary"}
rounded={false}
/>
</form>
</div>
{/if}
{/snippet}

Expand Down Expand Up @@ -157,4 +171,17 @@ function switchMode() {
font-size: 1.1em;
font-weight: bold;
}
.send {
display: flex;
flex-direction: column;
background: var(--primary);
color: var(--on-primary);
}
.suggestions {
display: flex;
gap: 10px;
padding: 10px 10px 5px;
}
</style>
7 changes: 7 additions & 0 deletions src/lib/components/ui/Button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface Props {
mode: "primary" | "secondary" | "outlined" | "accent";
bold?: boolean;
type?: "button" | "submit";
inline?: boolean;
}
const {
Expand All @@ -24,6 +25,7 @@ const {
bold,
icon,
disabled,
inline = false,
type = "button",
}: Props = $props();
Expand Down Expand Up @@ -53,6 +55,7 @@ function onContext() {
class:outlined={mode === "outlined"}
class:accent={mode === "accent"}
class:bold
class:inline
>
{#if icon}
{#if typeof icon === "string"}
Expand All @@ -76,6 +79,10 @@ function onContext() {
padding: 10px 15px;
}
.inline {
padding: 5px 10px;
}
.icon {
height: 1em;
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/ui/TextInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface Props {
focus?: boolean;
required?: boolean;
type?: string;
input: HTMLInputElement;
}
let {
Expand All @@ -19,9 +20,9 @@ let {
focus,
required,
type = "text",
input = $bindable(),
}: Props = $props();
let input: HTMLInputElement;
onMount(() => {
if (focus) input.focus();
});
Expand Down
71 changes: 71 additions & 0 deletions src/lib/domain/blockly/toolbox.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import robotGroups from "$domain/robots.groups";
import { RobotType } from "$domain/robots.types";
import { format } from "date-fns";

function number(value: number) {
return {
Expand Down Expand Up @@ -83,6 +84,64 @@ export default [
{
type: "leaphy_i2c_gesture",
},
{
type: "leaphy_i2c_rtc_get",
},
{
type: "leaphy_i2c_rtc_format",
extraState: [
{
type: "item",
item: "day",
fmt: "2-digit",
},
{
type: "text",
value: "/",
},
{
type: "item",
item: "month",
fmt: "2-digit",
},
{
type: "text",
value: "/",
},
{
type: "item",
item: "year",
fmt: "full",
},
{
type: "text",
value: " ",
},
{
type: "item",
item: "hour",
fmt: "2-digit",
},
{
type: "text",
value: ":",
},
{
type: "item",
item: "minute",
fmt: "2-digit",
},
{
type: "text",
value: ":",
},
{
type: "item",
item: "second",
fmt: "2-digit",
},
],
},
],
[
{
Expand Down Expand Up @@ -311,6 +370,12 @@ export default [
type: "i2c_use_channel",
robots: robotGroups.L_NANO_ALL,
},
{
type: "leaphy_i2c_rtc_set",
inputs: {
VALUE: text(format(new Date(), "yyMMddiHHmmss")),
},
},
],
],
},
Expand Down Expand Up @@ -611,6 +676,12 @@ export default [
CHECK: text("a"),
},
},
{
type: "text_to_double",
inputs: {
VALUE: text("123"),
},
},
],
],
},
Expand Down
1 change: 1 addition & 0 deletions src/lib/domain/robots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const DEFAULT_LIBRARIES = [
"Adafruit BMP280 Library",
"TM1637",
"LedControl",
"DS3231",
];

interface BaseRobot {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,10 @@
resolved "https://registry.yarnpkg.com/@leaphy-robotics/dfu-util-wasm/-/dfu-util-wasm-1.0.2.tgz#29afcc01266655e1c7b5da0eeceb0ead48c86fd7"
integrity sha512-lvS+tJFO049b4ERYKX0HcoUtnQv76A1z9sZrAvbs7s3bvdMW0BObKmktZeJ7emcp3lU/+OJWsD2h0EY5rnkiNg==

"@leaphy-robotics/leaphy-blocks@^3.1.1":
version "3.1.1"
resolved "https://registry.yarnpkg.com/@leaphy-robotics/leaphy-blocks/-/leaphy-blocks-3.1.1.tgz#7f83203b481a2dacbf9017ab8d7def15d9e80054"
integrity sha512-nbT/sY070Wgq+0RS6//q1s7MFR+2qhkh0z42+wm37ygTjw6s0o4Sm005gA/4DBiwiHI1azdtPwvKAlsFdAvfAg==
"@leaphy-robotics/leaphy-blocks@3.2.0":
version "3.2.0"
resolved "https://registry.yarnpkg.com/@leaphy-robotics/leaphy-blocks/-/leaphy-blocks-3.2.0.tgz#49cfa2425afe08aafa0e9a8539536ef98ba1af05"
integrity sha512-LmvsrcGBQgq6H69T9tWSYK1sejwFaLoDQbprVOuWfoI2GRsKYcEq5+vzSz3JitmVEMigeBn4uNrQzueIaYZ4iw==
dependencies:
blockly "^10.4.3"

Expand Down

0 comments on commit dbbd6b2

Please sign in to comment.