2020-09-22 23:27:53 +00:00
|
|
|
#!/usr/bin/env python
|
2020-09-29 20:40:10 +00:00
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
Improved dac.py and talk.py (by Jacob Potter). Pimped by Sam Neurohack.
|
|
|
|
|
|
|
|
- python3
|
|
|
|
- works with nannou visualisers
|
|
|
|
- can talk to a given etherdream knowing it's IP.
|
|
|
|
|
|
|
|
v0.1.0
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
2020-09-22 23:27:53 +00:00
|
|
|
#
|
|
|
|
# j4cDAC test code
|
|
|
|
#
|
|
|
|
# Copyright 2011 Jacob Potter
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, version 3.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import dac3 as dac
|
2020-09-29 20:40:10 +00:00
|
|
|
import argparse
|
|
|
|
import sys
|
|
|
|
|
|
|
|
argsparser = argparse.ArgumentParser(description="Draw a square on a laser via Etherdream DAC")
|
|
|
|
|
2020-09-29 22:15:40 +00:00
|
|
|
argsparser.add_argument("-i","--ip",help="Etherdream IP (default : first etherdream broadcast received)",default="True",type=str)
|
2020-09-29 20:40:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
args = argsparser.parse_args()
|
|
|
|
etherIP = args.ip
|
|
|
|
|
|
|
|
|
2020-09-22 23:27:53 +00:00
|
|
|
|
|
|
|
class SquarePointStream(object):
|
|
|
|
'''
|
|
|
|
def produce(self):
|
|
|
|
pmax = 15600
|
|
|
|
pstep = 100
|
|
|
|
cmax = 65535
|
|
|
|
while True:
|
|
|
|
for x in xrange(-pmax, pmax, pstep):
|
|
|
|
yield (x, pmax, cmax, 0, 0, cmax)
|
|
|
|
for y in xrange(pmax, -pmax, -pstep):
|
|
|
|
yield (pmax, y, 0, cmax, 0, cmax)
|
|
|
|
for x in xrange(pmax, -pmax, -pstep):
|
|
|
|
yield (x, -pmax, 0, 0, cmax, cmax)
|
|
|
|
for y in xrange(-pmax, pmax, pstep):
|
|
|
|
yield (-pmax, y, cmax, cmax, cmax, cmax)
|
|
|
|
'''
|
|
|
|
|
|
|
|
def produce(self):
|
|
|
|
|
|
|
|
pmax = 15600
|
|
|
|
pstep = 100
|
|
|
|
Cmax = 65535
|
|
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
|
|
|
print("Cmax:",Cmax)
|
|
|
|
|
|
|
|
for x in range(-pmax, pmax, pstep):
|
|
|
|
|
|
|
|
yield (x, pmax, Cmax, 0, 0) # pure Red
|
|
|
|
#yield (x, pmax, 0, Cmax, 0) # pure Green
|
|
|
|
#yield (x, pmax, 0, 0, Cmax) # pure Blue
|
|
|
|
#yield (x, pmax, Cmax, Cmax, Cmax) # pure White
|
|
|
|
|
|
|
|
|
|
|
|
for y in range(pmax, -pmax, -pstep):
|
|
|
|
|
|
|
|
#yield (pmax, y, Cmax, 0, 0) # pure Red
|
|
|
|
yield (pmax, y, 0, Cmax, 0) # pure Green
|
|
|
|
#yield (pmax, y, 0, 0, Cmax) # pure Blue
|
|
|
|
#yield (pmax, y, Cmax, Cmax, Cmax) # pure White
|
|
|
|
|
|
|
|
for x in range(pmax, -pmax, -pstep):
|
|
|
|
#yield (x, -pmax, Cmax, 0, 0) # pure Red
|
|
|
|
#yield (x, -pmax, 0, Cmax, 0) # pure Green
|
|
|
|
yield (x, -pmax, 0, 0, Cmax) # pure Blue
|
|
|
|
#yield (x, -pmax, Cmax, Cmax, Cmax) # pure White
|
|
|
|
|
|
|
|
|
|
|
|
for y in range(-pmax, pmax, pstep):
|
|
|
|
#yield (-pmax, y, Cmax, 0, 0) # pure Red
|
|
|
|
#yield (-pmax, y,0, Cmax, 0) # pure Green
|
|
|
|
#yield (-pmax, y, 0, 0, Cmax) # pure Blue
|
|
|
|
yield (-pmax, y, Cmax, Cmax, Cmax) # pure White
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.stream = self.produce()
|
|
|
|
|
|
|
|
def read(self, n):
|
|
|
|
return [next(self.stream) for i in range(n)]
|
|
|
|
|
|
|
|
class NullPointStream(object):
|
|
|
|
def read(self, n):
|
|
|
|
return [(0, 0, 0, 0, 0)] * n
|
|
|
|
|
|
|
|
#dac.find_dac()
|
2020-09-29 20:40:10 +00:00
|
|
|
if etherIP == "True":
|
|
|
|
print("Waiting for the first DAC broadcast...")
|
|
|
|
d = dac.DAC(dac.find_first_dac())
|
|
|
|
|
|
|
|
else:
|
|
|
|
print("Using Etherdream :", etherIP)
|
|
|
|
d = dac.DAC(etherIP)
|
2020-09-22 23:27:53 +00:00
|
|
|
|
|
|
|
|
2020-09-29 20:40:10 +00:00
|
|
|
print("Sending points...")
|
2020-09-22 23:27:53 +00:00
|
|
|
d.play_stream(SquarePointStream())
|