@mchp-mcc/scf-pic8-clc-v1 4.0.13 → 4.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/Changelog.md +9 -0
  2. package/Readme.md +9 -0
  3. package/output/autoCreator.js +167 -3
  4. package/output/autoCreator.js.map +1 -1
  5. package/output/autoProcessor.js +167 -3
  6. package/output/autoProcessor.js.map +1 -1
  7. package/output/creator.js +167 -3
  8. package/output/creator.js.map +1 -1
  9. package/output/processor.js +167 -3
  10. package/output/processor.js.map +1 -1
  11. package/output/reducer.js +1 -1
  12. package/output/view.js +1 -1
  13. package/package.json +6 -8
  14. package/src/App.tsx +0 -101
  15. package/src/Constants.ts +0 -181
  16. package/src/CreatorFunctions.ts +0 -44
  17. package/src/DerivedData.test.tsx +0 -285
  18. package/src/DerivedData.ts +0 -444
  19. package/src/GeneratorModel.test.ts +0 -57
  20. package/src/GeneratorModel.ts +0 -60
  21. package/src/InputStateCalculator.test.ts +0 -64
  22. package/src/InputStateCalculator.ts +0 -50
  23. package/src/PinsLogic.test.ts +0 -514
  24. package/src/PinsLogic.ts +0 -164
  25. package/src/SettingNameCalculator.test.ts +0 -21
  26. package/src/SettingNameCalculator.ts +0 -28
  27. package/src/actions.ts +0 -22
  28. package/src/catalog.json +0 -24
  29. package/src/components/CLCView.tsx +0 -141
  30. package/src/components/Canvas.tsx +0 -757
  31. package/src/components/InputSource.tsx +0 -24
  32. package/src/components/InputStage.tsx +0 -55
  33. package/src/components/MX.ts +0 -12
  34. package/src/gates/ALogicGate.ts +0 -221
  35. package/src/gates/AndGate.ts +0 -36
  36. package/src/gates/GateInputState.ts +0 -1
  37. package/src/gates/Latch.ts +0 -93
  38. package/src/gates/NotGate.ts +0 -37
  39. package/src/gates/OrGate.ts +0 -134
  40. package/src/gates/XorGate.ts +0 -12
  41. package/src/index.tsx +0 -51
  42. package/src/interfaces/cla-clc-stacked.test.ts +0 -61
  43. package/src/interfaces/cla-clc-stacked.ts +0 -181
  44. package/src/interfaces/clc-connections.tsx +0 -62
  45. package/src/interfaces/signal-source.ts +0 -78
  46. package/src/interfaces/trigger-source.ts +0 -78
  47. package/src/moduleConfig.json +0 -882
  48. package/src/pinsdata.json +0 -151
  49. package/src/reducer.test.tsx +0 -118
  50. package/src/reducer.tsx +0 -80
