Skip to content

Commit

Permalink
add flipper none mode
Browse files Browse the repository at this point in the history
  • Loading branch information
GLDuval committed Jun 12, 2023
1 parent ad019fc commit e490156
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/renderer/components/StatusBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const ModeInfo = () => {
{flipper.matches('rl') && (isReverse ? 'FRONT RIGHT' : 'REAR LEFT')}
{flipper.matches('rr') && (isReverse ? 'FRONT LEFT' : 'REAR RIGHT')}
{flipper.matches('all') && 'ALL'}
{flipper.matches('none') && 'NONE'}
{flipper.matches('rear') && (isReverse ? 'FRONT' : 'REAR')}
</div>
);
Expand Down
27 changes: 20 additions & 7 deletions src/renderer/state/flipper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface FlipperStateSchema {
rl: Record<string, unknown>;
rr: Record<string, unknown>;
all: Record<string, unknown>;
none: Record<string, unknown>;
};
}

Expand All @@ -32,57 +33,69 @@ export const flipperMachine = Machine<
>(
{
id: 'flipper',
initial: 'all',
initial: 'none',
context: {},
states: {
front: {
on: {
MODE_LEFT: { target: 'fl', actions: 'set_mode_fl' },
MODE_RIGHT: { target: 'fr', actions: 'set_mode_fr' },
MODE_REAR: { target: 'all', actions: 'set_mode_all' },
MODE_REAR: { target: 'none', actions: 'set_mode_none' },
},
},
fl: {
on: {
MODE_RIGHT: { target: 'front', actions: 'set_mode_front' },
MODE_REAR: { target: 'all', actions: 'set_mode_all' },
MODE_REAR: { target: 'none', actions: 'set_mode_none' },
},
},
fr: {
on: {
MODE_LEFT: { target: 'front', actions: 'set_mode_front' },
MODE_REAR: { target: 'all', actions: 'set_mode_all' },
MODE_REAR: { target: 'none', actions: 'set_mode_none' },
},
},
rear: {
on: {
MODE_FRONT: { target: 'all', actions: 'set_mode_all' },
MODE_FRONT: { target: 'none', actions: 'set_mode_none' },
MODE_LEFT: { target: 'rl', actions: 'set_mode_rl' },
MODE_RIGHT: { target: 'rr', actions: 'set_mode_rr' },
},
},
rl: {
on: {
MODE_FRONT: { target: 'all', actions: 'set_mode_all' },
MODE_FRONT: { target: 'none', actions: 'set_mode_none' },
MODE_RIGHT: { target: 'rear', actions: 'set_mode_rear' },
},
},
rr: {
on: {
MODE_FRONT: { target: 'all', actions: 'set_mode_none' },
MODE_FRONT: { target: 'none', actions: 'set_mode_none' },
MODE_LEFT: { target: 'rear', actions: 'set_mode_rear' },
},
},
all: {
on: {
MODE_FRONT: { target: 'front', actions: 'set_mode_front' },
MODE_REAR: { target: 'rear', actions: 'set_mode_rear' },
MODE_LEFT: { target: 'none', actions: 'set_mode_none' },
},
},
none: {
on: {
MODE_FRONT: { target: 'front', actions: 'set_mode_front' },
MODE_REAR: { target: 'rear', actions: 'set_mode_rear' },
MODE_RIGHT: { target: 'all', actions: 'set_mode_all' },
},
},
},
},
{
actions: {
set_mode_none: () => {
void sendFlipperMode('front_disable');
void sendFlipperMode('rear_disable');
},
set_mode_all: () => {
void sendFlipperMode('front_enable');
void sendFlipperMode('rear_enable');
Expand Down

0 comments on commit e490156

Please sign in to comment.