Last active
November 4, 2024 23:48
-
-
Save victorypoint/630255e525360a20e1d9f56e7c63f507 to your computer and use it in GitHub Desktop.
Test batch sequence of speeds with iFit2 auto-speed control of treadmill via ADB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' iFit2-Speed-Batch - Test batch sequence of speeds with iFit2 auto-speed control of treadmill via ADB | |
' Author: Al Udell | |
' Revised: November 4, 2024 | |
' To debug - enable wscript.echo and run by cscript in command line | |
' On error resume next | |
' Initialize | |
set wso = createobject("wscript.shell") | |
buttonCount = 8 ' number of displayed buttons | |
swipeAmount = 400 ' y swipe amount | |
swipeSpeed = 300 ' swipe speed in ms | |
' *** Start - NordicTrack C2950 Treadmill *** | |
' Define button arrays for speed | |
speedButtons = Array(2, 3, 4, 6, 8, 10, 12, 14, 16, 19) | |
minSpeed = 1 | |
maxSpeed = 19.3 | |
' Define button parameters | |
speedX = 1808 ' x position of middle of speed buttons | |
' Define button positions and layout | |
Select Case buttonCount | |
Case 10 | |
buttonBottomY = 977 ' y position of middle of bottom button (swipe up) | |
swipeBottomY = 0 ' y position of middle of bottom button (swipe down) | |
buttonTopY = 186 ' y position of middle of top button (swipe up) | |
swipeShift = 0 ' y button shift for swipe | |
Case 9 | |
buttonBottomY = 915 | |
swipeBottomY = 889 | |
buttonTopY = 211 | |
swipeShift = 63 | |
Case 8 | |
buttonBottomY = 827 | |
swipeBottomY = 801 | |
buttonTopY = 212 | |
swipeShift = 150 | |
Case 7 | |
buttonBottomY = 752 | |
swipeBottomY = 714 | |
buttonTopY = 227 | |
swipeShift = 225 | |
Case 6 | |
buttonBottomY = 672 | |
swipeBottomY = 625 | |
buttonTopY = 233 | |
swipeShift = 305 | |
End Select | |
' *** End - NordicTrack C2950 Treadmill *** | |
buttonSpacingY = (buttonBottomY - buttonTopY) / (buttonCount - 1) ' vertical spacing between buttons | |
' Define batch sequence of speeds | |
'arrSpeeds = Array(9, 14, 4, 6, 12, 3, 11, 5, 9, 7, 19, 2, 14, 8, 3, 13, 4, 2, "end") | |
arrSpeeds = Array(2, 3, 4, 6, 8, 10, 12, 14, 16, 19, 16, 14, 12, 10, 8, 6, 4, 3, 2, "end") | |
'arrSpeeds = Array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, "end") | |
' Loop through each target speed | |
For Each targetSpeed In arrSpeeds | |
If targetSpeed = "end" Then WScript.Quit | |
targetSpeed = CDbl(targetSpeed) | |
' Initialize variables for finding the closest speed | |
closestSpeed = speedButtons(0) | |
minSpeedDifference = Abs(targetSpeed - speedButtons(0)) | |
closestSpeedIndex = 0 | |
' Loop through the speed buttons to find the closest speed | |
For i = 1 To UBound(speedButtons) | |
currentSpeedDifference = Abs(targetSpeed - speedButtons(i)) | |
If currentSpeedDifference < minSpeedDifference Then | |
minSpeedDifference = currentSpeedDifference | |
closestSpeed = speedButtons(i) | |
closestSpeedIndex = i | |
End If | |
Next | |
' Calculate pixel location for center of the closest speed button | |
If (closestSpeedIndex + 1) > buttonCount Then | |
speedY = Round(buttonBottomY - (buttonSpacingY * closestSpeedIndex) + swipeShift) ' Center y-coordinate of the speed button | |
Else | |
speedY = Round(buttonBottomY - (buttonSpacingY * closestSpeedIndex)) ' Center y-coordinate of the speed button | |
End If | |
' Process speed swipe for button visibility | |
If buttonCount <> 10 Then | |
If (closestSpeedIndex + 1) > buttonCount Then | |
cmdString = "adb shell input swipe " & speedX & " " & buttonTopY & " " & speedX & " " & (buttonTopY + swipeAmount) & " " & swipeSpeed ' Swipe down | |
Else | |
cmdString = "adb shell input swipe " & speedX & " " & buttonBottomY & " " & speedX & " " & (buttonBottomY - swipeAmount) & " " & swipeSpeed ' Swipe up | |
End If | |
'use synchronous exec | |
set oexec = wso.exec("cmd /c " & cmdstring) ' Execute adb command | |
'wait for completion | |
Do While oexec.Status = 0 | |
wscript.sleep 100 | |
Loop | |
sValue = oexec.stdout.readline | |
wscript.echo "Speed swipe: " & cmdString | |
End If | |
' Process speed button click | |
cmdString = "adb shell input tap " & speedX & " " & speedY | |
'use synchronous exec | |
set oexec = wso.exec("cmd /c " & cmdstring) ' Execute adb command | |
'wait for completion | |
Do While oexec.Status = 0 | |
wscript.sleep 100 | |
Loop | |
sValue = oexec.stdout.readline | |
wscript.echo "Target speed: " & closestSpeed & ", " & cmdString | |
Next |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment