Page 1 of 1

gamepad alternative

Posted: Thu Nov 26, 2020 8:43 pm
by charliex
i noticed i wasn't able to use the analog sticks etc in my gamepad with the existing code, so i started to throw together an alternative, trying to make it so it inserts easily and i haven't played around with the scaling, added a few ways of dead zone and enumeration(mostly from msdn) just call myjoyGetPosEx instead of joyGetPosEx ... bec0b3d205

still have to work to do with it, but figured maybe its useful for others wanting to do the same as starting point

Like I added a feature where the left trigger can scale the feed rate. joyGetPosEx doesn't have features for the other sticks so it can't be a basic func replacement.

i wouldn't cut and paste this without some testing.

Code: Select all

// Triggers return 0 - 255
				if (!FirstFeedRateLow && (state.Gamepad.bLeftTrigger) == 0)
					SetDlgItemText(IDC_FeedRateEdit, OrigFeedRate);
					PostMessage(WM_COMMAND, IDC_FeedRateApply);
					FirstFeedRateLow = true;
				else if (state.Gamepad.bLeftTrigger) {

					if (FirstFeedRateLow) {
						// remember what it was.
						GetDlgItemText(IDC_FeedRateEdit, OrigFeedRate);

					FirstFeedRateLow = false;

					CString tRate;

					//convert from 0 - 255 to 0 - 1.0f
					float rate = (1.0f / 255.0f) * float(255 - state.Gamepad.bLeftTrigger);

					// snapping back the trigger will miss the last conversion.

					// slight dead zones
					rate = max(0.1f, rate);

					// when let it it'll reset to original feed rate anyway.
					///if (rate > 0.94f) rate = 1.0f;

					tRate.Format("%0.02f", rate);

					SetDlgItemText(IDC_FeedRateEdit, tRate);
					PostMessage(WM_COMMAND, IDC_FeedRateApply);