Skip to content

Commit

Permalink
work on simplifying terminal handling (#420)
Browse files Browse the repository at this point in the history
* work on simplifying terminal handling

* update terminal handling function

* some debugging to do

* terminal logic refactored

* more thoughts
  • Loading branch information
tballmsft authored Oct 14, 2023
1 parent 1fd6c45 commit 31223e3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 33 deletions.
15 changes: 1 addition & 14 deletions language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace microcode {
tiles?: string[]
categories?: string[]
}
handling?: { [id: string]: any }
}

// TODO: make into class
Expand Down Expand Up @@ -146,13 +145,6 @@ namespace microcode {
dst.disallow.categories.push(item)
)
}
if (src.handling) {
const keys = Object.keys(src.handling)
for (const key of keys) {
// TODO: deep copy
dst.handling[key] = src.handling[key]
}
}
}

isCompatibleWith(c: Constraints): boolean {
Expand Down Expand Up @@ -423,11 +415,7 @@ namespace microcode {
}

function isTerminal(tile: TileDefn) {
return (
tile.constraints &&
tile.constraints.handling &&
tile.constraints.handling["terminal"]
)
return !isTidNotTerminal(tidToEnum(tile.tid))
}

export class Language {
Expand Down Expand Up @@ -501,7 +489,6 @@ namespace microcode {
tiles: [],
categories: [],
},
handling: {},
}
return c
}
Expand Down
48 changes: 46 additions & 2 deletions tids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ namespace microcode {
TID_FILTER_COIN_5,
TID_FILTER_TIMESPAN_SHORT,
TID_FILTER_TIMESPAN_LONG,
TID_FILTER_TIMESPAN_RANDOM,
TID_FILTER_TIMESPAN_VERY_LONG,
TID_FILTER_LOUD,
TID_FILTER_QUIET,
TID_FILTER_ACCEL,
Expand All @@ -195,8 +197,6 @@ namespace microcode {
TID_FILTER_ACCEL_TILT_DOWN,
TID_FILTER_ACCEL_TILT_LEFT,
TID_FILTER_ACCEL_TILT_RIGHT,
TID_FILTER_TIMESPAN_RANDOM,
TID_FILTER_TIMESPAN_VERY_LONG,
TID_FILTER_CUP_X_READ,
TID_FILTER_CUP_Y_READ,
TID_FILTER_CUP_Z_READ,
Expand Down Expand Up @@ -753,6 +753,50 @@ namespace microcode {
return tid >= Tid.MODIFIER_START && tid < Tid.MODIFER_END
}

export function isTidNotTerminal(tid: Tid) {
// the following sensors and actuators are terminal
if (
tid == Tid.TID_SENSOR_CAR_WALL ||
tid == Tid.TID_SENSOR_SLIDER ||
tid == Tid.TID_ACTUATOR_SWITCH_PAGE
)
return false
// everything else except some filters is not terminal
if (!isFilter(tid)) return true
// the following filters are not terminal
if (
(Tid.TID_FILTER_COIN_1 <= tid && tid <= Tid.TID_FILTER_COIN_5) ||
(Tid.TID_FILTER_TIMESPAN_SHORT <= tid &&
tid <= Tid.TID_FILTER_TIMESPAN_VERY_LONG) ||
(Tid.TID_FILTER_CUP_X_READ <= tid &&
tid <= Tid.TID_FILTER_CUP_Z_READ)
)
return true
// all other filters are terminal
return false
}

// TODO: we don't need separate bits for everything.
// TODO: only certain things can be combined. Analyze and optimize
export enum TidKinds {
PressEvent = 0x01,
ValueIn = 0x02,
ValueOut = 0x04,
RotaryEvent = 0x08,
TempEvent = 0x10,
AccelEvent = 0x20,
TimeSpan = 0x40,
SoundEvent = 0x80,
IconEditor = 0x100,
Loop = 0x200,
MelodyEditor = 0x400,
SoundEmoji = 0x800,
Constant = 0x1000,
Page = 0x2000,
Car = 0x4000,
RGBLed = 0x8000,
}

export function assert(cond: boolean, msg?: string) {
if (!cond) {
if (msg == null) msg = "Assertion failed"
Expand Down
17 changes: 0 additions & 17 deletions tiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ namespace microcode {

// initialize the database, imperatively!!!

const terminal = {
handling: {
terminal: true,
},
}

function addButtonTiles() {
function addPress(tid: string, evt: number) {
const press_event = new SensorDefn(tid)
Expand All @@ -63,9 +57,6 @@ namespace microcode {
function addPressFilter(tid: string, instanceNo: number) {
const press_filter = new FilterDefn(tid, "press_event", 10)
press_filter.constraints = {
handling: {
terminal: true,
},
allow: {
categories: ["press_event"],
},
Expand Down Expand Up @@ -142,7 +133,6 @@ namespace microcode {
slider.jdExternalClass = 0x1f274746
slider.constraints.allow.categories = []
slider.constraints.allow.tiles = only5
slider.constraints.handling = { terminal: true }

if (CAR_TILES) {
const wall = makeSensor(TID_SENSOR_CAR_WALL, "value_in", 500)
Expand All @@ -151,7 +141,6 @@ namespace microcode {
wall.jdKind = JdKind.Radio
wall.constraints.allow.categories = []
wall.constraints.allow.tiles = only5
wall.constraints.handling = { terminal: true }
}

const magnet = makeSensor(TID_SENSOR_MAGNET, "value_in", 500)
Expand All @@ -173,7 +162,6 @@ namespace microcode {
function addEvent(tid: string, type: string, id: number) {
const ev = new FilterDefn(tid, type, 10)
ev.jdParam = id
ev.constraints = terminal
ev.jdKind = JdKind.EventCode
tilesDB.filters[tid] = ev
return ev
Expand Down Expand Up @@ -221,7 +209,6 @@ namespace microcode {
TID_FILTER_LINE_BOTH,
TID_FILTER_LINE_NEITHER,
]
line.constraints.handling = { terminal: true }
}

const timer = new SensorDefn(TID_SENSOR_TIMER)
Expand Down Expand Up @@ -260,7 +247,6 @@ namespace microcode {
const accelEvent = new FilterDefn(tid, "accel_event", 10)
accelEvent.jdKind = JdKind.EventCode
accelEvent.jdParam = id
accelEvent.constraints = terminal
tilesDB.filters[tid] = accelEvent
return accelEvent
}
Expand All @@ -285,7 +271,6 @@ namespace microcode {
tilesDB.sensors[TID_SENSOR_MICROPHONE] = microphone
function addSoundFilter(tid: string, eventCode: number) {
const soundFilter = new FilterDefn(tid, "sound_event", 10)
soundFilter.constraints = terminal
tilesDB.filters[tid] = soundFilter
soundFilter.jdKind = JdKind.EventCode
soundFilter.jdParam = eventCode
Expand Down Expand Up @@ -424,8 +409,6 @@ namespace microcode {
make_vals(one_to_five, "value_in", "F", 8)
make_vals(one_to_five, "constant", "M", 6)
make_vals(one_to_five, "page", "M", 1).forEach(m => {
m.constraints.handling = m.constraints.handling || {}
m.constraints.handling.terminal = true
m.jdKind = JdKind.Page
})

Expand Down

0 comments on commit 31223e3

Please sign in to comment.