Initial working version
This commit is contained in:
commit
f344cf83d9
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/target
|
||||||
|
**/*.rs.bk
|
6
Cargo.lock
generated
Normal file
6
Cargo.lock
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
[[package]]
|
||||||
|
name = "chorus-client"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
9
Cargo.toml
Normal file
9
Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "chorus-client"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Lukas Bachschwell <lukas@lbsfilm.at>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
23
index.html
Normal file
23
index.html
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<body onload="init()">
|
||||||
|
<p><span id="res"></span></p>
|
||||||
|
<script>
|
||||||
|
function init() {
|
||||||
|
setInterval(() => {
|
||||||
|
loadDoc("racestate.txt");
|
||||||
|
}, 250);
|
||||||
|
}
|
||||||
|
function loadDoc(url) {
|
||||||
|
var xhttp = new XMLHttpRequest();
|
||||||
|
xhttp.onreadystatechange = function() {
|
||||||
|
if (this.readyState == 4 && this.status == 200) {
|
||||||
|
document.getElementById("res").innerHTML = this.responseText;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhttp.open("GET", url, true);
|
||||||
|
xhttp.send();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
1
racestate.txt
Normal file
1
racestate.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Race inactive
|
64
src/main.rs
Normal file
64
src/main.rs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
use std::io::Write;
|
||||||
|
use std::net;
|
||||||
|
|
||||||
|
fn listen(socket: &net::UdpSocket) {
|
||||||
|
let mut buf: [u8; 20] = [0; 20];
|
||||||
|
let number_of_bytes: usize = 0;
|
||||||
|
let mut result: Vec<u8> = Vec::new();
|
||||||
|
match socket.recv_from(&mut buf) {
|
||||||
|
Ok((number_of_bytes, _)) => {
|
||||||
|
result = Vec::from(&buf[0..number_of_bytes]);
|
||||||
|
}
|
||||||
|
Err(fail) => println!("failed listening {:?}", fail),
|
||||||
|
}
|
||||||
|
|
||||||
|
let display_result = result.clone();
|
||||||
|
let result_str = String::from_utf8(display_result).unwrap();
|
||||||
|
println!("received message: {:?}", result_str);
|
||||||
|
|
||||||
|
if result_str.contains("S0R1") {
|
||||||
|
write_file("Race active", "racestate.txt");
|
||||||
|
write_file("00", "rx1.txt");
|
||||||
|
write_file("00", "rx2.txt");
|
||||||
|
write_file("00", "rx3.txt");
|
||||||
|
}
|
||||||
|
if result_str.contains("S0R0") {
|
||||||
|
write_file("Race inactive", "racestate.txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
if result_str.contains("S0L") {
|
||||||
|
// zb sS1L0000000DAF
|
||||||
|
write_file(&result_str[3..5], "rx1.txt");
|
||||||
|
}
|
||||||
|
if result_str.contains("S1L") {
|
||||||
|
write_file(&result_str[3..5], "rx2.txt");
|
||||||
|
}
|
||||||
|
if result_str.contains("S2L") {
|
||||||
|
write_file(&result_str[3..5], "rx3.txt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_file(text: &str, filename: &str) {
|
||||||
|
let mut file = std::fs::File::create(filename).expect("create failed");
|
||||||
|
file.write_all(text.as_bytes()).expect("write failed");
|
||||||
|
//println!("data written to file");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
write_file("Race inactive", "racestate.txt");
|
||||||
|
write_file("00", "rx1.txt");
|
||||||
|
write_file("00", "rx2.txt");
|
||||||
|
write_file("00", "rx3.txt");
|
||||||
|
|
||||||
|
let socket = net::UdpSocket::bind("0.0.0.0:0").expect("failed to bind host socket"); // local bind port
|
||||||
|
|
||||||
|
let msg = String::from("ok").into_bytes();
|
||||||
|
|
||||||
|
socket
|
||||||
|
.send_to(&msg, "192.168.0.141:9000")
|
||||||
|
.expect("cannot send");
|
||||||
|
|
||||||
|
loop {
|
||||||
|
listen(&socket); // this call is blockig
|
||||||
|
}
|
||||||
|
}
|
68
text1.lua
Normal file
68
text1.lua
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
function script_description()
|
||||||
|
return "This script lets you select a text source to force it to reread files every frame instead of once per second."
|
||||||
|
end
|
||||||
|
|
||||||
|
obs = obslua
|
||||||
|
source_name = nil
|
||||||
|
|
||||||
|
local open = io.open
|
||||||
|
|
||||||
|
local function read_file(path)
|
||||||
|
local file = open(path, "rb") -- r read mode and b binary mode
|
||||||
|
if not file then return nil end
|
||||||
|
local content = file:read "*a" -- *a or *all reads the whole file
|
||||||
|
file:close()
|
||||||
|
return content
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function script_update(settings)
|
||||||
|
source_name = obs.obs_data_get_string(settings, "source")
|
||||||
|
filepath = obs.obs_data_get_string(settings, "filepath")
|
||||||
|
|
||||||
|
local fileContent = read_file("/Users/LB/Desktop/z_Projects/chorus-client/racestate.txt");
|
||||||
|
set_text(fileContent)
|
||||||
|
end
|
||||||
|
|
||||||
|
function script_properties()
|
||||||
|
local props = obs.obs_properties_create()
|
||||||
|
local p = obs.obs_properties_add_list(props, "source", "Text Source", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING)
|
||||||
|
local p2 = obs.obs_properties_add_path(props, "filepath", "File", obs.OBS_PATH_FILE, nil, nil)
|
||||||
|
|
||||||
|
local sources = obs.obs_enum_sources()
|
||||||
|
if sources ~= nil then
|
||||||
|
for _, source in ipairs(sources) do
|
||||||
|
source_id = obs.obs_source_get_id(source)
|
||||||
|
if source_id == "text_gdiplus" or source_id == "text_ft2_source" or source_id == "text_pango_source" then
|
||||||
|
local name = obs.obs_source_get_name(source)
|
||||||
|
obs.obs_property_list_add_string(p, name, name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
obs.source_list_release(sources)
|
||||||
|
|
||||||
|
return props
|
||||||
|
end
|
||||||
|
|
||||||
|
function set_text(text)
|
||||||
|
|
||||||
|
local source = obs.obs_get_source_by_name(source_name)
|
||||||
|
|
||||||
|
if source ~= nil then
|
||||||
|
local settings = obs.obs_data_create()
|
||||||
|
obs.obs_data_set_string(settings, "text", text)
|
||||||
|
obs.obs_source_update(source, settings)
|
||||||
|
obs.obs_data_release(settings)
|
||||||
|
obs.obs_source_release(source)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function script_tick(seconds)
|
||||||
|
if source_name == nil then return end
|
||||||
|
local fileContent = read_file(filepath);
|
||||||
|
set_text(fileContent)
|
||||||
|
end
|
68
text2.lua
Normal file
68
text2.lua
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
function script_description()
|
||||||
|
return "This script lets you select a text source to force it to reread files every frame instead of once per second."
|
||||||
|
end
|
||||||
|
|
||||||
|
obs = obslua
|
||||||
|
source_name = nil
|
||||||
|
|
||||||
|
local open = io.open
|
||||||
|
|
||||||
|
local function read_file(path)
|
||||||
|
local file = open(path, "rb") -- r read mode and b binary mode
|
||||||
|
if not file then return nil end
|
||||||
|
local content = file:read "*a" -- *a or *all reads the whole file
|
||||||
|
file:close()
|
||||||
|
return content
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function script_update(settings)
|
||||||
|
source_name = obs.obs_data_get_string(settings, "source")
|
||||||
|
filepath = obs.obs_data_get_string(settings, "filepath")
|
||||||
|
|
||||||
|
local fileContent = read_file("/Users/LB/Desktop/z_Projects/chorus-client/racestate.txt");
|
||||||
|
set_text(fileContent)
|
||||||
|
end
|
||||||
|
|
||||||
|
function script_properties()
|
||||||
|
local props = obs.obs_properties_create()
|
||||||
|
local p = obs.obs_properties_add_list(props, "source", "Text Source", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING)
|
||||||
|
local p2 = obs.obs_properties_add_path(props, "filepath", "File", obs.OBS_PATH_FILE, nil, nil)
|
||||||
|
|
||||||
|
local sources = obs.obs_enum_sources()
|
||||||
|
if sources ~= nil then
|
||||||
|
for _, source in ipairs(sources) do
|
||||||
|
source_id = obs.obs_source_get_id(source)
|
||||||
|
if source_id == "text_gdiplus" or source_id == "text_ft2_source" or source_id == "text_pango_source" then
|
||||||
|
local name = obs.obs_source_get_name(source)
|
||||||
|
obs.obs_property_list_add_string(p, name, name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
obs.source_list_release(sources)
|
||||||
|
|
||||||
|
return props
|
||||||
|
end
|
||||||
|
|
||||||
|
function set_text(text)
|
||||||
|
|
||||||
|
local source = obs.obs_get_source_by_name(source_name)
|
||||||
|
|
||||||
|
if source ~= nil then
|
||||||
|
local settings = obs.obs_data_create()
|
||||||
|
obs.obs_data_set_string(settings, "text", text)
|
||||||
|
obs.obs_source_update(source, settings)
|
||||||
|
obs.obs_data_release(settings)
|
||||||
|
obs.obs_source_release(source)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function script_tick(seconds)
|
||||||
|
if source_name == nil then return end
|
||||||
|
local fileContent = read_file(filepath);
|
||||||
|
set_text(fileContent)
|
||||||
|
end
|
68
text3.lua
Normal file
68
text3.lua
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
function script_description()
|
||||||
|
return "This script lets you select a text source to force it to reread files every frame instead of once per second."
|
||||||
|
end
|
||||||
|
|
||||||
|
obs = obslua
|
||||||
|
source_name = nil
|
||||||
|
|
||||||
|
local open = io.open
|
||||||
|
|
||||||
|
local function read_file(path)
|
||||||
|
local file = open(path, "rb") -- r read mode and b binary mode
|
||||||
|
if not file then return nil end
|
||||||
|
local content = file:read "*a" -- *a or *all reads the whole file
|
||||||
|
file:close()
|
||||||
|
return content
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function script_update(settings)
|
||||||
|
source_name = obs.obs_data_get_string(settings, "source")
|
||||||
|
filepath = obs.obs_data_get_string(settings, "filepath")
|
||||||
|
|
||||||
|
local fileContent = read_file("/Users/LB/Desktop/z_Projects/chorus-client/racestate.txt");
|
||||||
|
set_text(fileContent)
|
||||||
|
end
|
||||||
|
|
||||||
|
function script_properties()
|
||||||
|
local props = obs.obs_properties_create()
|
||||||
|
local p = obs.obs_properties_add_list(props, "source", "Text Source", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING)
|
||||||
|
local p2 = obs.obs_properties_add_path(props, "filepath", "File", obs.OBS_PATH_FILE, nil, nil)
|
||||||
|
|
||||||
|
local sources = obs.obs_enum_sources()
|
||||||
|
if sources ~= nil then
|
||||||
|
for _, source in ipairs(sources) do
|
||||||
|
source_id = obs.obs_source_get_id(source)
|
||||||
|
if source_id == "text_gdiplus" or source_id == "text_ft2_source" or source_id == "text_pango_source" then
|
||||||
|
local name = obs.obs_source_get_name(source)
|
||||||
|
obs.obs_property_list_add_string(p, name, name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
obs.source_list_release(sources)
|
||||||
|
|
||||||
|
return props
|
||||||
|
end
|
||||||
|
|
||||||
|
function set_text(text)
|
||||||
|
|
||||||
|
local source = obs.obs_get_source_by_name(source_name)
|
||||||
|
|
||||||
|
if source ~= nil then
|
||||||
|
local settings = obs.obs_data_create()
|
||||||
|
obs.obs_data_set_string(settings, "text", text)
|
||||||
|
obs.obs_source_update(source, settings)
|
||||||
|
obs.obs_data_release(settings)
|
||||||
|
obs.obs_source_release(source)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function script_tick(seconds)
|
||||||
|
if source_name == nil then return end
|
||||||
|
local fileContent = read_file(filepath);
|
||||||
|
set_text(fileContent)
|
||||||
|
end
|
68
text4.lua
Normal file
68
text4.lua
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
function script_description()
|
||||||
|
return "This script lets you select a text source to force it to reread files every frame instead of once per second."
|
||||||
|
end
|
||||||
|
|
||||||
|
obs = obslua
|
||||||
|
source_name = nil
|
||||||
|
|
||||||
|
local open = io.open
|
||||||
|
|
||||||
|
local function read_file(path)
|
||||||
|
local file = open(path, "rb") -- r read mode and b binary mode
|
||||||
|
if not file then return nil end
|
||||||
|
local content = file:read "*a" -- *a or *all reads the whole file
|
||||||
|
file:close()
|
||||||
|
return content
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function script_update(settings)
|
||||||
|
source_name = obs.obs_data_get_string(settings, "source")
|
||||||
|
filepath = obs.obs_data_get_string(settings, "filepath")
|
||||||
|
|
||||||
|
local fileContent = read_file("/Users/LB/Desktop/z_Projects/chorus-client/racestate.txt");
|
||||||
|
set_text(fileContent)
|
||||||
|
end
|
||||||
|
|
||||||
|
function script_properties()
|
||||||
|
local props = obs.obs_properties_create()
|
||||||
|
local p = obs.obs_properties_add_list(props, "source", "Text Source", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING)
|
||||||
|
local p2 = obs.obs_properties_add_path(props, "filepath", "File", obs.OBS_PATH_FILE, nil, nil)
|
||||||
|
|
||||||
|
local sources = obs.obs_enum_sources()
|
||||||
|
if sources ~= nil then
|
||||||
|
for _, source in ipairs(sources) do
|
||||||
|
source_id = obs.obs_source_get_id(source)
|
||||||
|
if source_id == "text_gdiplus" or source_id == "text_ft2_source" or source_id == "text_pango_source" then
|
||||||
|
local name = obs.obs_source_get_name(source)
|
||||||
|
obs.obs_property_list_add_string(p, name, name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
obs.source_list_release(sources)
|
||||||
|
|
||||||
|
return props
|
||||||
|
end
|
||||||
|
|
||||||
|
function set_text(text)
|
||||||
|
|
||||||
|
local source = obs.obs_get_source_by_name(source_name)
|
||||||
|
|
||||||
|
if source ~= nil then
|
||||||
|
local settings = obs.obs_data_create()
|
||||||
|
obs.obs_data_set_string(settings, "text", text)
|
||||||
|
obs.obs_source_update(source, settings)
|
||||||
|
obs.obs_data_release(settings)
|
||||||
|
obs.obs_source_release(source)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function script_tick(seconds)
|
||||||
|
if source_name == nil then return end
|
||||||
|
local fileContent = read_file(filepath);
|
||||||
|
set_text(fileContent)
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user