Move coordinate scaling from app to controller

- joystick.cpp/hpp:
  - move method scaleCoordinate from joystick class to public function
  - modify scaleCoordinate function to accept float values instead of
    ADC pin, change tolerance parameters to percent instead of absolute
    number
  - change method getData to use the public function now

- control.cpp:
  - use scaleCoordinate function in http mode
  - calculate radius in http mode

- config.cpp
  - adjust tolerance thresholds for joystick to percent

- App.js
  - disable "snap to zero" feature -> just scale joystick output to
    value of -1 to 1
This commit is contained in:
jonny_ji7
2022-06-19 15:37:42 +02:00
parent 0165a88f1f
commit 20873b4175
5 changed files with 116 additions and 72 deletions

21
react-app/src/App.js vendored
View File

@@ -33,7 +33,7 @@ function App() {
// - snaps 0 zero for a given tolerance in percent
// - rounds value do given decimal places
// - TODO: add threshold it snaps to 1 / -1 (100%) toleranceEnd
const ScaleCoordinate = (input) => {
const ScaleCoordinateTolerance = (input) => {
//calc tolerance threshold and available range
const tolerance = joystickSize/2 * toleranceSnapToZeroPer/100;
const range = joystickSize/2 - tolerance;
@@ -61,6 +61,15 @@ function App() {
//----------------------------------------
//----------- Scale coordinate -----------
//----------------------------------------
//simply scale coordinate from joystick to a value of -1 to 1 without applying any tolerances
const ScaleCoordinate = (input) => {
return ( input / (joystickSize/2) ).toFixed(decimalPlaces);
}
//-------------------------------------------
//------- Senda data via POST request -------
@@ -106,13 +115,19 @@ function App() {
//evaluate coordinates and send to esp32
const handleMove = (e) => {
//console.log("data from joystick-element X:" + e.x + " Y:" + e.y + " distance:" + e.distance);
//calculate needed variables
//--- convert coordinates ---
//Note: tolerance (snap to zero) now handled by controller -> send raw coordinates
//const x = ScaleCoordinateTolerance(e.x);
//const y = ScaleCoordinateTolerance(e.y);
const x = ScaleCoordinate(e.x);
const y = ScaleCoordinate(e.y);
//--- scale radius ---
const radius = (e.distance / 100).toFixed(5);
//--- calculate angle ---
const angle = ( Math.atan( y / x ) * 180 / Math.PI ).toFixed(2);
//crate object with necessary data
//create object with necessary data
const joystick_data={
x: x,
y: y,