Skip to content

Commit 1517e8d

Browse files
committed
Slider parameter changed
1 parent 255e6b5 commit 1517e8d

4 files changed

+28
-30
lines changed

src/BTSensorDrivePage.hpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Requires BlueDisplay library.
77
*
8-
* Copyright (C) 2016-2022 Armin Joachimsmeyer
8+
* Copyright (C) 2016-2025 Armin Joachimsmeyer
99
1010
*
1111
* This file is part of Arduino-RobotCar https://github.com/ArminJo/Arduino-RobotCar.
@@ -221,30 +221,30 @@ void initBTSensorDrivePage(void) {
221221
// Position Slider at middle of screen
222222
// Top/forward slider
223223
SliderForward.init(SENSOR_SLIDER_CENTER_X, (SENSOR_SLIDER_CENTER_Y - VERTICAL_SLIDER_LENTGH), SENSOR_SLIDER_WIDTH,
224-
VERTICAL_SLIDER_LENTGH, SLIDER_SPEED_THRESHOLD, 0, SLIDER_BACKGROUND_COLOR, SLIDER_BAR_COLOR, FLAG_SLIDER_IS_ONLY_OUTPUT, nullptr);
224+
VERTICAL_SLIDER_LENTGH, SLIDER_SPEED_THRESHOLD, 0, SLIDER_BACKGROUND_COLOR, SLIDER_BAR_COLOR, FLAG_SLIDER_IS_ONLY_OUTPUT);
225225

226226
// SliderForward.setBarThresholdColor(SLIDER_THRESHOLD_COLOR);
227227

228228
// Bottom/backward slider
229229
SliderBackward.init(SENSOR_SLIDER_CENTER_X, SENSOR_SLIDER_CENTER_Y, SENSOR_SLIDER_WIDTH, -(VERTICAL_SLIDER_LENTGH),
230-
SLIDER_SPEED_THRESHOLD, 0, SLIDER_BACKGROUND_COLOR, SLIDER_BAR_COLOR, FLAG_SLIDER_IS_ONLY_OUTPUT, nullptr);
230+
SLIDER_SPEED_THRESHOLD, 0, SLIDER_BACKGROUND_COLOR, SLIDER_BAR_COLOR, FLAG_SLIDER_IS_ONLY_OUTPUT);
231231

232232
// SliderBackward.setBarThresholdColor(SLIDER_THRESHOLD_COLOR);
233-
SliderForward.setScaleFactor((float) MAX_SPEED_PWM / (float) VERTICAL_SLIDER_LENTGH);
234-
SliderBackward.setScaleFactor((float) MAX_SPEED_PWM / (float) VERTICAL_SLIDER_LENTGH); // second expression is optimized by compiler :-)
233+
SliderForward.setMinMaxValue(0, MAX_SPEED_PWM);
234+
SliderBackward.setMinMaxValue(0, MAX_SPEED_PWM); // second expression is optimized by compiler :-)
235235
sAccelerationForwardBackwardSliders.positiveSliderPtr = &SliderForward;
236236
sAccelerationForwardBackwardSliders.negativeSliderPtr = &SliderBackward;
237237

238238
// Position slider right from at middle of screen
239239
SliderRight.init(SENSOR_SLIDER_CENTER_X + SENSOR_SLIDER_WIDTH, SENSOR_SLIDER_CENTER_Y - (SENSOR_SLIDER_WIDTH / 2),
240240
SENSOR_SLIDER_WIDTH, HORIZONTAL_SLIDER_LENTGH, SLIDER_LEFT_RIGHT_THRESHOLD, 0, SLIDER_BACKGROUND_COLOR, SLIDER_BAR_COLOR,
241-
FLAG_SLIDER_IS_HORIZONTAL | FLAG_SLIDER_IS_ONLY_OUTPUT | FLAG_SLIDER_SHOW_VALUE, nullptr);
241+
FLAG_SLIDER_IS_HORIZONTAL | FLAG_SLIDER_IS_ONLY_OUTPUT | FLAG_SLIDER_SHOW_VALUE);
242242
// SliderRight.setBarThresholdColor(SLIDER_THRESHOLD_COLOR);
243243

