#!/usr/bin/perl -w

use strict;
use warnings;

# Author : Nathael Pajani
# Copyright 2016 Nathael Pajani <nathael.pajani@techno-innov.fr>
#
# 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, either version 2 of the License, or
# (at your option) any later version.
#
# 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/>.


my $file = $ARGV[0];
if (! -e $file) {
	print "Need file name as first argument\n";
	exit 1;
}

my $count = 0;
my $skip = 4000;

open(LOGFILE, "<", $file);
open(TEMP, ">", "data_temp.log") or die $!;
open(CAP, ">", "data_cap.log") or die $!;
open(RES, ">", "data_res.log") or die $!;


foreach my $line (<LOGFILE>) {
	if ($skip > 0) {
		$skip--;
		next;
	}
	chomp($line); # remove the newline from $line.
	my $w = "(.+?)";
	if ($line =~ m/Temp read: $w - raw/) {
		my $temp = $1;
		$temp =~ s/,/./;
		print TEMP "$count  $temp\n";
		# Increment counter
		$count++;
	} elsif ($line =~ m/ADC9: $w, ADC10: (.+)/) {
		print CAP "$count  $1\n";
		print RES "$count  $2\n";
	}
}


print "Got $count values\n";

close(TEMP);
close(CAP);
close(RES);

