Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jfabellera committed Sep 14, 2024
1 parent 720f8ab commit 694ea23
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 49 deletions.
16 changes: 7 additions & 9 deletions back-end/realtime/src/util/WLEDHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ export const buildWledSetColorPacket = (
};

packet.patterns.forEach((pattern) => {
wledJson.seg.push(
...pattern.targetSegments.map((segment) => ({
id: segment,
on: true,
frz: false,
fx: 0,
col: [pattern.color]
}))
);
wledJson.seg.push({
id: pattern.segment,
on: true,
frz: false,
fx: 0,
col: [pattern.color]
});
});

return JSON.stringify(wledJson);
Expand Down
2 changes: 1 addition & 1 deletion lib/models/src/base/FieldControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export type HubUpdateParameters = HubParameters<
// WLED parameters
//-------------------------------------------
export interface LedPatternUpdateParameters {
segment: number;
color: string;
targetSegments: number[];
}

export interface LedSegment {
Expand Down
98 changes: 59 additions & 39 deletions lib/models/src/fcs/Packets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function applyPatternToStrips(
}

packet.wleds[strip.controller].patterns.push({
targetSegments: strip.segments,
segment: strip.segment,
color
});
});
Expand Down Expand Up @@ -82,37 +82,57 @@ function applySetpointToMotors(
type WledController = 'center' | 'red' | 'blue';

class LedStrip {
public static readonly RED_NEXUS_GOAL = new LedStrip(
'red',
[0, 1, 2, 3, 4, 5]
);
public static readonly BLUE_NEXUS_GOAL = new LedStrip(
'blue',
[0, 1, 2, 3, 4, 5]
);
public static readonly RED_CENTER_NEXUS_GOAL = new LedStrip(
'center',
[0, 1, 2, 3, 4, 5]
);
public static readonly BLUE_CENTER_NEXUS_GOAL = new LedStrip(
'center',
[6, 7, 8, 9, 10, 11]
);
public static readonly RAMP = new LedStrip('center', [12]);
public static readonly RED_SIDE_GOALS = [
new LedStrip('red', 0),
new LedStrip('red', 1),
new LedStrip('red', 2),
new LedStrip('red', 3),
new LedStrip('red', 4),
new LedStrip('red', 5)
];

public static readonly BLUE_SIDE_GOALS = [
new LedStrip('blue', 0),
new LedStrip('blue', 1),
new LedStrip('blue', 2),
new LedStrip('blue', 3),
new LedStrip('blue', 4),
new LedStrip('blue', 5)
];

public static readonly RED_CENTER_GOALS = [
new LedStrip('center', 0),
new LedStrip('center', 1),
new LedStrip('center', 2),
new LedStrip('center', 3),
new LedStrip('center', 4),
new LedStrip('center', 5)
];

public static readonly BLUE_CENTER_GOALS = [
new LedStrip('center', 6),
new LedStrip('center', 7),
new LedStrip('center', 8),
new LedStrip('center', 9),
new LedStrip('center', 10),
new LedStrip('center', 11)
];

public static readonly RAMP = new LedStrip('center', 12);

public static readonly ALL_RED_STRIPS = [
LedStrip.RED_NEXUS_GOAL,
LedStrip.RED_CENTER_NEXUS_GOAL
public static readonly ALL_RED_GOALS = [
...LedStrip.RED_SIDE_GOALS,
...LedStrip.RED_CENTER_GOALS
];

public static readonly ALL_BLUE_STRIPS = [
LedStrip.BLUE_NEXUS_GOAL,
LedStrip.BLUE_CENTER_NEXUS_GOAL
public static readonly ALL_BLUE_GOALS = [
...LedStrip.BLUE_SIDE_GOALS,
...LedStrip.BLUE_CENTER_GOALS
];

public static readonly ALL_NEXUS_GOALS = [
...LedStrip.ALL_RED_STRIPS,
...LedStrip.ALL_BLUE_STRIPS
...LedStrip.ALL_RED_GOALS,
...LedStrip.ALL_BLUE_GOALS
];

public static readonly ALL_STRIPS = [
Expand All @@ -121,18 +141,18 @@ class LedStrip {
];

public readonly controller: WledController;
public readonly segments: number[];
public readonly segment: number;

private constructor(controller: WledController, segments: number[]) {
private constructor(controller: WledController, segment: number) {
this.controller = controller;
this.segments = segments;
this.segment = segment;
}
}

type MotorPortType = 'on board' | 'spark mini';

class Motor {
public static readonly RED_NEXUS_GOALS: Motor[] = [
public static readonly RED_SIDE_GOALS: Motor[] = [
new Motor(RevHub.RED_CONTROL_HUB, 'on board', 0),
new Motor(RevHub.RED_CONTROL_HUB, 'on board', 1),
new Motor(RevHub.RED_CONTROL_HUB, 'on board', 2),
Expand All @@ -141,7 +161,7 @@ class Motor {
new Motor(RevHub.RED_CONTROL_HUB, 'spark mini', 5)
];

public static readonly BLUE_NEXUS_GOALS: Motor[] = [
public static readonly BLUE_SIDE_GOALS: Motor[] = [
new Motor(RevHub.BLUE_CONTROL_HUB, 'on board', 0),
new Motor(RevHub.BLUE_CONTROL_HUB, 'on board', 1),
new Motor(RevHub.BLUE_CONTROL_HUB, 'on board', 2),
Expand All @@ -150,7 +170,7 @@ class Motor {
new Motor(RevHub.BLUE_CONTROL_HUB, 'spark mini', 5)
];

public static readonly RED_CENTER_NEXUS_GOALS: Motor[] = [
public static readonly RED_CENTER_GOALS: Motor[] = [
new Motor(RevHub.CENTER_CONTROL_HUB, 'on board', 0),
new Motor(RevHub.CENTER_CONTROL_HUB, 'on board', 1),
new Motor(RevHub.CENTER_CONTROL_HUB, 'on board', 2),
Expand All @@ -159,7 +179,7 @@ class Motor {
new Motor(RevHub.CENTER_CONTROL_HUB, 'spark mini', 5)
];

public static readonly BLUE_CENTER_NEXUS_GOALS: Motor[] = [
public static readonly BLUE_CENTER_GOALS: Motor[] = [
new Motor(RevHub.CENTER_EXPANSION_HUB, 'on board', 0),
new Motor(RevHub.CENTER_EXPANSION_HUB, 'on board', 1),
new Motor(RevHub.CENTER_EXPANSION_HUB, 'on board', 2),
Expand All @@ -169,10 +189,10 @@ class Motor {
];

public static readonly ALL_GOALS = [
...this.RED_NEXUS_GOALS,
...this.BLUE_NEXUS_GOALS,
...this.RED_CENTER_NEXUS_GOALS,
...this.BLUE_CENTER_NEXUS_GOALS
...this.RED_SIDE_GOALS,
...this.BLUE_SIDE_GOALS,
...this.RED_CENTER_GOALS,
...this.BLUE_CENTER_GOALS
];

public readonly hub: RevHub;
Expand Down Expand Up @@ -290,12 +310,12 @@ function buildMatchEndPacket(
const result: FieldControlUpdatePacket = { hubs: {}, wleds: {} };
applyPatternToStrips(
fieldOptions.matchEndBlueNexusGoalColor,
LedStrip.ALL_BLUE_STRIPS,
LedStrip.ALL_BLUE_GOALS,
result
);
applyPatternToStrips(
fieldOptions.matchEndRedNexusGoalColor,
LedStrip.ALL_RED_STRIPS,
LedStrip.ALL_RED_GOALS,
result
);
applyPatternToStrips(fieldOptions.matchEndRampColor, [LedStrip.RAMP], result);
Expand Down

0 comments on commit 694ea23

Please sign in to comment.