-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lights) add lights switches to support DMX switchpacks (#39)
- Loading branch information
Showing
10 changed files
with
251 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import BaseEntity from '../../root/entities/base-entity'; | ||
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm'; | ||
import LightsController from '../../root/entities/lights-controller'; | ||
|
||
@Entity() | ||
export default class LightsSwitch extends BaseEntity { | ||
@ManyToOne(() => LightsController, { eager: true }) | ||
@JoinColumn() | ||
public controller: LightsController; | ||
|
||
/** | ||
* DMX channel this lights switch is on | ||
*/ | ||
@Column({ type: 'tinyint', unsigned: true }) | ||
public dmxChannel: number; | ||
|
||
/** | ||
* DMX value to send to the channel to turn on the switch | ||
*/ | ||
@Column({ type: 'tinyint', unsigned: true }) | ||
public onValue: number; | ||
|
||
@Column() | ||
public name: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import { Entity, OneToMany } from 'typeorm'; | ||
// eslint-disable-next-line import/no-cycle | ||
import { LightsGroup } from '../../lights/entities'; | ||
import { LightsGroup, LightsSwitch } from '../../lights/entities'; | ||
import SubscribeEntity from './subscribe-entity'; | ||
|
||
@Entity() | ||
export default class LightsController extends SubscribeEntity { | ||
@OneToMany(() => LightsGroup, (group) => group.controller) | ||
public lightsGroups: LightsGroup[]; | ||
|
||
@OneToMany(() => LightsSwitch, (lightsSwitch) => lightsSwitch.controller) | ||
public lightsSwitches: LightsSwitch[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { LightsSwitch } from '../lights/entities'; | ||
|
||
export default class LightsSwitchManager { | ||
private static instance: LightsSwitchManager; | ||
|
||
private enabledSwitches: LightsSwitch[] = []; | ||
|
||
private constructor() {} | ||
|
||
public static getInstance(): LightsSwitchManager { | ||
if (this.instance == null) { | ||
this.instance = new LightsSwitchManager(); | ||
} | ||
return this.instance; | ||
} | ||
|
||
/** | ||
* Turn on the given switch if it is turned off | ||
* @param lightsSwitch | ||
*/ | ||
public enableSwitch(lightsSwitch: LightsSwitch): void { | ||
const index = this.enabledSwitches.findIndex((s) => s.id === lightsSwitch.id); | ||
// Switch is already turned on | ||
if (index >= 0) return; | ||
|
||
this.enabledSwitches.push(lightsSwitch); | ||
} | ||
|
||
/** | ||
* Turn off the given switch if it is turned on | ||
* @param lightsSwitch | ||
*/ | ||
public disableSwitch(lightsSwitch: LightsSwitch) { | ||
const index = this.enabledSwitches.findIndex((s) => s.id === lightsSwitch.id); | ||
if (index >= 0) { | ||
// Remove the switch from the list if it is turned on | ||
this.enabledSwitches.splice(index, 1); | ||
} | ||
} | ||
|
||
/** | ||
* Get all lights switches that are turned on | ||
*/ | ||
public getEnabledSwitches(): LightsSwitch[] { | ||
return this.enabledSwitches; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.