Skip to content

Commit 18b0526

Browse files
authored
Merge pull request #4 from Kamoool/Set_sensor_button
Added Set sensor button
2 parents a9bb68a + 722d587 commit 18b0526

2 files changed

Lines changed: 190 additions & 78 deletions

File tree

lib/widgets/downshifter_widget.dart

Lines changed: 95 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -123,46 +123,86 @@ class _DownshifterWidgetState extends State<DownshifterWidget> {
123123
),
124124
],
125125
),
126-
Align(
127-
alignment: Alignment.center,
128-
child: Padding(
129-
padding: const EdgeInsets.fromLTRB(0, 30, 0, 35),
130-
child: TapDebouncer(
131-
cooldown: const Duration(milliseconds: 500),
132-
onTap: () async => await blipCommandCall(),
133-
builder: (BuildContext context, TapDebouncerFunc? onTap) {
134-
return ElevatedButton(
135-
onPressed: onTap,
136-
style: ElevatedButton.styleFrom(
137-
minimumSize: const Size(150, 55),
138-
primary: Colors.white38,
139-
onPrimary: Colors.black12,
140-
onSurface: Colors.red,
141-
shadowColor: Colors.black,
142-
elevation: 3,
143-
side: const BorderSide(
144-
color: Colors.transparent,
145-
width: 2,
146-
style: BorderStyle.solid),
147-
shape: RoundedRectangleBorder(
148-
borderRadius: BorderRadius.circular(20),
126+
Padding(
127+
padding: const EdgeInsets.fromLTRB(0, 30, 0, 35),
128+
child: Row(
129+
mainAxisAlignment: MainAxisAlignment.spaceAround,
130+
children: [
131+
TapDebouncer(
132+
cooldown: const Duration(milliseconds: 500),
133+
onTap: () async => await blipCommandCall(),
134+
builder:
135+
(BuildContext context, TapDebouncerFunc? onTap) {
136+
return ElevatedButton(
137+
onPressed: onTap,
138+
style: ElevatedButton.styleFrom(
139+
minimumSize: const Size(150, 55),
140+
primary: Colors.white38,
141+
onPrimary: Colors.black12,
142+
onSurface: Colors.red,
143+
shadowColor: Colors.black,
144+
elevation: 3,
145+
side: const BorderSide(
146+
color: Colors.transparent,
147+
width: 2,
148+
style: BorderStyle.solid),
149+
shape: RoundedRectangleBorder(
150+
borderRadius: BorderRadius.circular(20),
151+
),
152+
tapTargetSize: MaterialTapTargetSize.padded,
149153
),
150-
tapTargetSize: MaterialTapTargetSize.padded,
151-
),
152-
child: onTap == null
153-
? const Text(
154-
'Wait',
155-
style: TextStyle(
156-
color: Colors.white, fontSize: 25),
157-
)
158-
: const Text(
159-
'Blip',
160-
style: TextStyle(
161-
color: Colors.white, fontSize: 25),
162-
),
163-
);
164-
},
165-
),
154+
child: onTap == null
155+
? const Text(
156+
'Wait',
157+
style: TextStyle(
158+
color: Colors.white, fontSize: 25),
159+
)
160+
: const Text(
161+
'Blip',
162+
style: TextStyle(
163+
color: Colors.white, fontSize: 25),
164+
),
165+
);
166+
},
167+
),
168+
TapDebouncer(
169+
cooldown: const Duration(milliseconds: 100),
170+
onTap: () async => await setSensor(),
171+
builder:
172+
(BuildContext context, TapDebouncerFunc? onTap) {
173+
return ElevatedButton(
174+
onPressed: onTap,
175+
style: ElevatedButton.styleFrom(
176+
minimumSize: const Size(150, 55),
177+
primary: Colors.white38,
178+
onPrimary: Colors.black12,
179+
onSurface: Colors.red,
180+
shadowColor: Colors.black,
181+
elevation: 3,
182+
side: const BorderSide(
183+
color: Colors.transparent,
184+
width: 2,
185+
style: BorderStyle.solid),
186+
shape: RoundedRectangleBorder(
187+
borderRadius: BorderRadius.circular(20),
188+
),
189+
tapTargetSize: MaterialTapTargetSize.padded,
190+
),
191+
child: onTap == null
192+
? const Text(
193+
'Wait',
194+
style: TextStyle(
195+
color: Colors.white, fontSize: 25),
196+
)
197+
: const Text(
198+
'Set sensor',
199+
style: TextStyle(
200+
color: Colors.white, fontSize: 25),
201+
),
202+
);
203+
},
204+
),
205+
],
166206
),
167207
),
168208
NumericSetting(
@@ -284,4 +324,20 @@ class _DownshifterWidgetState extends State<DownshifterWidget> {
284324
Future<void> blipCommandCall() async {
285325
SerialPortUtils().blip();
286326
}
327+
328+
Future<void> setSensor() async {
329+
if (double.tryParse(SettingsRepository().sensorReading.value)! != 2000) {
330+
SettingsRepository().dsForce.value =
331+
(((double.tryParse(SettingsRepository().sensorReading.value)! > 2000)
332+
? 1
333+
: -1) *
334+
(double.tryParse(SettingsRepository().sensorReading.value)! -
335+
2000))
336+
.toString();
337+
SettingsRepository().pushCheckQS.value =
338+
(double.tryParse(SettingsRepository().sensorReading.value)! > 2000)
339+
? '1'
340+
: '0';
341+
}
342+
}
287343
}

lib/widgets/quickshifter_widget.dart

Lines changed: 95 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -123,46 +123,86 @@ class _QuickshifterWidgetState extends State<QuickshifterWidget> {
123123
),
124124
],
125125
),
126-
Align(
127-
alignment: Alignment.center,
128-
child: Padding(
129-
padding: const EdgeInsets.fromLTRB(0, 30, 0, 35),
130-
child: TapDebouncer(
131-
cooldown: const Duration(milliseconds: 500),
132-
onTap: () async => await cutCommandCall(),
133-
builder: (BuildContext context, TapDebouncerFunc? onTap) {
134-
return ElevatedButton(
135-
onPressed: onTap,
136-
style: ElevatedButton.styleFrom(
137-
minimumSize: const Size(150, 55),
138-
primary: Colors.white38,
139-
onPrimary: Colors.black12,
140-
onSurface: Colors.red,
141-
shadowColor: Colors.black,
142-
elevation: 3,
143-
side: const BorderSide(
144-
color: Colors.transparent,
145-
width: 2,
146-
style: BorderStyle.solid),
147-
shape: RoundedRectangleBorder(
148-
borderRadius: BorderRadius.circular(20),
126+
Padding(
127+
padding: const EdgeInsets.fromLTRB(0, 30, 0, 35),
128+
child: Row(
129+
mainAxisAlignment: MainAxisAlignment.spaceAround,
130+
children: [
131+
TapDebouncer(
132+
cooldown: const Duration(milliseconds: 500),
133+
onTap: () async => await cutCommandCall(),
134+
builder:
135+
(BuildContext context, TapDebouncerFunc? onTap) {
136+
return ElevatedButton(
137+
onPressed: onTap,
138+
style: ElevatedButton.styleFrom(
139+
minimumSize: const Size(150, 55),
140+
primary: Colors.white38,
141+
onPrimary: Colors.black12,
142+
onSurface: Colors.red,
143+
shadowColor: Colors.black,
144+
elevation: 3,
145+
side: const BorderSide(
146+
color: Colors.transparent,
147+
width: 2,
148+
style: BorderStyle.solid),
149+
shape: RoundedRectangleBorder(
150+
borderRadius: BorderRadius.circular(20),
151+
),
152+
tapTargetSize: MaterialTapTargetSize.padded,
149153
),
150-
tapTargetSize: MaterialTapTargetSize.padded,
151-
),
152-
child: onTap == null
153-
? const Text(
154-
'Wait',
155-
style: TextStyle(
156-
color: Colors.white, fontSize: 25),
157-
)
158-
: const Text(
159-
'Cut',
160-
style: TextStyle(
161-
color: Colors.white, fontSize: 25),
162-
),
163-
);
164-
},
165-
),
154+
child: onTap == null
155+
? const Text(
156+
'Wait',
157+
style: TextStyle(
158+
color: Colors.white, fontSize: 25),
159+
)
160+
: const Text(
161+
'Cut',
162+
style: TextStyle(
163+
color: Colors.white, fontSize: 25),
164+
),
165+
);
166+
},
167+
),
168+
TapDebouncer(
169+
cooldown: const Duration(milliseconds: 100),
170+
onTap: () async => await setSensor(),
171+
builder:
172+
(BuildContext context, TapDebouncerFunc? onTap) {
173+
return ElevatedButton(
174+
onPressed: onTap,
175+
style: ElevatedButton.styleFrom(
176+
minimumSize: const Size(150, 55),
177+
primary: Colors.white38,
178+
onPrimary: Colors.black12,
179+
onSurface: Colors.red,
180+
shadowColor: Colors.black,
181+
elevation: 3,
182+
side: const BorderSide(
183+
color: Colors.transparent,
184+
width: 2,
185+
style: BorderStyle.solid),
186+
shape: RoundedRectangleBorder(
187+
borderRadius: BorderRadius.circular(20),
188+
),
189+
tapTargetSize: MaterialTapTargetSize.padded,
190+
),
191+
child: onTap == null
192+
? const Text(
193+
'Wait',
194+
style: TextStyle(
195+
color: Colors.white, fontSize: 25),
196+
)
197+
: const Text(
198+
'Set sensor',
199+
style: TextStyle(
200+
color: Colors.white, fontSize: 25),
201+
),
202+
);
203+
},
204+
),
205+
],
166206
),
167207
),
168208
NumericSetting(
@@ -272,4 +312,20 @@ class _QuickshifterWidgetState extends State<QuickshifterWidget> {
272312
Future<void> cutCommandCall() async {
273313
SerialPortUtils().cut();
274314
}
315+
316+
Future<void> setSensor() async {
317+
if (double.tryParse(SettingsRepository().sensorReading.value)! != 2000) {
318+
SettingsRepository().qsForce.value =
319+
(((double.tryParse(SettingsRepository().sensorReading.value)! > 2000)
320+
? 1
321+
: -1) *
322+
(double.tryParse(SettingsRepository().sensorReading.value)! -
323+
2000))
324+
.toString();
325+
SettingsRepository().pushCheckQS.value =
326+
(double.tryParse(SettingsRepository().sensorReading.value)! > 2000)
327+
? '0'
328+
: '1';
329+
}
330+
}
275331
}

0 commit comments

Comments
 (0)