forked from mirror/joycontrol
fixed frequency bytes
This commit is contained in:
+17
-4
@@ -272,16 +272,29 @@ class OutputReport:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _encode_rumble_data(freq, amp):
|
def _encode_rumble_data(freq, amp):
|
||||||
if not 0 <= freq <= 1252:
|
# TODO: Fix LA Byte 2
|
||||||
raise ValueError('Frequency must be in [0, 1252].')
|
|
||||||
|
if not (40 <= freq <= 1253):
|
||||||
|
raise ValueError('Frequency must be in [40, 1253].')
|
||||||
|
|
||||||
|
if amp > 1.003:
|
||||||
|
raise ValueError('Amplitudes higher than 1.003 are not safe '
|
||||||
|
'for the integrity of the linear resonant actuators')
|
||||||
|
|
||||||
# Float frequency to hex conversion
|
# Float frequency to hex conversion
|
||||||
encoded_hex_freq = int(round(math.log2(freq / 10) * 32))
|
encoded_hex_freq = int(round(math.log2(freq / 10) * 32))
|
||||||
|
|
||||||
# Convert to Joy-Con HF range. Range in big-endian: 0x0004-0x01FC with +0x0004 steps.
|
# Convert to Joy-Con HF range. Range in big-endian: 0x0004-0x01FC with +0x0004 steps.
|
||||||
hf = (encoded_hex_freq - 0x60) * 4
|
if freq <= 80:
|
||||||
|
hf = 0x00
|
||||||
|
else:
|
||||||
|
hf = (encoded_hex_freq - 0x60) * 4
|
||||||
|
|
||||||
# Convert to Joy-Con LF range. Range: 0x01-0x7F.
|
# Convert to Joy-Con LF range. Range: 0x01-0x7F.
|
||||||
lf = encoded_hex_freq - 0x40
|
if freq >= 640:
|
||||||
|
lf = 0x00
|
||||||
|
else:
|
||||||
|
lf = encoded_hex_freq - 0x40
|
||||||
|
|
||||||
# Float amplitude to hex conversion
|
# Float amplitude to hex conversion
|
||||||
encoded_hex_amp = 0
|
encoded_hex_amp = 0
|
||||||
|
|||||||
+18
-12
@@ -50,21 +50,22 @@ async def send_vibration_report(hid_device):
|
|||||||
await hid_device.write(bytes(data))
|
await hid_device.write(bytes(data))
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
|
|
||||||
|
octave = [261.63, 293.66, 329.63, 349.23, 392.00, 440.00, 493.88, 523.25]
|
||||||
|
octave = [int(round(n)) for n in octave]
|
||||||
|
|
||||||
time = 2
|
time = 2
|
||||||
while True:
|
while True:
|
||||||
for i in range(10):
|
rumble_report = OutputReport()
|
||||||
rumble_report = OutputReport()
|
report.set_timer(time)
|
||||||
report.set_timer(time)
|
time += 1
|
||||||
time += 1
|
rumble_report.set_output_report_id(OutputReportID.RUMBLE_ONLY)
|
||||||
rumble_report.set_output_report_id(OutputReportID.RUMBLE_ONLY)
|
# increase frequency
|
||||||
# increase frequency
|
rumble_report.set_right_rumble_data(octave[time % len(octave)], 1)
|
||||||
rumble_report.set_right_rumble_data(100 + i * 100, 1)
|
data = bytes(rumble_report)[1:]
|
||||||
data = bytes(rumble_report)[1:]
|
print('writing', data)
|
||||||
print('writing', data)
|
await hid_device.write(bytes(data))
|
||||||
await hid_device.write(bytes(data))
|
|
||||||
|
|
||||||
await asyncio.sleep(.5)
|
await asyncio.sleep(.2)
|
||||||
break
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await reader
|
await reader
|
||||||
@@ -89,6 +90,11 @@ if __name__ == '__main__':
|
|||||||
if not os.geteuid() == 0:
|
if not os.geteuid() == 0:
|
||||||
raise PermissionError('Script must be run as root!')
|
raise PermissionError('Script must be run as root!')
|
||||||
|
|
||||||
|
# h = lambda bla: list(map(hex, bla))
|
||||||
|
# report = OutputReport()
|
||||||
|
# report.set_left_rumble_data(1253, 0.012)
|
||||||
|
# exit()
|
||||||
|
|
||||||
# setup logging
|
# setup logging
|
||||||
log.configure()
|
log.configure()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user