-
Notifications
You must be signed in to change notification settings - Fork 2
/
get-tiltinfo.php
53 lines (44 loc) · 2.08 KB
/
get-tiltinfo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/* Copyright (C) 2018, 2019 Lee C. Bussy (@LBussy)
*
* This file is part of LBussy's BrewPi WWW Remix (BrewPi-WWW-RMX).
*
* BrewPi WWW RMX 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 3 of the
* License, or (at your option) any later version.
*
* BrewPi WWW RMX 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 BrewPi WWW RMX. If not, see <https://www.gnu.org/licenses/>.
*/
// load default settings from file
$defaultSettings = file_get_contents('defaultSettings.json');
if ($defaultSettings == false) die("Cannot open: defaultSettings.json");
$settingsArray = json_decode(prepareJSON($defaultSettings), true);
if (is_null($settingsArray)) die("Cannot decode: defaultSettings.json");
if (file_exists('userSettings.json')){
$userSettings = file_get_contents('userSettings.json');
if ($userSettings == false) die("Cannot open: userSettings.json");
$userSettingsArray = json_decode(prepareJSON($userSettings), true);
if (is_null($settingsArray)) die("Cannot decode: userSettings.json");
foreach ($userSettingsArray as $key => $value) {
$settingsArray[$key] = $userSettingsArray[$key];
}
}
$tiltInfo = json_encode(['isHighRes' => $settingsArray["isHighResTilt"]]);
function prepareJSON($input) {
// This will convert ASCII/ISO-8859-1 to UTF-8.
// Be careful with the third parameter (encoding detect list), because
// if set wrong, some input encodings will get garbled (including UTF-8!)
$input = mb_convert_encoding($input, 'UTF-8', 'ASCII,UTF-8,ISO-8859-1');
// Remove UTF-8 BOM if present, json_decode() does not like it.
if(substr($input, 0, 3) == pack("CCC", 0xEF, 0xBB, 0xBF)) $input = substr($input, 3);
return $input;
}
echo "$tiltInfo"
?>