I have built a scoreboard using the html from https://buildyourownscoreboard.wordpress.com/
But I have added several variables myself, one of which is RunsReq
RunsReq is calculated by subtracting Score from Target, so if the target is 150 & the score is 95, RunsReq is 55
In the first Innings of the game the target & RunsReq are obviously zero, so there’s a line of code that converts RunsReq 0 in to a dash. There’s then some code that tells the scoreboard not to display a dash so the RunsReq on the board is blank. Perfect.
So as the score increases the RunsReq decreases. My problem is that once the RunsReq reached 0, the digit on the board goes blank. But I want it to display a 0.
There’s also a line that strips out leading zeroes so that it displays 65 rather than 065
I will paste the entire php script below but the relevant lines ( I think) are these:
if($target==0) { $runsreq="—"; } else { $runsreq = ltrim($runsreq, ‘-’); $runsreq = str_pad($runsreq, 3, ‘-’, STR_PAD_LEFT); }
if($target==0) { $target="—"; } else { $target = ltrim($target, ‘0’); $target = str_pad($target, 3, ‘-’, STR_PAD_LEFT); }
if($runsreq==0) { $runsreq="—"; } else { $runsreq = ltrim($runsreq, ‘0’); $runsreq = str_pad($runsreq, 3, ‘-’, STR_PAD_LEFT); }
So I think I need to add an extra line that says (in Excel language)
IF target >0 AND runsreq<1 THEN runsreq = “–0”
I’ve tried every combination I can think of & can’t make it work so any help would be greatly appreciated.
Full code of PHP script:
<?php
//
// 20.04.2016
//
// Overs and wickets output swapped from orginal scoreboard.php to account for Bradford on Avon CC scoreboard design to show
// overs - wickets - target along the bottom
//
// 20.04.2016
// Form method changed from POST to GET and data simplified to send one string -
// total[3] wickets[1] overs[2] batsa[3] batsb[3] target[3]
//
// e.g. 126807042084453 = Total 126, Wickets 8, Overs 07, Batsman A 042, Batsman B 084, Target 453.
//
// 18.06.2016
// Added back in line for original westbury on server scoreboard layout for second line
// see lines 50 and 51
//
// 28.12.2018
// Modified version for whitchurch CC which includes batsman numbers.
//
// Changed string order & contents Tot/Wkts/Overs/Tatget/RunsReq 123456123456
file_put_contents('save.txt', $_GET['data']); // Save the scores! They will be automatically loaded when the scoreboard is turned on. Make sure save.txt is writable by the web server user!
include "php_serial.class.php";
$total=substr($_GET['data'], 0, 3); //Get first 3 digits
$wicketsOnes=substr($_GET['data'], 3, 1); //Get next 1 digit
$overs=substr($_GET['data'], 4, 2); //Get next 2 digits
$runsreq=$runsreq=substr($_GET['data'], 6, 3); //Get next 3 digits
$target=$target=substr($_GET['data'], 9, 3); //Get next 3 digits
$batsmana=$batsmana=substr($_GET['data'], 12, 3); //Get next 3 digits
$batsmanb=$batsmanb=substr($_GET['data'], 15, 3); //Get next 3 digits
$batsmananum=$batsmananum=substr($_GET['data'], 18, 2); //Get next 2 digits
$batsmanbnum=$batsmanbnum=substr($_GET['data'], 20, 2); //Get next 2 digits
$lastwkt=$lastwkt=substr($_GET['data'], 22, 3); //Get next 3 digits
$pship=$pship=substr($_GET['data'], 25, 3); //Get next 3 digits
$dltarget=$dltarget=substr($_GET['data'], 28, 3); //Get next 3 digits
$lastman=$lastman=substr($_GET['data'], 31, 3); //Get next 3 digits
// creatre new variable & pad it out to 3 digits, also make it blank if target = 0 (as done below for other fields)
// $runsreq = $target - $total;
if($target==0) { $runsreq="---"; } else { $runsreq = ltrim($runsreq, '-'); $runsreq = str_pad($runsreq, 3, '-', STR_PAD_LEFT); }
// if($runsreq<0) { $runsreq="---"; } else { $runsreq = ltrim($runsreq, '0'); $runsreq = str_pad($runsreq, 3, '-', STR_PAD_LEFT); }
// Now we want to check if the mutiple digit displays are under 10 or over 10 and turn off the LED's instead of showing 0
// But if they are 0, show 0
//
// First strip the leading zeros, then "pad" the number to the required length by adding dashes to turn off
// LEDs that would be showing 0 before the actual score
if($total==0) { $total="--0"; } else { $total = ltrim($total, '0'); $total = str_pad($total, 3, '-', STR_PAD_LEFT); }
if($overs==0) { $overs="-0"; } else { $overs = ltrim($overs, '0'); $overs = str_pad($overs, 2, '-', STR_PAD_LEFT); }
if($batsmana==0) { $batsmana="--0"; } else { $batsmana = ltrim($batsmana, '0'); $batsmana = str_pad($batsmana, 3, '-', STR_PAD_LEFT); }
if($batsmanb==0) { $batsmanb="--0"; } else { $batsmanb = ltrim($batsmanb, '0'); $batsmanb = str_pad($batsmanb, 3, '-', STR_PAD_LEFT); }
if($target==0) { $target="---"; } else { $target = ltrim($target, '0'); $target = str_pad($target, 3, '-', STR_PAD_LEFT); }
if($runsreq==0) { $runsreq="---"; } else { $runsreq = ltrim($runsreq, '0'); $runsreq = str_pad($runsreq, 3, '-', STR_PAD_LEFT); }
// THIS IS WHERE I THINK I NEED TO PUT MY NEW LINE
if($lastwkt==0) { $lastwkt="---"; } else { $lastwkt = ltrim($lastwkt, '0'); $lastwkt = str_pad($lastwkt, 3, '-', STR_PAD_LEFT); }
if($pship==0) { $pship="---"; } else { $pship = ltrim($pship, '0'); $pship = str_pad($pship, 3, '-', STR_PAD_LEFT); }
if($lastman==0) { $lastman="---"; } else { $lastman = ltrim($lastman, '0'); $lastman = str_pad($lastman, 3, '-', STR_PAD_LEFT); }
$batsmananum = ltrim($batsmananum, '0'); $batsmananum = str_pad($batsmananum, 2, '-', STR_PAD_LEFT);
$batsmanbnum = ltrim($batsmanbnum, '0'); $batsmanbnum = str_pad($batsmanbnum, 2, '-', STR_PAD_LEFT);
include 'updateSpectator.php';
$serial = new phpSerial;
$serial->deviceSet("/dev/ttyACM0");
#$serial->deviceSet("/dev/ttyAMA0");
#$serial->confBaudRate(115200);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
//original string
// $tempString="4,".$total.",".$overs.",".$wicketsOnes.",".$target.",".$batsmana.",".$batsmanb."".$batsmananum.",".$batsmanbnum."#";
// use ONE OR THE OTHER of these depending on whether you want Target or Runs Required displayed
// $tempString="4,".$total.",".$overs.",".$wicketsOnes.",".$target.",".$batsmana.",".$batsmanb."".$batsmananum.",".$batsmanbnum."#";
$tempString="4,".$total.",".$wicketsOnes.",".$overs.",".$runsreq.",".$batsmana.",".$batsmanb.",".$batsmananum.",".$batsmanbnum.",".$dltarget."#";
//or it might be this one that makes it work
// $tempString="4,".$total.",".$wicketsOnes.",".$overs.",".$runsreq.",".$target.",".$batsmana.",".$batsmanb."".$batsmananum.",".$batsmanbnum."#";
echo $tempString;
#echo($tempString."<br>");
$serial->deviceOpen();
$serial->sendMessage($tempString);
$serial->deviceClose();
#print_r($_POST);
?>