Skip to content

Commit

Permalink
Merge pull request #247 from microbit-foundation/output-gesture-type-…
Browse files Browse the repository at this point in the history
…fixing

Output gesture type fixing
  • Loading branch information
JonAlexandra authored Jul 3, 2023
2 parents d1a30a7 + 380c7a7 commit 467da82
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
14 changes: 5 additions & 9 deletions src/components/OutputGesture.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
triggerFunc();
});
$: triggerOutputPin(requiredConfidenceLevel, currentConfidenceLevel, triggered);
$: if (shouldTrigger(requiredConfidenceLevel, currentConfidenceLevel, triggered)) {
$: triggerOutputPin(triggered);
$: if (shouldTrigger(triggered)) {
triggerComponents();
playSound();
}
Expand All @@ -69,7 +69,7 @@
onUserInteraction();
}
function triggerOutputPin(requiredLevel, currentLevel, oldTriggered) {
function triggerOutputPin(oldTriggered: boolean) {
if (!Microbits.isOutputReady()) {
return;
}
Expand Down Expand Up @@ -122,14 +122,10 @@
const refreshAfterChange = () => {
Microbits.resetIOPins();
triggerOutputPin(requiredConfidenceLevel, currentConfidenceLevel, false);
triggerOutputPin(false);
};
const shouldTrigger = (
requiredConfidence: number,
confidence: number,
oldTriggered: boolean,
) => {
const shouldTrigger = (oldTriggered: boolean) => {
triggered = isConfidenceOverThreshold as boolean;
if (!triggered) return false;
if (!$settings.automaticClassification) return true;
Expand Down
26 changes: 18 additions & 8 deletions src/components/output/PinSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@
import { t } from '../../i18n.js';
import MBSpecs from '../../script/microbit-interfacing/MBSpecs.js';
export let onPinSelect: (pin: MBSpecs.UsableIOPin) => void;
export let onTurnOnTimeSelect: ({
turnOnState: PinTurnOnState,
turnOnTime: number,
export let onTurnOnTimeSelect: (turnOnArgs: {
turnOnState: PinTurnOnState;
turnOnTime: number;
}) => void;
export let turnOnTime: number;
export let turnOnState: PinTurnOnState;
export let selectedPin: string;
export let selectedPin: MBSpecs.UsableIOPin;
let selectedTurnOnState = turnOnState;
let turnOnTimeInSeconds = turnOnTime / 1000;
const onPinSelected = (pin: MBSpecs.UsableIOPin) => {
onPinSelect(pin);
const onPinSelected = (pin: MBSpecs.IOPin) => {
if (!includes(StaticConfiguration.supportedPins, pin)) {
return;
}
onPinSelect(pin as MBSpecs.UsableIOPin);
};
const onTurnOnStateSelect = () => {
Expand All @@ -29,12 +32,19 @@
};
const largePins: MBSpecs.IOPin[] = [0, 1, 2, '3V', 'GND'];
// Hacky way to check if a value is included in an array since typescript
// has made a very poor decision on how array.includes() is typed
function includes<T>(array: T[], value: unknown): boolean {
return array.includes(value as T);
}
</script>

<!-- svelte-ignore a11y-click-events-have-key-events -->
<GestureTilePart>
<div class="flex flex-row">
{#each MBSpecs.IO_PIN_LAYOUT as val, index}
{#if StaticConfiguration.supportedPins.includes(val)}
{#each MBSpecs.IO_PIN_LAYOUT as val}
{#if includes(StaticConfiguration.supportedPins, val)}
<!-- These are pins we support, make them selectable and yellow -->
{#if largePins.includes(val)}
<!-- Large pins -->
Expand Down

0 comments on commit 467da82

Please sign in to comment.