@@ -1,444 +0,0 @@
1
- import * as Processor from "@microchip/scf-common/lib/Processor";
2
- import { getGeneratorModel, getHeaderFiles } from "./GeneratorModel";
3
- import * as initializer_system from "@microchip/initializer-system";
4
- import * as claClcStacked from "./interfaces/cla-clc-stacked";
5
- import * as trigger_source from "./interfaces/trigger-source";
6
- import * as signal_source from "./interfaces/signal-source";
7
- import { find } from "@microchip/scf-device/lib/util/Arrays";
8
- import { InputStateCalculator, LogicSelection } from "./InputStateCalculator";
9
- import { Module } from "@microchip/scf-device";
10
- import { GATES, DATA_INPUTS, OPTION_MODULES } from "./Constants";
11
- import {
12
- getGatePolaritySetting,
13
- getGateSourceSetting,
14
- getGateNonInvertedSetting,
15
- getGateInvertedSetting,
16
- } from "./SettingNameCalculator";
17
- import * as clcConnections from "./interfaces/clc-connections";
18
- import { Interface } from "@microchip/scf-interface";
19
- import { values } from "../generated_module/src/Utils";
20
- import {
21
- AppModel,
22
- DerivedData,
23
- DerivedFunctions,
24
- } from "../generated_module/src/types/AutoModuleTypes";
25
- import CalculateRegisterValue from "@microchip/scf-device/lib/CalculateRegisterValue";
26
-
27
- export const getDerivedData = (dataModel: AppModel | undefined): DerivedData => {
28
- if (dataModel) {
29
- return new MyDerivedData(dataModel);
30
- }
31
- return new EmptyDerivedData();
32
- };
33
-
34
- //This data will be used at the creator stage and relies on only the state
35
- export class EmptyDerivedData implements DerivedData {
36
- getMyFunctions = (): DerivedFunctions => {
37
- return {};
38
- };
39
- getModel = (): AppModel | undefined => {
40
- return undefined;
41
- };
42
- }
43
-
44
- //This data will be used at the processor stage
45
- class MyDerivedData implements DerivedData {
46
- private dataModel: AppModel;
47
- private gateDerivedSettings: any;
48
-
49
- constructor(dataModel: AppModel) {
50
- this.dataModel = dataModel;
51
- }
52
-
53
- getMyFunctions = (): DerivedFunctions => {
54
- return {
55
- overrideDefaultValues: this.overrideDefaultValues,
56
- moduleName: (): string | undefined => this.dataModel.getHardware()?.getName(),
57
- componentName: this.componentName,
58
- lcenClccon: this.lcenClccon,
59
- lcmodeClccon: this.lcmodeClccon,
60
- ...this.getGateDerivedSettings(),
61
- lcpolClcpol: this.lcpolClcpol,
62
- slctClcselect: this.getClcSelect,
63
- clci: this.clci,
64
- importName: this.friendlyImportName,
65
- filterImports: this.filterImports,
66
- "cla-clc-stacked_payload": this.cla_clc_payload,
67
- "trigger-source_payload": this.trigger_source_payload,
68
- "signal-source_payload": this.signal_source_payload,
69
- templateData: (): any => getGeneratorModel(this.dataModel),
70
- alerts: this.getMyAlerts,
71
- showCanvasBased: (): boolean => false,
72
- initializer_system_results: this.initializer_system_results,
73
- isrCallback: this.isrCallback,
74
- clc_connections_results: this.clc_connections_results,
75
- isEnabled: this.isEnabled,
76
- getRequestedModule: this.getRequestedModule,
77
- };
78
- };
79
- private isEnabled = (compName: string): boolean | undefined => {
80
- let status;
81
- if (this.dataModel.getComponentValue("clci") === false) {
82
- switch (compName) {
83
- case "lcintnClccon":
84
- status = false;
85
- break;
86
- case "lcintpClccon":
87
- status = false;
88
- break;
89
- default:
90
- status = undefined;
91
- }
92
- return status;
93
- }
94
- };
95
-
96
- private clc_connections_results = (): clcConnections.Results => {
97
- const inputs: string[] = [];
98
-
99
- GATES.forEach((gate) => {
100
- const setting = getGateSourceSetting(gate);
101
- const value = this.dataModel.getComponentValue(setting);
102
- const input: string | undefined = OPTION_MODULES[value];
103
-
104
- if (input && input.indexOf("CLC") !== -1) {
105
- if (inputs.indexOf(input) === -1) {
106
- inputs.push(input);
107
- }
108
- }
109
- });
110
-
111
- return {
112
- moduleName: this.dataModel.getName(),
113
- inputs,
114
- };
115
- };
116
-
117
- private getGateDerivedSettings = (): any => {
118
- if (!this.gateDerivedSettings) {
119
- this.gateDerivedSettings = this.createGateDerivedSettings();
120
- }
121
- return this.gateDerivedSettings;
122
- };
123
-
124
- private createGateDerivedSettings = (): any => {
125
- const result = {};
126
- type ReturnType = string | undefined;
127
-
128
- GATES.forEach((gate: number) => {
129
- DATA_INPUTS.forEach((input: number) => {
130
- result[getGateInvertedSetting(gate, input)] = (): ReturnType =>
131
- this.getDataConfigInvertedProcessedArg(gate, input);
132
-
133
- result[getGateNonInvertedSetting(gate, input)] = (): ReturnType =>
134
- this.getDataConfigNonInvertedProcessedArg(gate, input);
135
- });
136
-
137
- result[getGatePolaritySetting(gate)] = (): ReturnType =>
138
- this.getOutputConfigProcessedArg(gate);
139
-
140
- result[getGateSourceSetting(gate)] = (): ReturnType =>
141
- this.getGateConfig(gate)?.inputSource;
142
- });
143
-
144
- return result;
145
- };
146
-
147
- private overrideDefaultValues = (componentName: string): any => {
148
- switch (componentName) {
149
- case "componentName":
150
- return this.dataModel.getHardware()?.getName();
151
- default:
152
- return undefined;
153
- }
154
- };
155
-
156
- public getModel = (): AppModel => {
157
- return this.dataModel;
158
- };
159
-
160
- private componentName = (): string | undefined => {
161
- return this.getFirstClaClcArgument()?.customName;
162
- };
163
-
164
- private lcenClccon = (): boolean | undefined => {
165
- return this.getFirstClaClcArgument()?.enabled;
166
- };
167
-
168
- private lcmodeClccon = (): string | undefined => {
169
- return this.getFirstClaClcArgument()?.mode;
170
- };
171
-
172
- private lcpolClcpol = (): string | undefined => {
173
- const isInverted = this.getFirstClaClcArgument()?.isInverted;
174
- if (isInverted === true) {
175
- return "inverted";
176
- } else if (isInverted === false) {
177
- return "not_inverted";
178
- } else {
179
- return undefined;
180
- }
181
- };
182
-
183
- private getClcSelect = (): string | undefined => {
184
- const instance = this.dataModel.getPeripheralDescription()?.instance;
185
- if (instance != undefined && instance != "") {
186
- return CalculateRegisterValue.toHexString(parseInt(instance) - 1);
187
- }
188
-
189
- return undefined;
190
- };
191
-
192
- private clci = (): boolean | undefined => {
193
- return this.getFirstClaClcArgument()?.interruptEnabled;
194
- };
195
-
196
- private getMyAlerts = (): Processor.Alert[] => {
197
- const alerts: Processor.Alert[] = [];
198
-
199
- const getValue = (name: string): any => this.dataModel.getComponentValue(name);
200
- GATES.forEach((gate: number) => {
201
- DATA_INPUTS.forEach((input: number) => {
202
- const invertedSetting = getGateInvertedSetting(gate, input);
203
- const nonInvertedSetting = getGateNonInvertedSetting(gate, input);
204
- if (
205
- getValue(invertedSetting) === "enabled" &&
206
- getValue(nonInvertedSetting) === "enabled"
207
- ) {
208
- alerts.push({
209
- type: Processor.AlertTypes.Warning,
210
- text: `Can't have both ${invertedSetting} and ${nonInvertedSetting} settings enabled.`,
211
- });
212
- }
213
- });
214
- });
215
-
216
- const inputs: string[] = [];
217
- GATES.forEach((gate) => {
218
- const setting = getGateSourceSetting(gate);
219
- const value = this.dataModel.getComponentValue(setting);
220
- const input: string | undefined = OPTION_MODULES[value];
221
-
222
- if (input && inputs.indexOf(input) === -1) {
223
- inputs.push(input);
224
- }
225
- });
226
-
227
- inputs.forEach((input) => {
228
- const name = this.dataModel.getName();
229
- alerts.push({
230
- type: Processor.AlertTypes.Hint,
231
- text: `${name} uses ${input}. Ensure ${input} has been configured.`,
232
- });
233
- });
234
-
235
- if (
236
- !getValue("clci") &&
237
- (getValue("lcintpClccon") === "enabled" ||
238
- getValue("lcintnClccon") === "enabled")
239
- ) {
240
- let msg = "";
241
- if (getValue("lcintpClccon") === "enabled") {
242
- msg = "Rising Edge Interrupt";
243
- }
244
- if (getValue("lcintnClccon") === "enabled") {
245
- msg =
246
- msg.length > 1
247
- ? "Rising and Falling Edge Interrupts"
248
- : "Falling Edge Interrupt";
249
- }
250
- alerts.push({
251
- type: Processor.AlertTypes.Warning,
252
- text: `CLC Interrupt is disabled, ${msg} API will not be generated.`,
253
- });
254
- }
255
- return alerts;
256
- };
257
-
258
- private getDataConfigInvertedProcessedArg = (
259
- gate: number,
260
- input: number,
261
- ): string | undefined => {
262
- return this.boolToReg(this.getDataConfigProcessedArg(gate, input)?.inverted);
263
- };
264
-
265
- private getDataConfigNonInvertedProcessedArg = (
266
- gate: number,
267
- input: number,
268
- ): string | undefined => {
269
- return this.boolToReg(this.getDataConfigProcessedArg(gate, input)?.nonInverted);
270
- };
271
-
272
- private getDataConfigProcessedArg = (
273
- gate: number,
274
- input: number,
275
- ): LogicSelection | undefined => {
276
- const gateConfig = this.getGateConfig(gate);
277
- const dataConfigs = gateConfig?.dataInputConfigs ?? [];
278
- const dataConfig = find(dataConfigs, (config) => config.dataInput === input);
279
-
280
- const config = dataConfig?.config;
281
- if (config) {
282
- return InputStateCalculator.getLogicSelection(config);
283
- }
284
-
285
- return undefined;
286
- };
287
-
288
- private getOutputConfigProcessedArg = (gate: number): string | undefined => {
289
- const isInverted = this.getGateConfig(gate)?.isInverted;
290
- if (isInverted === true) {
291
- return "inverted";
292
- } else if (isInverted === false) {
293
- return "not_inverted";
294
- } else {
295
- return undefined;
296
- }
297
- };
298
-
299
- private getGateConfig = (gate: number): claClcStacked.GateConfig | undefined => {
300
- const gateConfigs = this.getFirstClaClcArgument()?.gateConfigs ?? [];
301
- return find(gateConfigs, (config) => config.gate === gate);
302
- };
303
-
304
- private getFirstClaClcArgument = (): claClcStacked.Arguments | undefined => {
305
- const args = this.getClaClcArguments();
306
- return args?.[Object.keys(args)[0]];
307
- };
308
-
309
- private getClaClcArguments = ():
310
- | Processor.Dictionary<claClcStacked.Arguments>
311
- | undefined => {
312
- return this.dataModel
313
- .getExportInterfaces()
314
- .getInterface("clc", claClcStacked.Interface.getInterfaceId())?.args;
315
- };
316
-
317
- private getExportArgs = (intf: Interface): Processor.Dictionary<any> | undefined => {
318
- return this.dataModel
319
- .getExportInterfaces()
320
- .getInterface("clc", intf.getInterfaceId())?.args;
321
- };
322
-
323
- private getRequestedModule = (): string | undefined => {
324
- let args: Processor.Dictionary<any> | undefined;
325
-
326
- args = this.getExportArgs(claClcStacked.Interface);
327
- if (args) {
328
- return values<claClcStacked.Arguments>(args)[0]?.moduleName;
329
- }
330
-
331
- args = this.getExportArgs(trigger_source.Interface);
332
- if (args) {
333
- return values<trigger_source.Arguments>(args)?.[0]?.moduleName;
334
- }
335
-
336
- args = this.getExportArgs(signal_source.Interface);
337
- if (args) {
338
- return values<signal_source.Arguments>(args)?.[0]?.moduleName;
339
- }
340
-
341
- return undefined;
342
- };
343
-
344
- private friendlyImportName = (importKey: string): string | undefined => {
345
- if (importKey === "scf_pic8_clc_v1") {
346
- return "CLC Hardware";
347
- }
348
-
349
- return undefined;
350
- };
351
-
352
- private filterImports = (imports: Processor.Imports): Processor.Imports => {
353
- const filteredImports: Processor.Imports = this.dataModel.filterImportBySetting(
354
- imports,
355
- "scf_pic8_clc_v1",
356
- (option: Processor.Option<Module>): boolean => {
357
- const moduleName = this.getRequestedModule();
358
- return moduleName != undefined
359
- ? option?.payload?.name === moduleName
360
- : true;
361
- },
362
- );
363
- return filteredImports;
364
- };
365
-
366
- private cla_clc_payload = (): claClcStacked.ProcessedPayload => {
367
- this.dataModel.isComponentValue;
368
- return {
369
- interfaceApi: claClcStacked.Interface.createFirmwareApi(
370
- this.getCustomName(),
371
- getHeaderFiles(this.dataModel),
372
- ),
373
- customName: this.getCustomName(),
374
- enabled: this.dataModel.isComponentValue("lcenClccon"),
375
- mode: this.dataModel.getComponentValue(
376
- "lcmodeClccon",
377
- ) as claClcStacked.CLCMode,
378
- gateConfigs: this.getGateConfigsPayload(),
379
- isInverted: this.dataModel.getComponentValue("lcpolClcpol") === "inverted",
380
- hasInterrupts: true,
381
- moduleName: this.dataModel.getName(),
382
- interruptEnabled: this.dataModel.isComponentValue("clci"),
383
- };
384
- };
385
-
386
- private trigger_source_payload = (): trigger_source.ProcessedPayload => {
387
- return {
388
- moduleName: this.dataModel.getName(),
389
- customName: this.getCustomName(),
390
- };
391
- };
392
-
393
- private signal_source_payload = (): signal_source.ProcessedPayload => {
394
- return {
395
- moduleName: this.dataModel.getName(),
396
- customName: this.getCustomName(),
397
- };
398
- };
399
-
400
- private getCustomName = (): string => {
401
- return this.dataModel.getComponentValue("componentName") ?? "CLC";
402
- };
403
-
404
- private getGateConfigsPayload = (): claClcStacked.GateConfig[] => {
405
- const getValue = (name: string): any => this.dataModel.getComponentValue(name);
406
-
407
- return GATES.map((gate: number) => ({
408
- gate: gate,
409
- isInverted: getValue(getGatePolaritySetting(gate)) === "inverted",
410
- inputSource: getValue(getGateSourceSetting(gate)),
411
- dataInputConfigs: DATA_INPUTS.map((input: number) => ({
412
- dataInput: input,
413
- config: InputStateCalculator.getInputState(
414
- this.dataModel.isComponentValue(
415
- getGateNonInvertedSetting(gate, input),
416
- ),
417
- this.dataModel.isComponentValue(getGateInvertedSetting(gate, input)),
418
- ),
419
- })),
420
- }));
421
- };
422
-
423
- private initializer_system_results = (): initializer_system.Results => {
424
- return {
425
- initializer: {
426
- name: this.getCustomName() + "_Initialize",
427
- header: getHeaderFiles(this.dataModel)[0],
428
- },
429
- };
430
- };
431
-
432
- private isrCallback = (intName: string): any => {
433
- return {
434
- name: this.getCustomName() + "_ISR",
435
- header: getHeaderFiles(this.dataModel)[0],
436
- };
437
- };
438
-
439
- private boolToReg = (bool: boolean | undefined): string | undefined => {
440
- if (bool === true) return "enabled";
441
- else if (bool === false) return "disabled";
442
- else return undefined;
443
- };
444
- }
@@ -1,57 +0,0 @@
1
- import { getModel } from "../generated_module/tests/AppModel.test";
2
- import { mockState } from "../generated_module/tests/AppModel.test";
3
- import { mockAssignedModule } from "../generated_module/tests/processor.test";
4
- import { getDerivedData } from "../generated_module/src/autoProcessor";
5
- import { getGeneratorModel } from "./GeneratorModel";
6
-
7
- describe("getGeneratorModel test Cases ", () => {
8
- describe("getGeneratorModel test case undefined getImportValue", () => {
9
- const mockModule = mockAssignedModule(mockState());
10
- const model = getModel(mockModule, getDerivedData);
11
- if (model) {
12
- model.getImportValue = (importName: string): any => {
13
- return undefined;
14
- };
15
- }
16
- it("Test componentName ", () => {
17
- if (model) expect(getGeneratorModel(model)).toBeDefined();
18
- });
19
- });
20
-
21
- describe("getGeneratorModel test case defined getImportValue", () => {
22
- const mockModule = mockAssignedModule(mockState());
23
- const model = getModel(mockModule, getDerivedData);
24
- if (model) {
25
- model.getImportValue = (importName: string): any => {
26
- return {
27
- isVectoredInterrupt: true,
28
- vectoredInterruptEnable: false,
29
- ivtBaseAddress: 8,
30
- isHighPriority: {
31
- CLCI: true,
32
- },
33
- };
34
- };
35
- }
36
- it("Test getGeneratorModel ", () => {
37
- if (model) expect(getGeneratorModel(model)).toBeDefined();
38
- });
39
- });
40
-
41
- describe("getGeneratorModel test case undefined getInterrupts ", () => {
42
- const mockModule = mockAssignedModule(mockState());
43
- const model = getModel(mockModule, getDerivedData);
44
- if (model) {
45
- model.getInterrupts = (): any => {
46
- return {
47
- CLCI: {
48
- handlerName: undefined,
49
- },
50
- };
51
- };
52
- }
53
- it("Test getGeneratorModel ", () => {
54
- if (model) expect(getGeneratorModel(model)).toBeDefined();
55
- });
56
- });
57
- });
@@ -1,60 +0,0 @@
1
- import * as claClcStacked from "./interfaces/cla-clc-stacked";
2
- //import { HeaderFile } from "@microchip/scf-interface";
3
- import * as interrupt_standard from "@microchip/interrupt-standard";
4
- import { AppModel } from "../generated_module/src/types/AutoModuleTypes";
5
- import { values } from "../generated_module/src/Utils";
6
- import { HeaderFile } from "@microchip/scf-interface";
7
-
8
- export const getGeneratorModel = (model: any): any => {
9
- if (!model.getHardware()) return {};
10
- const interrupts = model.getInterrupts();
11
- const registerValues = model.getRegisterValues();
12
- if (!registerValues || !interrupts) return {};
13
-
14
- const initRegisters = values(registerValues).filter(
15
- (reg) => reg.alias !== registerValues.CLCCON.alias,
16
- );
17
- initRegisters.push(registerValues.CLCCON); // should be the last register to be initialized
18
-
19
- const clcInterface = claClcStacked.Interface.createFirmwareApi(
20
- model.getComponentValue("componentName"),
21
- getHeaderFiles(model),
22
- );
23
-
24
- const intPayload:
25
- | interrupt_standard.ProcessedPayload
26
- | undefined = model.getImportValue("interrupt_standard");
27
-
28
- return {
29
- compiler: "XC8 v2.20",
30
- tool: "MPLABX v5.40",
31
-
32
- componentName: model.getComponentValue("componentName"),
33
- moduleNameLowerCase: model.getName().toLowerCase(),
34
- moduleNameUpperCase: model.getName().toUpperCase(),
35
- header: clcInterface.headerFiles?.[0],
36
- api: clcInterface.api,
37
- simpleApi: clcInterface.simpleApi,
38
-
39
- interruptEnabled: model.isComponentValue("clci"),
40
- isVectoredInterruptEnabled: intPayload?.vectoredInterruptEnable ?? false,
41
- isHighPriority: intPayload?.isHighPriority?.["CLCI"] ?? true,
42
- IVTBaseAddress: String(intPayload?.ivtBaseAddress ?? 8),
43
- interruptFlagName: interrupts["CLCI"].flag,
44
- interruptEnableBitName: interrupts["CLCI"].enable,
45
- IRQname: interrupts["CLCI"].handlerName?.replace("_", "") ?? "",
46
-
47
- initRegisters,
48
- CLCDATA: registerValues.CLCDATA,
49
- CLCCON: registerValues.CLCCON,
50
- };
51
- };
52
-
53
- export const getHeaderFiles = (model: AppModel): HeaderFile[] => {
54
- return [
55
- {
56
- name: model.getName().toLowerCase() + ".h",
57
- path: "clc/",
58
- },
59
- ];
60
- };
@@ -1,64 +0,0 @@
1
- import { InputStateCalculator, LogicSelection } from "./InputStateCalculator";
2
- import { GateInputState } from "./gates/GateInputState";
3
-
4
- describe("Input state calculator", () => {
5
- it("calculates grounded state", () => {
6
- const result = InputStateCalculator.getInputState(false, false);
7
- expect(result).toBe<GateInputState>("Grounded");
8
- });
9
-
10
- it("calculates normal state", () => {
11
- const result = InputStateCalculator.getInputState(true, false);
12
- expect(result).toBe<GateInputState>("Normal");
13
- });
14
-
15
- it("calculates inverted state", () => {
16
- const result = InputStateCalculator.getInputState(false, true);
17
- expect(result).toBe<GateInputState>("Inverted");
18
- });
19
-
20
- it("calculates illegal state", () => {
21
- const result = InputStateCalculator.getInputState(true, true);
22
- expect(result).toBe<GateInputState>("Illegal");
23
- });
24
-
25
- it("calculates logic selection for grounded state", () => {
26
- const result = InputStateCalculator.getLogicSelection("Grounded");
27
- expect(result).toEqual<LogicSelection>({ inverted: false, nonInverted: false });
28
- });
29
-
30
- it("calculates logic selection for normal state", () => {
31
- const result = InputStateCalculator.getLogicSelection("Normal");
32
- expect(result).toEqual<LogicSelection>({ inverted: false, nonInverted: true });
33
- });
34
-
35
- it("calculates logic selection for inverted state", () => {
36
- const result = InputStateCalculator.getLogicSelection("Inverted");
37
- expect(result).toEqual<LogicSelection>({ inverted: true, nonInverted: false });
38
- });
39
-
40
- it("calculates logic selection for illegal state", () => {
41
- const result = InputStateCalculator.getLogicSelection("Illegal");
42
- expect(result).toEqual<LogicSelection>({ inverted: true, nonInverted: true });
43
- });
44
-
45
- it("calculates next state after grounded", () => {
46
- const result = InputStateCalculator.getNextState("Grounded");
47
- expect(result).toBe<GateInputState>("Normal");
48
- });
49
-
50
- it("calculates next state after normal", () => {
51
- const result = InputStateCalculator.getNextState("Normal");
52
- expect(result).toBe<GateInputState>("Inverted");
53
- });
54
-
55
- it("calculates next state after inverted", () => {
56
- const result = InputStateCalculator.getNextState("Inverted");
57
- expect(result).toBe<GateInputState>("Grounded");
58
- });
59
-
60
- it("calculates next state after illegal", () => {
61
- const result = InputStateCalculator.getNextState("Illegal");
62
- expect(result).toBe<GateInputState>("Normal");
63
- });
64
- });
@@ -1,50 +0,0 @@
1
- import { GateInputState } from "./gates/GateInputState";
2
-
3
- export type LogicSelection = {
4
- nonInverted: boolean;
5
- inverted: boolean;
6
- };
7
-
8
- export class InputStateCalculator {
9
- static getInputState = (nonInverted: boolean, inverted: boolean): GateInputState => {
10
- if (!nonInverted && !inverted) {
11
- return "Grounded";
12
- } else if (!nonInverted && inverted) {
13
- return "Inverted";
14
- } else if (nonInverted && !inverted) {
15
- return "Normal";
16
- } else {
17
- return "Illegal";
18
- }
19
- };
20
-
21
- static getLogicSelection = (gateInputState: GateInputState): LogicSelection => {
22
- switch (gateInputState) {
23
- case "Grounded":
24
- return { nonInverted: false, inverted: false };
25
- case "Inverted":
26
- return { nonInverted: false, inverted: true };
27
- case "Normal":
28
- return { nonInverted: true, inverted: false };
29
- case "Illegal":
30
- return { nonInverted: true, inverted: true };
31
- default:
32
- throw new Error("Invalid input state");
33
- }
34
- };
35
-
36
- static getNextState = (gateInputState: GateInputState): GateInputState => {
37
- switch (gateInputState) {
38
- case "Grounded":
39
- return "Normal";
40
- case "Inverted":
41
- return "Grounded";
42
- case "Normal":
43
- return "Inverted";
44
- case "Illegal":
45
- return "Normal";
46
- default:
47
- throw new Error("Invalid input state");
48
- }
49
- };
50
- }