Skip to content

Instantly share code, notes, and snippets.

@pratimugale
Created July 24, 2019 02:44
Show Gist options
  • Save pratimugale/875def7870a9d170d0980091a864289c to your computer and use it in GitHub Desktop.
Save pratimugale/875def7870a9d170d0980091a864289c to your computer and use it in GitHub Desktop.
# this program function must be added to the prussd.py daemon and then a seperate userspace program will be written in cpp
import struct
'''frequency = input("Frequency of PWM in Hz (from 1Hz to 1Mhz): ")
multiplier = 1000000.0/frequency
duty_cycle = input("Duty Cycle of PWM ")
on_samples = duty_cycle * 100
total_samples = 100
on_samples *= multiplier
total_samples *= multiplier
print("On cycles: ", int(on_samples))
print("Total cycles: ", int(total_samples))
data = [int(on_samples), int(total_samples), 4, 124, 100, 123, 11, 11]'''
data = [101, 201, 100, 123, 11, 11, 124, 31, 2]
if isinstance(data[0], int):
with open('/dev/rpmsg_pru31', 'wb') as f:
f.write(struct.pack('>'+('B'*len(data)), *data))
f.close()
elif isinstance(data[0], str):
with open('/dev/rpmsg_pru31', 'w') as f:
f.write(data)
f.close()
else:
raise TypeError('Can only write string or int')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment