Acme-CPANModulesBundle-Import-MojoliciousAdvent-2017

 view release on metacpan or  search on metacpan

devdata/https_mojolicious.io_blog_2017_12_21_day-21-virtually-a-lumberjack  view on Meta::CPAN


<p>And add a method which progresses us through the script:</p>

<pre><code>sub instruction_show {
  my $self = shift;

  my $instruction = shift @{$self-&gt;instructions};
  return $self-&gt;loop-&gt;stop_gracefully unless defined $instruction;

  say $instruction-&gt;[1];
  $self-&gt;loop-&gt;timer(
    $instruction-&gt;[0] =&gt; sub { $self-&gt;instruction_show },
  );

  $self-&gt;loop-&gt;timer($instruction-&gt;[0] / 2, sub {
    my $type = (split / /, $self-&gt;instructions-&gt;[0][1])[1];
    my $file_count = $self-&gt;file_count;
    my $path = sprintf &#39;%i_%s.pgm&#39;, $file_count, uc $type;
    $self-&gt;file( $self-&gt;file_start($path) );
  }) if $instruction-&gt;[1] eq &#39;Steady&#39;;
}
</code></pre>

<p>As you can see, we ask the loop to stop gracefully when there are no more
instructions.

devdata/https_mojolicious.io_blog_2017_12_21_day-21-virtually-a-lumberjack  view on Meta::CPAN

to be done in the amount of seconds we specified in the script.</p>

<p>If the action is to steady the HMD, we know we are going to start another
action shortly so, in half of the wait time, we start a new file.
This should mean that the end and start of each file, the HMD is not moving
(much).</p>

<p>Then we need to start walking through this script by adding this before
starting the event loop in <em>main</em>:</p>

<pre><code>$self-&gt;loop-&gt;timer(0 =&gt; sub { $self-&gt;instruction_show });
</code></pre>

<p>Running this now prompts the user to move the HMD while outputting the packet
data in an image named after the movement that image represents!</p>

<h2>Get Your Head(er) Checked</h2>

<p>As mentioned, the PGM header is broken as it is supposed to contain the number
of rows and columns in the image, but this isn&#39;t known in advance.
We put an 8 character per value placeholder there and use this small shell

devdata/https_mojolicious.io_blog_2017_12_21_day-21-virtually-a-lumberjack  view on Meta::CPAN


<p>Now these are valid PGM images and we can open them to see the data stream!</p>

<p><img alt="Section of Yaw PGM" src="yaw.png"></p>

<p>(The above has been rotated and flipped, the original image is a thin
&quot;waterfall&quot;.)</p>

<p>Some parts are immediately obvious.
Very smooth gradients next to larger smooth blocks or gradients hints at a
high-precision timer, which tend to be 32 bits (4 bytes) wide.
This can be seen at the top of the example.</p>

<p>Other aspects are only noticeable when compared to the other movements.
The simple file format makes it very easy to graph the data with gnuplot.
In the worst/simple case scenario, you can simply graph at each offset and
various sizes until you see a (rough) sine wave, indicating you&#39;ve got the
right offset and number of bytes for that part of the puzzle!</p>

<h2>Moving On To Greater Things</h2>



( run in 1.374 second using v1.01-cache-2.11-cpan-49f99fa48dc )