244244
// Position inverse slider left from at middle of screen
245245
SliderLeft.init(SENSOR_SLIDER_CENTER_X - HORIZONTAL_SLIDER_LENTGH, SENSOR_SLIDER_CENTER_Y - (SENSOR_SLIDER_WIDTH / 2),
246246
SENSOR_SLIDER_WIDTH, -(HORIZONTAL_SLIDER_LENTGH), SLIDER_LEFT_RIGHT_THRESHOLD, 0, SLIDER_BACKGROUND_COLOR,
247-
SLIDER_BAR_COLOR, FLAG_SLIDER_IS_HORIZONTAL | FLAG_SLIDER_IS_ONLY_OUTPUT | FLAG_SLIDER_SHOW_VALUE, nullptr);
247+
SLIDER_BAR_COLOR, FLAG_SLIDER_IS_HORIZONTAL | FLAG_SLIDER_IS_ONLY_OUTPUT | FLAG_SLIDER_SHOW_VALUE);
248248
// SliderLeft.setBarThresholdColor(SLIDER_THRESHOLD_COLOR);
249249
SliderRight.setScaleFactor(1.2);
250250
SliderLeft.setScaleFactor(1.2);

src/RobotCarCommonGui.hpp

+16-18
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* Requires BlueDisplay library.
1111
*
12-
* Copyright (C) 2016-2022 Armin Joachimsmeyer
12+
* Copyright (C) 2016-2025 Armin Joachimsmeyer
1313
1414
*
1515
* This file is part of Arduino-RobotCar https://github.com/ArminJo/Arduino-RobotCar.
@@ -57,7 +57,7 @@ uint8_t sRobotCarDirection = DIRECTION_FORWARD; // DIRECTION_FORWARD or DIRECTIO
5757
BDButton TouchButtonInfo;
5858

5959
BDSlider SliderSpeed;
60-
uint16_t sLastSpeedSliderValue = 0; // local storage for requested speed by speed slider
60+
int16_t sLastSpeedSliderValue = 0; // local storage for requested speed by speed slider
6161

