Test pour écran OLED 128 x 64 SSD1306 avec sonde thermique DS18B20

Committer:
diltech
Date:
Sat May 28 13:22:32 2022 +0000
Revision:
0:8ae2868c8c6c
Projet initial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
diltech 0:8ae2868c8c6c 1 #!/usr/bin/perl
diltech 0:8ae2868c8c6c 2
diltech 0:8ae2868c8c6c 3 use strict;
diltech 0:8ae2868c8c6c 4 use warnings;
diltech 0:8ae2868c8c6c 5 use IPC::Open2;
diltech 0:8ae2868c8c6c 6
diltech 0:8ae2868c8c6c 7 # An example hook script to integrate Watchman
diltech 0:8ae2868c8c6c 8 # (https://facebook.github.io/watchman/) with git to speed up detecting
diltech 0:8ae2868c8c6c 9 # new and modified files.
diltech 0:8ae2868c8c6c 10 #
diltech 0:8ae2868c8c6c 11 # The hook is passed a version (currently 1) and a time in nanoseconds
diltech 0:8ae2868c8c6c 12 # formatted as a string and outputs to stdout all files that have been
diltech 0:8ae2868c8c6c 13 # modified since the given time. Paths must be relative to the root of
diltech 0:8ae2868c8c6c 14 # the working tree and separated by a single NUL.
diltech 0:8ae2868c8c6c 15 #
diltech 0:8ae2868c8c6c 16 # To enable this hook, rename this file to "query-watchman" and set
diltech 0:8ae2868c8c6c 17 # 'git config core.fsmonitor .git/hooks/query-watchman'
diltech 0:8ae2868c8c6c 18 #
diltech 0:8ae2868c8c6c 19 my ($version, $time) = @ARGV;
diltech 0:8ae2868c8c6c 20
diltech 0:8ae2868c8c6c 21 # Check the hook interface version
diltech 0:8ae2868c8c6c 22
diltech 0:8ae2868c8c6c 23 if ($version == 1) {
diltech 0:8ae2868c8c6c 24 # convert nanoseconds to seconds
diltech 0:8ae2868c8c6c 25 $time = int $time / 1000000000;
diltech 0:8ae2868c8c6c 26 } else {
diltech 0:8ae2868c8c6c 27 die "Unsupported query-fsmonitor hook version '$version'.\n" .
diltech 0:8ae2868c8c6c 28 "Falling back to scanning...\n";
diltech 0:8ae2868c8c6c 29 }
diltech 0:8ae2868c8c6c 30
diltech 0:8ae2868c8c6c 31 my $git_work_tree;
diltech 0:8ae2868c8c6c 32 if ($^O =~ 'msys' || $^O =~ 'cygwin') {
diltech 0:8ae2868c8c6c 33 $git_work_tree = Win32::GetCwd();
diltech 0:8ae2868c8c6c 34 $git_work_tree =~ tr/\\/\//;
diltech 0:8ae2868c8c6c 35 } else {
diltech 0:8ae2868c8c6c 36 require Cwd;
diltech 0:8ae2868c8c6c 37 $git_work_tree = Cwd::cwd();
diltech 0:8ae2868c8c6c 38 }
diltech 0:8ae2868c8c6c 39
diltech 0:8ae2868c8c6c 40 my $retry = 1;
diltech 0:8ae2868c8c6c 41
diltech 0:8ae2868c8c6c 42 launch_watchman();
diltech 0:8ae2868c8c6c 43
diltech 0:8ae2868c8c6c 44 sub launch_watchman {
diltech 0:8ae2868c8c6c 45
diltech 0:8ae2868c8c6c 46 my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty')
diltech 0:8ae2868c8c6c 47 or die "open2() failed: $!\n" .
diltech 0:8ae2868c8c6c 48 "Falling back to scanning...\n";
diltech 0:8ae2868c8c6c 49
diltech 0:8ae2868c8c6c 50 # In the query expression below we're asking for names of files that
diltech 0:8ae2868c8c6c 51 # changed since $time but were not transient (ie created after
diltech 0:8ae2868c8c6c 52 # $time but no longer exist).
diltech 0:8ae2868c8c6c 53 #
diltech 0:8ae2868c8c6c 54 # To accomplish this, we're using the "since" generator to use the
diltech 0:8ae2868c8c6c 55 # recency index to select candidate nodes and "fields" to limit the
diltech 0:8ae2868c8c6c 56 # output to file names only. Then we're using the "expression" term to
diltech 0:8ae2868c8c6c 57 # further constrain the results.
diltech 0:8ae2868c8c6c 58 #
diltech 0:8ae2868c8c6c 59 # The category of transient files that we want to ignore will have a
diltech 0:8ae2868c8c6c 60 # creation clock (cclock) newer than $time_t value and will also not
diltech 0:8ae2868c8c6c 61 # currently exist.
diltech 0:8ae2868c8c6c 62
diltech 0:8ae2868c8c6c 63 my $query = <<" END";
diltech 0:8ae2868c8c6c 64 ["query", "$git_work_tree", {
diltech 0:8ae2868c8c6c 65 "since": $time,
diltech 0:8ae2868c8c6c 66 "fields": ["name"],
diltech 0:8ae2868c8c6c 67 "expression": ["not", ["allof", ["since", $time, "cclock"], ["not", "exists"]]]
diltech 0:8ae2868c8c6c 68 }]
diltech 0:8ae2868c8c6c 69 END
diltech 0:8ae2868c8c6c 70
diltech 0:8ae2868c8c6c 71 print CHLD_IN $query;
diltech 0:8ae2868c8c6c 72 close CHLD_IN;
diltech 0:8ae2868c8c6c 73 my $response = do {local $/; <CHLD_OUT>};
diltech 0:8ae2868c8c6c 74
diltech 0:8ae2868c8c6c 75 die "Watchman: command returned no output.\n" .
diltech 0:8ae2868c8c6c 76 "Falling back to scanning...\n" if $response eq "";
diltech 0:8ae2868c8c6c 77 die "Watchman: command returned invalid output: $response\n" .
diltech 0:8ae2868c8c6c 78 "Falling back to scanning...\n" unless $response =~ /^\{/;
diltech 0:8ae2868c8c6c 79
diltech 0:8ae2868c8c6c 80 my $json_pkg;
diltech 0:8ae2868c8c6c 81 eval {
diltech 0:8ae2868c8c6c 82 require JSON::XS;
diltech 0:8ae2868c8c6c 83 $json_pkg = "JSON::XS";
diltech 0:8ae2868c8c6c 84 1;
diltech 0:8ae2868c8c6c 85 } or do {
diltech 0:8ae2868c8c6c 86 require JSON::PP;
diltech 0:8ae2868c8c6c 87 $json_pkg = "JSON::PP";
diltech 0:8ae2868c8c6c 88 };
diltech 0:8ae2868c8c6c 89
diltech 0:8ae2868c8c6c 90 my $o = $json_pkg->new->utf8->decode($response);
diltech 0:8ae2868c8c6c 91
diltech 0:8ae2868c8c6c 92 if ($retry > 0 and $o->{error} and $o->{error} =~ m/unable to resolve root .* directory (.*) is not watched/) {
diltech 0:8ae2868c8c6c 93 print STDERR "Adding '$git_work_tree' to watchman's watch list.\n";
diltech 0:8ae2868c8c6c 94 $retry--;
diltech 0:8ae2868c8c6c 95 qx/watchman watch "$git_work_tree"/;
diltech 0:8ae2868c8c6c 96 die "Failed to make watchman watch '$git_work_tree'.\n" .
diltech 0:8ae2868c8c6c 97 "Falling back to scanning...\n" if $? != 0;
diltech 0:8ae2868c8c6c 98
diltech 0:8ae2868c8c6c 99 # Watchman will always return all files on the first query so
diltech 0:8ae2868c8c6c 100 # return the fast "everything is dirty" flag to git and do the
diltech 0:8ae2868c8c6c 101 # Watchman query just to get it over with now so we won't pay
diltech 0:8ae2868c8c6c 102 # the cost in git to look up each individual file.
diltech 0:8ae2868c8c6c 103 print "/\0";
diltech 0:8ae2868c8c6c 104 eval { launch_watchman() };
diltech 0:8ae2868c8c6c 105 exit 0;
diltech 0:8ae2868c8c6c 106 }
diltech 0:8ae2868c8c6c 107
diltech 0:8ae2868c8c6c 108 die "Watchman: $o->{error}.\n" .
diltech 0:8ae2868c8c6c 109 "Falling back to scanning...\n" if $o->{error};
diltech 0:8ae2868c8c6c 110
diltech 0:8ae2868c8c6c 111 binmode STDOUT, ":utf8";
diltech 0:8ae2868c8c6c 112 local $, = "\0";
diltech 0:8ae2868c8c6c 113 print @{$o->{files}};
diltech 0:8ae2868c8c6c 114 }