changeset 1584:2239d5648932

captureDevice saves all pics Ignore-this: eae0e07b8f6d4a9b719a1193830f866 it used to drop the last one
author Drew Perttula <drewp@bigasterisk.com>
date Tue, 30 May 2017 07:57:52 +0000
parents 5db651b08d77
children 17da56a3c8df
files bin/captureDevice light9/paint/capture.py light9/web/timeline/timeline.coffee
diffstat 3 files changed, 43 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/bin/captureDevice	Tue May 30 07:38:04 2017 +0000
+++ b/bin/captureDevice	Tue May 30 07:57:52 2017 +0000
@@ -46,11 +46,15 @@
             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 @@
         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]))
-                     
-        relOutPath = path + '.jpg'
+        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]))
         
-        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 @@
 
 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,
--- a/light9/paint/capture.py	Tue May 30 07:38:04 2017 +0000
+++ b/light9/paint/capture.py	Tue May 30 07:57:52 2017 +0000
@@ -5,15 +5,18 @@
 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/'})
--- a/light9/web/timeline/timeline.coffee	Tue May 30 07:38:04 2017 +0000
+++ b/light9/web/timeline/timeline.coffee	Tue May 30 07:57:52 2017 +0000
@@ -302,7 +302,7 @@
     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 @@
       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 @@
     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 @@
     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