6262
BDSlider SliderSpeedRight;
6363
BDSlider SliderSpeedLeft;
@@ -170,7 +170,7 @@ void readAndShowDistancePeriodically() {
170170
#endif // defined(CAR_HAS_DISTANCE_SENSOR)
171171

172172
#if defined(CAR_HAS_DISTANCE_SERVO)
173-
void doUSServoPosition(BDSlider *aTheTouchedSlider, uint16_t aValue) {
173+
void doUSServoPosition(BDSlider *aTheTouchedSlider, int16_t aValue) {
174174
(void) aTheTouchedSlider; // for the compiler to be happy
175175
DistanceServoWriteAndWaitForStop(aValue);
176176
}
@@ -300,7 +300,7 @@ void doCalibrate(BDButton *aTheTouchedButton, int16_t aValue) {
300300
* Minimum Speed is 30 for USB power and no load, 50 for load
301301
* Minimum Speed is 20 for 2 Lithium 18650 battery power and no load, 25 for load
302302
*/
303-
void doSpeedSlider(BDSlider *aTheTouchedSlider, uint16_t aValue) {
303+
void doSpeedSlider(BDSlider *aTheTouchedSlider, int16_t aValue) {
304304
if (aValue != sLastSpeedSliderValue) {
305305
sLastSpeedSliderValue = aValue;
306306

@@ -481,16 +481,15 @@ void initCommonGui() {
481481
*/
482482
SliderSpeed.init(0, SLIDER_TOP_MARGIN, BUTTON_WIDTH_6, SPEED_SLIDER_SIZE, 200, 0, COLOR16_YELLOW, SLIDER_DEFAULT_BAR_COLOR,
483483
FLAG_SLIDER_SHOW_VALUE, &doSpeedSlider);
484-
SliderSpeed.setScaleFactor(255.0 / SPEED_SLIDER_SIZE); // Slider is virtually 2 times larger than displayed, values were divided by 2
484+
SliderSpeed.setMinMaxValue(0, 255); // Slider is virtually 2 times larger than displayed, values were divided by 2
485485

486486
SliderSpeedLeft.init(MOTOR_INFO_START_X, 0, BUTTON_WIDTH_16, SPEED_SLIDER_SIZE / 2, SPEED_SLIDER_SIZE / 2 - 1, 0,
487-
SLIDER_DEFAULT_BACKGROUND_COLOR, SLIDER_DEFAULT_BAR_COLOR, FLAG_SLIDER_SHOW_VALUE | FLAG_SLIDER_IS_ONLY_OUTPUT,
488-
nullptr);
487+
SLIDER_DEFAULT_BACKGROUND_COLOR, SLIDER_DEFAULT_BAR_COLOR, FLAG_SLIDER_SHOW_VALUE | FLAG_SLIDER_IS_ONLY_OUTPUT);
489488
SliderSpeedLeft.setValueFormatString("%3d"); // Since we also send values grater 100
490489

491490
SliderSpeedRight.init(MOTOR_INFO_START_X + BUTTON_WIDTH_16 + 8, 0, BUTTON_WIDTH_16, SPEED_SLIDER_SIZE / 2,
492491
SPEED_SLIDER_SIZE / 2 - 1, 0, SLIDER_DEFAULT_BACKGROUND_COLOR, SLIDER_DEFAULT_BAR_COLOR,
493-
FLAG_SLIDER_SHOW_VALUE | FLAG_SLIDER_IS_ONLY_OUTPUT, nullptr);
492+
FLAG_SLIDER_SHOW_VALUE | FLAG_SLIDER_IS_ONLY_OUTPUT);
494493
SliderSpeedRight.setValueFormatString("%3d");
495494

496495
#if defined(CAR_HAS_DISTANCE_SENSOR)
@@ -520,7 +519,7 @@ void initCommonGui() {
520519
SliderDistanceServoPosition.init(POS_X_DISTANCE_POSITION_SLIDER - BUTTON_WIDTH_6, SLIDER_TOP_MARGIN, BUTTON_WIDTH_6,
521520
US_SLIDER_SIZE, 90, 90, COLOR16_YELLOW, SLIDER_DEFAULT_BAR_COLOR, FLAG_SLIDER_SHOW_VALUE, &doUSServoPosition);
522521
SliderDistanceServoPosition.setBarThresholdColor(COLOR16_BLUE);
523-
SliderDistanceServoPosition.setScaleFactor(180.0 / US_SLIDER_SIZE); // Values from 0 to 180 degrees
522+
SliderDistanceServoPosition.setMinMaxValue(0, 180); // Values from 0 to 180 degrees
524523
SliderDistanceServoPosition.setValueUnitString("\xB0"); // \xB0 is degree character
525524
#endif
526525

@@ -535,7 +534,7 @@ void initCommonGui() {
535534
SliderUSDistance.init(POS_X_US_DISTANCE_SLIDER - ((BUTTON_WIDTH_10 / 2) - 2), SLIDER_TOP_MARGIN + BUTTON_HEIGHT_8,
536535
(BUTTON_WIDTH_10 / 2) - 2, DISTANCE_SLIDER_SIZE,
537536
FOLLOWER_DISPLAY_DISTANCE_TIMEOUT_CENTIMETER / DISTANCE_SLIDER_SCALE_FACTOR, 0, SLIDER_DEFAULT_BACKGROUND_COLOR,
538-
SLIDER_DEFAULT_BAR_COLOR, FLAG_SLIDER_SHOW_VALUE | FLAG_SLIDER_IS_ONLY_OUTPUT, nullptr);
537+
SLIDER_DEFAULT_BAR_COLOR, FLAG_SLIDER_SHOW_VALUE | FLAG_SLIDER_IS_ONLY_OUTPUT);
539538
SliderUSDistance.setCaptionProperties(TEXT_SIZE_10, FLAG_SLIDER_VALUE_CAPTION_ALIGN_LEFT | FLAG_SLIDER_VALUE_CAPTION_BELOW, 2,
540539
COLOR16_BLACK, COLOR16_WHITE);
541540
SliderUSDistance.setCaption("US");
@@ -546,8 +545,7 @@ void initCommonGui() {
546545
// Big US distance slider without caption but with cm units POS_X_THIRD_SLIDER because it is the position of the left edge
547546
SliderUSDistance.init(POS_X_US_DISTANCE_SLIDER - BUTTON_WIDTH_10, SLIDER_TOP_MARGIN + BUTTON_HEIGHT_8, BUTTON_WIDTH_10,
548547
DISTANCE_SLIDER_SIZE, FOLLOWER_DISPLAY_DISTANCE_TIMEOUT_CENTIMETER / DISTANCE_SLIDER_SCALE_FACTOR, 0,
549-
SLIDER_DEFAULT_BACKGROUND_COLOR, SLIDER_DEFAULT_BAR_COLOR, FLAG_SLIDER_SHOW_VALUE | FLAG_SLIDER_IS_ONLY_OUTPUT,
550-
nullptr);
548+
SLIDER_DEFAULT_BACKGROUND_COLOR, SLIDER_DEFAULT_BAR_COLOR, FLAG_SLIDER_SHOW_VALUE | FLAG_SLIDER_IS_ONLY_OUTPUT);
551549
SliderUSDistance.setValueUnitString("cm");
552550
#endif
553551
SliderUSDistance.setScaleFactor(DISTANCE_SLIDER_SCALE_FACTOR); // Slider is virtually 2 times larger, values were divided by 2
@@ -561,7 +559,7 @@ void initCommonGui() {
561559
SliderIROrTofDistance.init(POS_X_THIRD_SLIDER - ((BUTTON_WIDTH_10 / 2) - 2), SLIDER_TOP_MARGIN + BUTTON_HEIGHT_8,
562560
(BUTTON_WIDTH_10 / 2) - 2, DISTANCE_SLIDER_SIZE,
563561
FOLLOWER_DISPLAY_DISTANCE_TIMEOUT_CENTIMETER / DISTANCE_SLIDER_SCALE_FACTOR, 0, SLIDER_DEFAULT_BACKGROUND_COLOR,
564-
SLIDER_DEFAULT_BAR_COLOR, FLAG_SLIDER_SHOW_VALUE | FLAG_SLIDER_IS_ONLY_OUTPUT, nullptr);
562+
SLIDER_DEFAULT_BAR_COLOR, FLAG_SLIDER_SHOW_VALUE | FLAG_SLIDER_IS_ONLY_OUTPUT);
565563
SliderIROrTofDistance.setScaleFactor(DISTANCE_SLIDER_SCALE_FACTOR); // Slider is virtually 2 times larger, values were divided by 2
566564
SliderIROrTofDistance.setBarThresholdColor(DISTANCE_TIMEOUT_COLOR);
567565
// Caption properties
@@ -576,20 +574,20 @@ void initCommonGui() {
576574

577575
#if defined(CAR_HAS_PAN_SERVO)
578576
// left of SliderDistanceServoPosition
579-
SliderPan.init(POS_X_PAN_SLIDER - BUTTON_WIDTH_12, SLIDER_TOP_MARGIN, BUTTON_WIDTH_12, LASER_SLIDER_SIZE, 90, 90, COLOR16_YELLOW,
580-
SLIDER_DEFAULT_BAR_COLOR, FLAG_SLIDER_SHOW_VALUE, &doHorizontalServoPosition);
577+
SliderPan.init(POS_X_PAN_SLIDER - BUTTON_WIDTH_12, SLIDER_TOP_MARGIN, BUTTON_WIDTH_12, LASER_SLIDER_SIZE, 90, 90,
578+
COLOR16_YELLOW, SLIDER_DEFAULT_BAR_COLOR, FLAG_SLIDER_SHOW_VALUE, &doHorizontalServoPosition);
581579
SliderPan.setBarThresholdColor(COLOR16_BLUE);
582580
// scale slider values
583-
SliderPan.setScaleFactor(180.0 / LASER_SLIDER_SIZE); // Values from 0 to 180 degrees
581+
SliderPan.setMinMaxValue(0, 180); // Values from 0 to 180 degrees
584582
SliderPan.setValueUnitString("\xB0"); // \xB0 is degree character
585583
#endif
586584

587585
#if defined(CAR_HAS_TILT_SERVO)
588586
SliderTilt.init(POS_X_TILT_SLIDER - BUTTON_WIDTH_12, SLIDER_TOP_MARGIN, BUTTON_WIDTH_12, LASER_SLIDER_SIZE, 90,
589-
TILT_SERVO_MIN_VALUE, COLOR16_YELLOW, SLIDER_DEFAULT_BAR_COLOR, FLAG_SLIDER_SHOW_VALUE, &doVerticalServoPosition);
587+
TILT_SERVO_MIN_VALUE, COLOR16_YELLOW, SLIDER_DEFAULT_BAR_COLOR, FLAG_SLIDER_SHOW_VALUE, &doVerticalServoPosition);
590588
SliderTilt.setBarThresholdColor(COLOR16_BLUE);
591589
// scale slider values
592-
SliderTilt.setScaleFactor(180.0 / LASER_SLIDER_SIZE); // Values from 0 to 180 degrees
590+
SliderTilt.setMinMaxValue(0, 180); // Values from 0 to 180 degrees
593591
SliderTilt.setValueUnitString("\xB0"); // \xB0 is degree character
594592
#endif
595593

src/RobotCarGui.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ extern bool sPlayMelody;
132132
extern bool sEnableDemo;
133133
#endif
134134

135-
extern void doHorizontalServoPosition(BDSlider *aTheTouchedSlider, uint16_t aValue);
136-
extern void doVerticalServoPosition(BDSlider *aTheTouchedSlider, uint16_t aValue);
135+
extern void doHorizontalServoPosition(BDSlider *aTheTouchedSlider, int16_t aValue);
136+
extern void doVerticalServoPosition(BDSlider *aTheTouchedSlider, int16_t aValue);
137137

138138
void initHomePage(void);
139139
void drawHomePage(void);
@@ -181,7 +181,7 @@ extern BDButton TouchButtonCompensationStore;
181181
#endif
182182

183183
extern BDSlider SliderSpeed;
184-
extern uint16_t sLastSpeedSliderValue;
184+
extern int16_t sLastSpeedSliderValue;
185185
void showSpeedSliderValue();
186186

187187
extern BDSlider SliderSpeedRight;

src/RobotCarHomePage.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ BDSlider SliderTilt;
4646

4747
// Here we get values from 0 to 180 degrees from scaled slider
4848
#if defined(CAR_HAS_PAN_SERVO)
49-
void doHorizontalServoPosition(BDSlider *aTheTouchedSlider, uint16_t aValue) {
49+
void doHorizontalServoPosition(BDSlider *aTheTouchedSlider, int16_t aValue) {
5050
PanServo.write(aValue);
5151
}
5252
#endif
5353

5454
#if defined(CAR_HAS_TILT_SERVO)
55-
void doVerticalServoPosition(BDSlider *aTheTouchedSlider, uint16_t aValue) {
55+
void doVerticalServoPosition(BDSlider *aTheTouchedSlider, int16_t aValue) {
5656
TiltServo.write(aValue);
5757
}
5858
#endif

0 commit comments

Comments
 (0)