Changeset - 2239d5648932
[Not reviewed]
default
0 3 0
Drew Perttula - 8 years ago 2017-05-30 07:57:52
drewp@bigasterisk.com
captureDevice saves all pics
Ignore-this: eae0e07b8f6d4a9b719a1193830f866

it used to drop the last one
3 files changed with 42 insertions and 31 deletions:
0 comments (0 inline, 0 general)
bin/captureDevice
Show inline comments
 
@@ -46,11 +46,15 @@ class Camera(object):
 
            out.write(jpg)
 
        log.info('wrote %s', writePath)
 

	
 
def deferSleep(sec):
 
    d = Deferred()
 
    reactor.callLater(sec, d.callback, None)
 
    return d
 

	
 
class Capture(object):
 
    firstMoveTime = 5
 
    firstMoveTime = 3
 
    settleTime = .5
 
    def __init__(self, graph):
 
    def __init__(self, graph, dev):
 
        self.graph = graph
 
        
 
        def steps(a, b, n):
 
@@ -61,52 +65,55 @@ class Capture(object):
 
        self.toGather = []
 

	
 
        row = 0
 
        for ry in steps(0.85, .92, 6):
 
            xSteps = steps(.24, .45, 12)
 
        for ry in steps(0.82, .92, 6):
 
            xSteps = steps(.23, .42, 12)
 
            if row % 2:
 
                xSteps.reverse()
 
            row += 1
 
            for rx in xSteps:
 
                self.toGather.append(DeviceSettings(graph, [
 
                    (L9['device/moving1'], L9['rx'], rx),
 
                    (L9['device/moving1'], L9['ry'], ry),
 
                    (dev, L9['rx'], rx),
 
                    (dev, L9['ry'], ry),
 
                    (dev, L9['color'], '#ffffff'),
 
                ]))
 

	
 
        self.numPics = 0
 
        self.settingsCache = set()
 
        self.step().addErrback(log.error)
 
        
 
    def off(self):
 
        return sendToCollector(client='captureDevice', session='main',
 
                               settings=DeviceSettings(self.graph, []))
 
        
 
    @inlineCallbacks
 
    def step(self):
 
        if not self.toGather:
 
            yield self.off()
 
            yield deferSleep(1)
 
            reactor.stop()
 
            return
 
        settings = self.toGather.pop()
 
        
 
        log.info('move to %r', settings)
 
        yield sendToCollector(client='captureDevice', session='main', settings=settings)
 
        log.info('[%s left] move to %r', len(self.toGather), settings)
 
        yield sendToCollector(client='captureDevice', session='main',
 
                              settings=settings)
 
        
 
        d = Deferred()
 
        reactor.callLater(self.firstMoveTime if self.numPics == 0 else self.settleTime,
 
                          d.callback, None)
 
        yield d
 
        dev = settings.devices()[0]
 

	
 
        devTail = dev.rsplit('/')[-1]
 
        yield deferSleep(self.firstMoveTime if self.numPics == 0 else
 
                         self.settleTime)
 
        
 
        dev = settings.devices()[0]
 
        devTail = dev.rsplit('/')[-1]
 
        picId = 'pic%s' % self.numPics
 
        path = '/'.join(['capture', devTail, self.captureId, picId])
 
        ctx = URIRef('/'.join([showconfig.showUri(), 'capture', devTail, self.captureId,
 
                               'index']))
 
        uri = URIRef('/'.join([showconfig.showUri(), 'capture', devTail, self.captureId,
 
                               picId]))
 
        path = '/'.join(['capture', devTail, self.captureId, picId]) + '.jpg'
 
        ctx = URIRef('/'.join([showconfig.showUri(),
 
                               'capture', devTail, self.captureId, 'index']))
 
        uri = URIRef('/'.join([showconfig.showUri(),
 
                               'capture', devTail, self.captureId, picId]))
 
                     
 
        relOutPath = path + '.jpg'
 
        
 
        yield camera.takePic(uri, os.path.join(showconfig.root(), relOutPath))
 
        yield camera.takePic(uri, os.path.join(showconfig.root(), path))
 
        self.numPics += 1
 

	
 
        writeCaptureDescription(self.graph, ctx, uri, dev, relOutPath,
 
        writeCaptureDescription(self.graph, ctx, uri, dev, path,
 
                                self.settingsCache, settings)
 
        
 
        reactor.callLater(0, self.step)
 
@@ -123,7 +130,7 @@ class Attrs(PrettyErrorHandler, cyclone.
 

	
 
def launch(graph):
 

	
 
    cap = Capture(graph)
 
    cap = Capture(graph, dev=L9['device/moving1'])
 
    reactor.listenTCP(networking.captureDevice.port,
 
                      cyclone.web.Application(handlers=[
 
                          (r'/()', cyclone.web.StaticFileHandler,
light9/paint/capture.py
Show inline comments
 
@@ -5,15 +5,18 @@ from light9.rdfdb.patch import Patch
 
from light9.namespaces import L9, RDF
 
from light9.paint.solve import loadNumpy
 

	
 
def writeCaptureDescription(graph, ctx, uri, dev, relOutPath, settingsSubgraphCache, settings):
 
def writeCaptureDescription(graph, ctx, uri, dev, outPath, settingsSubgraphCache,
 
                            settings):
 
    graph.patch(Patch(addQuads=settings.statements(
 
        uri, ctx=ctx,
 
        settingRoot=URIRef('/'.join([showconfig.showUri(), 'capture', dev.rsplit('/')[1]])),
 
        settingRoot=URIRef('/'.join([
 
            showconfig.showUri(), 'capture', dev.rsplit('/')[1]])),
 
        settingsSubgraphCache=settingsSubgraphCache)))
 
    graph.patch(Patch(addQuads=[
 
        (dev, L9['capture'], uri, ctx),
 
        (uri, RDF.type, L9['LightSample'], ctx),
 
        (uri, L9['imagePath'], URIRef('/'.join([showconfig.showUri(), relOutPath])), ctx),
 
        (uri, L9['imagePath'], URIRef('/'.join([
 
            showconfig.showUri(), outPath])), ctx),
 
        ]))
 
    graph.suggestPrefixes(ctx, {'cap': uri.rsplit('/', 1)[0] + '/',
 
                                'showcap': showconfig.showUri() + '/capture/'})
light9/web/timeline/timeline.coffee
Show inline comments
 
@@ -302,7 +302,7 @@ Polymer
 
    quads = [
 
      quad(effect, U('rdf:type'), U(':Effect')),
 
      quad(effect, U(':copiedFrom'), uri),
 
      quad(effect, U('rdfs:label'), @graph.Literal('')),
 
      quad(effect, U('rdfs:label'), @graph.Literal(uri.replace(/.*capture\//, ''))),
 
      quad(effect, U(':publishAttr'), U(':strength')),
 
      ]
 

	
 
@@ -314,6 +314,7 @@ Polymer
 
      ts = toSettings.pop()
 
      # full copies of these since I may have to delete captures
 
      quads.push(quad(effect, U(':setting'), ts))
 
      quads.push(quad(ts, U(':device'), @graph.uriValue(fs, U(':device'))))
 
      quads.push(quad(ts, U(':deviceAttr'), @graph.uriValue(fs, U(':deviceAttr'))))
 
      quads.push(quad(ts, U(':value'), @graph.uriValue(fs, U(':value'))))
 

	
 
@@ -498,7 +499,7 @@ Polymer
 
    rightX = screenPts[Math.min(2, screenPts.length - 1)].e(1) - 5
 
    if screenPts.length < 3
 
      rightX = leftX + 120
 
    w = 114
 
    w = 150
 
    h = 80
 
    @inlineRect = {
 
      left: leftX,
 
@@ -603,7 +604,7 @@ Polymer
 
    console.time('attrs update')
 
    U = (x) -> @graph.Uri(x)
 
    @effect = @graph.uriValue(@uri, U(':effectClass'))
 
    @effectLabel = @effect.replace(/.*\//, '')
 
    @effectLabel = @graph.stringValue(@effect, U('rdfs:label')) or (@effect.replace(/.*\//, ''))
 
    @noteLabel = @uri.replace(/.*\//, '')
 

	
 
    @existingColorScaleSetting = null
0 comments (0 inline, 0 general)