Skip to content

Commit

Permalink
Merge pull request #489 from hplato/ia7
Browse files Browse the repository at this point in the history
Major web interface rehaul
  • Loading branch information
hollie committed Mar 18, 2015
2 parents 92697ba + 702f061 commit 3653573
Show file tree
Hide file tree
Showing 20 changed files with 2,919 additions and 296 deletions.
114 changes: 104 additions & 10 deletions bin/mh
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ use vars qw(%Run_Members);

my ($Pgm_PathU);
my ($Loop_Speed, @Loop_Speeds, $Loop_Sleep_Time, $Loop_Tk_Passes, $Web_Play_Index);
my (@Requested_Files, @Print_Log, @Display_Log, @Speak_Log, @Error_Log);
my (@Requested_Files, @Print_Log, @Print_Log_Time, @Display_Log, @Speak_Log, @Speak_Log_Time, @Error_Log, @Error_Log_Time);

my ($exit_flag, $xcmd_file, %file_code_times, %file_code_times2, %file_change_times);
my (@Loop_Code, @Sub_Code, %Sub_Code, %Run_Members, %Run_Members_Error_Count, %Benchmark_Members, @Item_Code, @Item_Code_Objects);
Expand Down Expand Up @@ -1150,20 +1150,24 @@ sub open_logs {
my $speak_log = "$config_parms{data_dir}/logs/speak.log";
my $error_log = "$config_parms{data_dir}/logs/error.log";

my (@log);
my (@log,@speaklog,@errorlog);
@log = &file_tail($print_log, $config_parms{max_log_entries});
chomp @log;
@Print_Log = reverse @log;
unshift @Print_Log, "$Time_Date ---------- Restart ---------- ";
@Print_Log_Time = (1)x scalar @Print_Log;

@speaklog = &file_tail($speak_log, $config_parms{max_log_entries});
chomp @speaklog;
@Speak_Log = reverse @speaklog;
@Speak_Log_Time = (1)x scalar @Speak_Log;

@log = &file_tail($speak_log, $config_parms{max_log_entries});
chomp @log;
@Speak_Log = reverse @log;
# unshift @Speak_Log, "$Time_Date ---------- Restart ---------- ";

@log = &file_tail($error_log, $config_parms{max_log_entries});
chomp @log;
@Error_Log = reverse @log;
@errorlog = &file_tail($error_log, $config_parms{max_log_entries});
chomp @errorlog;
@Error_Log = reverse @errorlog;
@Error_Log_Time = (1)x scalar @Error_Log;
unshift @Error_Log, "$Time_Date ---------- Restart ---------- ";


Expand Down Expand Up @@ -4017,6 +4021,9 @@ sub print_log {
unshift (@Print_Log, $data);
pop @Print_Log if @Print_Log > $config_parms{max_log_entries};

unshift (@Print_Log_Time, &get_tickcount);
pop @Print_Log_Time if @Print_Log_Time > @Print_Log;

$Last_Response = 'print_log' unless $Last_Response;


Expand Down Expand Up @@ -4044,6 +4051,37 @@ sub print_log_last {
}
}

sub print_log_since {
# Return the print_log phrases since time
my ($time) = @_;
#Search from front to back, we are likely looking for an entry near the front
my $index;
for my $i (0 .. $#Print_Log_Time) {
$index = $i;
if ($time >= $Print_Log_Time[$i]){
# We have already seen this message, so the prior index is what we need
$index--;
last;
}
}
my $count = @Print_Log;
if ($index < 0) {
return;
}
elsif (($index+1) >= $count) {
return @Print_Log;
}
else {
return (@Print_Log[0 .. $index]);
}
}

sub print_log_current_time {
# Return the time of most recent print_log phrase
return $Print_Log_Time[0] unless (scalar @Print_Log_Time <= 0);
return 0;
}

sub error_log_last {
# Return the last how_many error_log phrases
my ($how_many) = @_;
Expand Down Expand Up @@ -4077,12 +4115,15 @@ sub print_speaklog {
# my ($data) = @_;
my $data = "@_";

$data =~ s/<\/?voice.*?>//g; # Drop XML speech tags
$data =~ s/\n *$//; # Drop trailing cr

# unshift (@Speak_Log, "$Time_Now $data");
unshift (@Speak_Log, "$Time_Date $data");
pop @Speak_Log if @Speak_Log > $config_parms{max_log_entries};
unshift (@Speak_Log_Time, &get_tickcount);
pop @Speak_Log_Time if @Speak_Log_Time > @Speak_Log;

$data =~ s/<\/?voice.*?>//g; # Drop XML speech tags
$data =~ s/\n *$//; # Drop trailing cr

if ($Tk_objects{speak_window}) {
# Most recent at top ... if we put it on the bottom, we have to constantly
Expand All @@ -4093,8 +4134,61 @@ sub print_speaklog {
print "$data\n" unless $config_parms{no_log} =~ /speak/ or $Startup; # On startup no print needed as it is just the "System Restarted" message (or an error with its own debug info)
}
print SPEAKLOG "$Time_Date $data\n";

return;
}

sub print_speaklog_last {
# Return the last how_many speak phrases
my ($how_many) = @_;
my $count = @Speak_Log;
if ($how_many == 1) {
return $Speak_Log[0];
}
elsif ($how_many >= $count) {
return @Speak_Log;
}
else {
return (@Speak_Log[0 .. ($how_many-1)]);
}
}

sub print_speaklog_since {
# Return the speak phrases since time
my ($time) = @_;
#Search from front to back, we are likely looking for an entry near the front
my $index;
for my $i (0 .. $#Speak_Log_Time) {
$index = $i;
#print "db/mh/since: i=$i time=$time, plt=$Print_Log_Time[$i] slt=$Speak_Log_Time[$i]\n";
if ($time >= $Speak_Log_Time[$i]){ #TODO: Problem
# We have already seen this message, so the prior index is what we need
$index--;
last;
}
}
my $count = @Speak_Log;
if ($index < 0) {
return;
}
elsif (($index+1) >= $count) {
return @Speak_Log;
}
else {
print "db/mh/since [ " . @Speak_Log[0 .. $index]. "]\n";
return (@Speak_Log[0 .. $index]);
}
}

sub print_speaklog_current_time {
# Return the time of most recent speak phrase

#print "db/mh/curr: time=" . &get_tickcount . " plt=$Print_Log_Time[0] slt=$Speak_Log_Time[0]\n";
return $Print_Log_Time[0] unless (scalar @Speak_Log_Time <= 0); #TODO HP should return $Speak_Log_Time
return 0;
}


sub process_external_command {
my ($cmd, $warning_flag, $set_by, $respond_target) = @_;
$cmd =~ s/^\s+//; # Deletes leading blanks
Expand Down
Loading

0 comments on commit 3653573

Please sign in to comment.