Skip to content

Commit

Permalink
remove more fields from classes, replace by function lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
tballmsft committed Oct 14, 2023
1 parent 460c550 commit b8e66d8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
4 changes: 2 additions & 2 deletions jacs_topwriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,8 @@ namespace jacs {

lookupEventCode(role: Role, rule: microcode.RuleDefn) {
const sensor = rule.sensor
if (sensor.eventCode != undefined) {
let evCode = sensor.eventCode
let evCode = microcode.eventCode(microcode.tidToEnum(sensor.tid))
if (evCode != undefined) {
for (const m of rule.filters)
if (m.jdKind == microcode.JdKind.EventCode)
evCode = m.jdParam
Expand Down
7 changes: 1 addition & 6 deletions language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,7 @@ namespace microcode {
public serviceInstanceIndex: number = 0
}

export class SensorDefn extends StmtTileDefn {
public eventCode: number
constructor(tid: string) {
super(tid)
}
}
export class SensorDefn extends StmtTileDefn {}

export class FilterModifierBase extends TileDefn {
constructor(type: TileType, tid: string, public category: string) {
Expand Down
23 changes: 23 additions & 0 deletions tids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,29 @@ namespace microcode {
return false
}

// Jacdac event codes
export function eventCode(tid: Tid) {
switch (tid) {
case Tid.TID_SENSOR_TEMP:
case Tid.TID_FILTER_QUIET:
case Tid.TID_SENSOR_RELEASE:
return 2
case Tid.TID_SENSOR_LINE:
case Tid.TID_SENSOR_CAR_WALL:
case Tid.TID_SENSOR_RADIO_RECEIVE:
return 0x91
case Tid.TID_SENSOR_MICROPHONE:
case Tid.TID_SENSOR_ROTARY:
case Tid.TID_FILTER_LOUD:
case Tid.TID_SENSOR_PRESS:
return 1
case Tid.TID_SENSOR_ACCELEROMETER:
return 0x8b
default:
return undefined
}
}

// TODO: we don't need separate bits for everything.
// TODO: only certain things can be combined. Analyze and optimize
export enum TidKinds {
Expand Down
8 changes: 0 additions & 8 deletions tiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ namespace microcode {
function addPress(tid: string, evt: number) {
const press_event = new SensorDefn(tid)
press_event.serviceClassName = "button"
press_event.eventCode = evt
press_event.serviceInstanceIndex = 0
press_event.constraints = {
allow: {
Expand Down Expand Up @@ -111,11 +110,9 @@ namespace microcode {
const temp = makeSensor(TID_SENSOR_TEMP, "temperature_event", 99)
temp.serviceClassName = "temperature"
temp.jdKind = JdKind.Temperature
temp.eventCode = 2

const radio_recv = makeSensor(TID_SENSOR_RADIO_RECEIVE, "value_in", 100)
radio_recv.serviceClassName = "radio"
radio_recv.eventCode = 0x91
radio_recv.jdKind = JdKind.Radio
radio_recv.constraints.provides = [TID_SENSOR_RADIO_RECEIVE]

Expand All @@ -137,7 +134,6 @@ namespace microcode {
if (CAR_TILES) {
const wall = makeSensor(TID_SENSOR_CAR_WALL, "value_in", 500)
wall.serviceClassName = "radio"
wall.eventCode = 0x91
wall.jdKind = JdKind.Radio
wall.constraints.allow.categories = []
wall.constraints.allow.tiles = only5
Expand All @@ -157,7 +153,6 @@ namespace microcode {
rotary.serviceClassName = "rotaryEncoder"
rotary.jdExternalClass = 0x10fa29c9
rotary.jdKind = JdKind.Rotary
rotary.eventCode = 1

function addEvent(tid: string, type: string, id: number) {
const ev = new FilterDefn(tid, type, 10)
Expand Down Expand Up @@ -200,7 +195,6 @@ namespace microcode {

const line = makeSensor(TID_SENSOR_LINE, "line", 505)
line.serviceClassName = "radio"
line.eventCode = 0x91
line.jdKind = JdKind.Radio
line.constraints.allow.categories = []
line.constraints.allow.tiles = [
Expand Down Expand Up @@ -238,7 +232,6 @@ namespace microcode {
},
}
accel.serviceClassName = "accelerometer"
accel.eventCode = 0x8b // shake
accel.priority = 20
tilesDB.sensors[TID_SENSOR_ACCELEROMETER] = accel

Expand Down Expand Up @@ -267,7 +260,6 @@ namespace microcode {
}
microphone.priority = 30
microphone.serviceClassName = "soundLevel"
microphone.eventCode = 1 // loud by default
tilesDB.sensors[TID_SENSOR_MICROPHONE] = microphone
function addSoundFilter(tid: string, eventCode: number) {
const soundFilter = new FilterDefn(tid, "sound_event", 10)
Expand Down

0 comments on commit b8e66d8

Please sign in to comment.