Skip to content

Instantly share code, notes, and snippets.

@victorypoint
Last active November 4, 2024 23:47
Show Gist options
  • Save victorypoint/910841034f933b01692bc69390def539 to your computer and use it in GitHub Desktop.
Save victorypoint/910841034f933b01692bc69390def539 to your computer and use it in GitHub Desktop.
Test batch sequence of inclines with iFit2 auto-incline control of treadmill via ADB
' iFit2-Incline-Batch - Test batch sequence of inclines with iFit2 auto-incline 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 incline
inclineButtons = Array(-3, 0, 1, 2, 4, 6, 8, 10, 12, 15)
' Define button parameters
inclineX = 114 ' x position of middle of incline 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 inclines
'arrInclines = Array(2, 4.5, -3, 9, 15, -1.5, 5, 5.5, 6, 6.5, 7, 0, "end")
arrInclines = Array(-3, 0, 1, 2, 4, 6, 8, 10, 12, 15, 12, 10, 8, 6, 4, 2, 1, 0, -3, "end")
'arrInclines = Array(-3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, "end")
' Loop through each target incline
For Each targetIncline In arrInclines
If targetIncline = "end" Then WScript.Quit
targetIncline = CDbl(targetIncline)
' Initialize variables for finding the closest incline
closestIncline = inclineButtons(0)
minInclineDifference = Abs(targetIncline - inclineButtons(0))
closestInclineIndex = 0
' Loop through the incline buttons to find the closest incline
For i = 1 To UBound(inclineButtons)
currentInclineDifference = Abs(targetIncline - inclineButtons(i))
If currentInclineDifference < minInclineDifference Then
minInclineDifference = currentInclineDifference
closestIncline = inclineButtons(i)
closestInclineIndex = i
End If
Next
' Calculate pixel location for center of the closest incline button
If (closestInclineIndex + 1) > buttonCount Then
inclineY = Round(buttonBottomY - (buttonSpacingY * closestInclineIndex) + swipeShift) ' Center y-coordinate of the incline button
Else
inclineY = Round(buttonBottomY - (buttonSpacingY * closestInclineIndex)) ' Center y-coordinate of the incline button
End If
' Process incline swipe for button visibility
If buttonCount <> 10 Then
If (closestInclineIndex + 1) > buttonCount Then
cmdString = "adb shell input swipe " & inclineX & " " & buttonTopY & " " & inclineX & " " & (buttonTopY + swipeAmount) & " " & swipeSpeed ' Swipe down
Else
cmdString = "adb shell input swipe " & inclineX & " " & buttonBottomY & " " & inclineX & " " & (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 "Incline swipe: " & cmdString
End If
' Process incline button click
cmdString = "adb shell input tap " & inclineX & " " & inclineY
'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 incline: " & closestIncline & ", " & cmdString
Next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment