Compare commits
No commits in common. "dev/marc" and "master" have entirely different histories.
@ -1,3 +1,4 @@
|
|||||||
|
use std::io::_print;
|
||||||
/**
|
/**
|
||||||
|
|
||||||
# Populate Redis Example
|
# Populate Redis Example
|
||||||
@ -6,6 +7,7 @@
|
|||||||
|
|
||||||
$ cargo run --example populate_redis
|
$ cargo run --example populate_redis
|
||||||
**/
|
**/
|
||||||
|
|
||||||
use redis::{
|
use redis::{
|
||||||
//RedisResult,
|
//RedisResult,
|
||||||
Client,
|
Client,
|
||||||
@ -17,10 +19,7 @@ fn do_something() -> redis::RedisResult<()> {
|
|||||||
let client = Client::open("redis://127.0.0.1/")?;
|
let client = Client::open("redis://127.0.0.1/")?;
|
||||||
let mut con: Connection = client.get_connection()?;
|
let mut con: Connection = client.get_connection()?;
|
||||||
let _ = con.set("/clientkey", "/pl/0/")?;
|
let _ = con.set("/clientkey", "/pl/0/")?;
|
||||||
let _ = con.set(
|
let _ = con.set("/EDH/0", "[[1.0, 0.0, 0.0],\n [ 0.0, 1.0, 0.0],\n [ 0.0, 0.0, 1.0]]")?;
|
||||||
"/EDH/0",
|
|
||||||
"[[1.0, 0.0, 0.0],\n [ 0.0, 1.0, 0.0],\n [ 0.0, 0.0, 1.0]]",
|
|
||||||
)?;
|
|
||||||
let _ = con.set("/kpps/0", "5000")?;
|
let _ = con.set("/kpps/0", "5000")?;
|
||||||
let _ = con.set("/intensity/0", "255")?;
|
let _ = con.set("/intensity/0", "255")?;
|
||||||
let _ = con.set("/pl/0/0", "[(1000, 2000, 0), (1000, 1000, 65535), (2000, 1000, 65535), (2000, 2000, 65535), (1000, 2000, 65535)]")?;
|
let _ = con.set("/pl/0/0", "[(1000, 2000, 0), (1000, 1000, 65535), (2000, 1000, 65535), (2000, 2000, 65535), (1000, 2000, 65535)]")?;
|
||||||
@ -30,6 +29,6 @@ fn do_something() -> redis::RedisResult<()> {
|
|||||||
fn main() {
|
fn main() {
|
||||||
match do_something() {
|
match do_something() {
|
||||||
Err(err) => println!("Something wrong occured: {:?}", err),
|
Err(err) => println!("Something wrong occured: {:?}", err),
|
||||||
Ok(..) => println!("Successfully inserted content in Redis"),
|
Ok(..) => println!("Successfully inserted content in Redis")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
///
|
///
|
||||||
/// $ cargo run --example simple_client
|
/// $ cargo run --example simple_client
|
||||||
///
|
///
|
||||||
|
|
||||||
use redis::{
|
use redis::{
|
||||||
//RedisResult,
|
//RedisResult,
|
||||||
Client,
|
Client,
|
||||||
Commands,
|
Commands,
|
||||||
Connection,
|
Connection,
|
||||||
};
|
};
|
||||||
use std::thread::sleep;
|
|
||||||
use std::time::{Duration, Instant};
|
|
||||||
|
|
||||||
const SCALE: f32 = 20.0;
|
use std::time::Instant;
|
||||||
|
|
||||||
fn do_something() -> redis::RedisResult<()> {
|
fn do_something() -> redis::RedisResult<()> {
|
||||||
let client = Client::open("redis://127.0.0.1/")?;
|
let client = Client::open("redis://127.0.0.1/")?;
|
||||||
@ -19,22 +18,25 @@ fn do_something() -> redis::RedisResult<()> {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
let elapsed = start.elapsed();
|
let elapsed = start.elapsed();
|
||||||
let time = 60.0 * elapsed.as_millis() as f32 / 5_000.0;
|
let time = 60.0 * elapsed.as_millis() as f32 / 1000.0;
|
||||||
|
|
||||||
let mut v: Vec<(f32, f32, u32)> = vec![];
|
let mut v : Vec<(f32,f32,u32)> = vec![];
|
||||||
|
|
||||||
for i in 0..128 {
|
for i in 0..128 {
|
||||||
let a = (time + i as f32) / 128.0 * std::f32::consts::PI * 2.0;
|
let a = (time + i as f32) / 128.0 * std::f32::consts::PI * 2.0;
|
||||||
let r = 24.0 * SCALE + (a * 5.0).cos() * (10.0 * SCALE * (time / 5.0).cos());
|
let r = 1200.0 + (a*5.0).cos() * (500.0 * (time/5.0).cos());
|
||||||
|
|
||||||
let x = a.cos() * r;
|
let x = a.cos() * r;
|
||||||
let y = a.sin() * r;
|
let y = a.sin() * r;
|
||||||
let col = if i % 8 < 4 { 0x000000ff } else { 0x00ff0000 };
|
let col = if i % 8 < 4 {
|
||||||
v.push((x, y, col));
|
0x000000ff
|
||||||
|
} else {
|
||||||
|
0x00ff0000
|
||||||
|
};
|
||||||
|
v.push((x,y,col));
|
||||||
}
|
}
|
||||||
// println!("{:?}", v);
|
// println!("{:?}", v);
|
||||||
let _ = con.set("/pl/0/0", format!("{:?}", v))?;
|
let _ = con.set("/pl/0/0", format!("{:?}", v))?;
|
||||||
sleep(Duration::from_millis(100));
|
|
||||||
}
|
}
|
||||||
// Ok(())
|
// Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
|
mod helios;
|
||||||
mod dummy;
|
mod dummy;
|
||||||
mod etherdream;
|
mod etherdream;
|
||||||
mod helios;
|
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
use crate::conf::{Conf, DacFamily /*EtherDreamConf, HeliosConf*/};
|
use crate::conf::{Conf, DacFamily /*EtherDreamConf, HeliosConf*/};
|
||||||
use crate::device::dummy::DummyDevice;
|
|
||||||
use crate::device::etherdream::EtherdreamDevice;
|
|
||||||
use crate::device::helios::HeliosDevice;
|
use crate::device::helios::HeliosDevice;
|
||||||
|
use crate::device::dummy::DummyDevice;
|
||||||
use crate::errors::LJResult;
|
use crate::errors::LJResult;
|
||||||
use crate::point::Point;
|
use crate::point::Point;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::fmt;
|
use crate::device::etherdream::EtherdreamDevice;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
self.protocol_version,
|
self.protocol_version,
|
||||||
@ -28,7 +28,7 @@ self.point_count
|
|||||||
pub enum PlaybackState {
|
pub enum PlaybackState {
|
||||||
IDLE = 0,
|
IDLE = 0,
|
||||||
PREPARE = 1,
|
PREPARE = 1,
|
||||||
PLAYING = 2,
|
PLAYING = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for PlaybackState {
|
impl fmt::Display for PlaybackState {
|
||||||
@ -52,7 +52,11 @@ pub struct Status {
|
|||||||
|
|
||||||
pub trait Device {
|
pub trait Device {
|
||||||
fn status(&mut self) -> Status;
|
fn status(&mut self) -> Status;
|
||||||
fn draw(&mut self, frame: Vec<Point>, speed: u32) -> LJResult<()>;
|
fn draw(
|
||||||
|
&mut self,
|
||||||
|
frame: Vec<Point>,
|
||||||
|
speed: u32,
|
||||||
|
) -> LJResult<()>;
|
||||||
fn stop(&mut self) -> LJResult<()>;
|
fn stop(&mut self) -> LJResult<()>;
|
||||||
fn grid(&mut self) -> Vec<Point>;
|
fn grid(&mut self) -> Vec<Point>;
|
||||||
}
|
}
|
||||||
@ -60,8 +64,8 @@ pub trait Device {
|
|||||||
pub fn device_factory(config: &Conf) -> LJResult<Box<dyn Device>> {
|
pub fn device_factory(config: &Conf) -> LJResult<Box<dyn Device>> {
|
||||||
let device: Box<dyn Device> = match &config.dac {
|
let device: Box<dyn Device> = match &config.dac {
|
||||||
DacFamily::Helios(conf) => Box::new(HeliosDevice::new(conf)?),
|
DacFamily::Helios(conf) => Box::new(HeliosDevice::new(conf)?),
|
||||||
DacFamily::Etherdream(conf) => Box::new(EtherdreamDevice::new(conf)?),
|
DacFamily::Etherdream( conf) => Box::new( EtherdreamDevice::new(conf)?),
|
||||||
DacFamily::Dummy => Box::new(DummyDevice::new()?),
|
DacFamily::Dummy => Box::new(DummyDevice::new()?)
|
||||||
};
|
};
|
||||||
Ok(device)
|
Ok(device)
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,24 @@
|
|||||||
#[warn(unused_imports)]
|
#[warn(unused_imports)]
|
||||||
use log::{debug, info, warn};
|
use log::{ debug, info, warn};
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
|
||||||
use ether_dream::dac::stream::{connect, CommunicationError};
|
|
||||||
use ether_dream::dac::{Playback, Stream};
|
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
|
use ether_dream::dac::stream::{CommunicationError, connect};
|
||||||
|
use ether_dream::dac::{Playback, Stream};
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
use std::time;
|
use std::time;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
use crate::conf::EtherDreamConf;
|
use crate::conf::EtherDreamConf;
|
||||||
use crate::device::{Device, PlaybackState, Status};
|
use crate::device::{Device, Status, PlaybackState};
|
||||||
use crate::errors::{LJError, LJResult};
|
use crate::errors::{LJError, LJResult};
|
||||||
use crate::point::{Color, Point};
|
use crate::point::{Color, Point};
|
||||||
use ether_dream::protocol::{DacBroadcast, DacResponse};
|
use ether_dream::protocol::{DacBroadcast, DacResponse};
|
||||||
|
|
||||||
|
|
||||||
#[warn(dead_code)]
|
#[warn(dead_code)]
|
||||||
pub struct EtherdreamDevice {
|
pub struct EtherdreamDevice {
|
||||||
conf: EtherDreamConf,
|
pub conf: EtherDreamConf,
|
||||||
dac: DacBroadcast,
|
dac: DacBroadcast,
|
||||||
stream: Stream,
|
stream: Stream,
|
||||||
|
|
||||||
@ -33,22 +34,16 @@ pub struct EtherdreamDevice {
|
|||||||
// pub const NAK_STOP_CONDITION: u8 = 0x21;
|
// pub const NAK_STOP_CONDITION: u8 = 0x21;
|
||||||
// }
|
// }
|
||||||
dac_response: u8,
|
dac_response: u8,
|
||||||
chunk_size: usize,
|
|
||||||
cool_down: Duration, // in milisecs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EtherdreamDevice {
|
impl EtherdreamDevice {
|
||||||
pub fn new(conf: &EtherDreamConf) -> LJResult<Self> {
|
pub fn new(conf: &EtherDreamConf) -> LJResult<Self> {
|
||||||
let (dac, _source_address, stream) = EtherdreamDevice::connect(conf)?;
|
let (dac, _source_address, stream) = EtherdreamDevice::connect(conf)?;
|
||||||
|
|
||||||
let chunk_size = dac.buffer_capacity / 10;
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
conf: (*conf).clone(),
|
conf: (*conf).clone(),
|
||||||
dac,
|
dac,
|
||||||
stream,
|
stream,
|
||||||
dac_response: DacResponse::ACK,
|
dac_response: DacResponse::ACK,
|
||||||
chunk_size: chunk_size.into(),
|
|
||||||
cool_down: Duration::from_millis(20),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fn connect(conf: &EtherDreamConf) -> LJResult<(DacBroadcast, SocketAddr, Stream)> {
|
fn connect(conf: &EtherDreamConf) -> LJResult<(DacBroadcast, SocketAddr, Stream)> {
|
||||||
@ -58,10 +53,11 @@ impl EtherdreamDevice {
|
|||||||
info!("Attempting to get DAC broadcast...");
|
info!("Attempting to get DAC broadcast...");
|
||||||
let broadcast = dac_broadcast
|
let broadcast = dac_broadcast
|
||||||
.take(3)
|
.take(3)
|
||||||
.filter_map(|result| match result {
|
.filter_map(|result| {
|
||||||
|
match result {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!("Failed to find a valid DAC via broadcast. Error: {:?}", err);
|
warn!( "Failed to find a valid DAC via broadcast. Error: {:?}", err);
|
||||||
info!("Retrying...");
|
info!( "Retrying...");
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
Ok((dac, source_addr)) => {
|
Ok((dac, source_addr)) => {
|
||||||
@ -77,11 +73,14 @@ impl EtherdreamDevice {
|
|||||||
}
|
}
|
||||||
Some(Ok((dac, source_addr)))
|
Some(Ok((dac, source_addr)))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.next()
|
.next()
|
||||||
.expect("Failed to receive broadcast.");
|
.expect("Failed to receive broadcast.");
|
||||||
match broadcast {
|
match broadcast {
|
||||||
Err(err) => Err(Box::new(LJError::EtherdreamConnectError(err))),
|
Err(err) => {
|
||||||
|
Err(Box::new(LJError::EtherdreamConnectError(err)))
|
||||||
|
}
|
||||||
Ok((dac, source_addr)) => {
|
Ok((dac, source_addr)) => {
|
||||||
info!("Trying to open TCP stream...");
|
info!("Trying to open TCP stream...");
|
||||||
let stream = EtherdreamDevice::get_tcp_stream(&dac, &source_addr)?;
|
let stream = EtherdreamDevice::get_tcp_stream(&dac, &source_addr)?;
|
||||||
@ -118,10 +117,9 @@ impl EtherdreamDevice {
|
|||||||
.data(sine_wave.by_ref().take(400))
|
.data(sine_wave.by_ref().take(400))
|
||||||
// .data(begin_list.into_iter().take(400 as usize))
|
// .data(begin_list.into_iter().take(400 as usize))
|
||||||
.begin(0, points_per_second)
|
.begin(0, points_per_second)
|
||||||
.submit()
|
.submit() {
|
||||||
{
|
Err(err) => warn!("err occurred when submitting first data: {}",err),
|
||||||
Err(err) => warn!("err occurred when submitting first data: {}", err),
|
Ok(_) => info!("Sent first data to Etherdream.")
|
||||||
Ok(_) => info!("Sent first data to Etherdream."),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(stream)
|
Ok(stream)
|
||||||
@ -132,14 +130,14 @@ impl EtherdreamDevice {
|
|||||||
Determine the number of points needed to fill the DAC.
|
Determine the number of points needed to fill the DAC.
|
||||||
***/
|
***/
|
||||||
// Fixme thread 'main' panicked at 'attempt to subtract with overflow', src/device/etherdream.rs:144:24
|
// Fixme thread 'main' panicked at 'attempt to subtract with overflow', src/device/etherdream.rs:144:24
|
||||||
let n_points = self.dac.buffer_capacity as i64
|
let n_points = self.dac.buffer_capacity as usize - self.stream.dac().dac.status.buffer_fullness as usize - 1;
|
||||||
- self.stream.dac().dac.status.buffer_fullness as i64
|
n_points
|
||||||
- 1;
|
|
||||||
n_points.max(0) as usize
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ping(&mut self) -> LJResult<()> {
|
fn ping(&mut self) -> LJResult<()> {
|
||||||
|
|
||||||
Ok(self.stream.queue_commands().ping().submit()?)
|
Ok(self.stream.queue_commands().ping().submit()?)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,76 +165,69 @@ impl Device for EtherdreamDevice {
|
|||||||
// status
|
// status
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&mut self, line: Vec<Point>, _speed: u32) -> LJResult<()> {
|
fn draw(&mut self,
|
||||||
|
line: Vec<Point>,
|
||||||
|
_speed: u32,
|
||||||
|
) -> LJResult<()> {
|
||||||
|
let chunk_size = 64;
|
||||||
let points_iter = line.into_iter();
|
let points_iter = line.into_iter();
|
||||||
for chunk in points_iter.as_slice().chunks(self.chunk_size) {
|
for chunk in points_iter.as_slice().chunks(chunk_size){
|
||||||
debug!("New chunk length: {:?}", chunk.len());
|
debug!("New chunk length: {:?}", chunk.len());
|
||||||
debug!("Point Cap: {}", self.points_capacity());
|
loop {
|
||||||
debug!("drawing");
|
let capacity = self.points_capacity();
|
||||||
let mut cool_down = self.cool_down;
|
if chunk.len() > capacity {
|
||||||
let mut i = 0;
|
debug!("Sleep, capacity : {:?}", capacity);
|
||||||
while self.points_capacity() < chunk.len() {
|
// Sleep for 1/100th of a sec
|
||||||
debug!(
|
sleep(Duration::new( 0, 10000000));
|
||||||
"Buffer full, waiting... (Point Cap: {}), cool_down: {:?}",
|
|
||||||
self.points_capacity(),
|
|
||||||
self.cool_down
|
|
||||||
);
|
|
||||||
sleep(cool_down);
|
|
||||||
self.ping()?;
|
self.ping()?;
|
||||||
if i > 0 {
|
} else {
|
||||||
cool_down *= 2;
|
break;
|
||||||
}
|
}
|
||||||
i += 1;
|
|
||||||
}
|
}
|
||||||
if i > 1 {
|
debug!("drawing");
|
||||||
info!(
|
match self.stream
|
||||||
"Cool_down adjusted from {:?} to {:?}",
|
|
||||||
self.cool_down, cool_down
|
|
||||||
);
|
|
||||||
self.cool_down = cool_down;
|
|
||||||
}
|
|
||||||
|
|
||||||
match self
|
|
||||||
.stream
|
|
||||||
.queue_commands()
|
.queue_commands()
|
||||||
.data(
|
.data(
|
||||||
chunk
|
chunk.iter()
|
||||||
.iter()
|
|
||||||
.map(|point| (*point).into())
|
.map(|point| (*point).into())
|
||||||
.take(self.chunk_size),
|
.take(chunk_size)
|
||||||
)
|
)
|
||||||
.submit()
|
.submit() {
|
||||||
{
|
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// We should account for
|
// We should account for
|
||||||
// 'Broken pipe (os error 32)'
|
// 'Broken pipe (os error 32)'
|
||||||
// Connection reset by peer (os error 104)
|
// Connection reset by peer (os error 104)
|
||||||
self.dac_response = match err {
|
self.dac_response = match err {
|
||||||
CommunicationError::Io(err) => {
|
CommunicationError::Io(err) => {
|
||||||
warn!("IO ERROR while drawing: '{}'", err);
|
warn!("IO ERROR while drawing: '{}'",err);
|
||||||
DacResponse::ACK
|
DacResponse::ACK
|
||||||
}
|
}
|
||||||
CommunicationError::Protocol(err) => {
|
CommunicationError::Protocol(err) => {
|
||||||
warn!("Protocol ERROR while drawing: '{}'", err);
|
warn!("Protocol ERROR while drawing: '{}'",err);
|
||||||
DacResponse::ACK
|
DacResponse::ACK
|
||||||
}
|
}
|
||||||
CommunicationError::Response(err) => {
|
CommunicationError::Response(err) => {
|
||||||
warn!("Response ERROR while drawing: '{}'", err);
|
warn!("Response ERROR while drawing: '{}'",err);
|
||||||
err.response.response
|
err.response.response
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
self.dac_response = DacResponse::ACK;
|
self.dac_response = DacResponse::ACK;
|
||||||
|
// debug!("Draw is ok");
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stop(&mut self) -> LJResult<()> {
|
fn stop(&mut self) -> LJResult<()> {
|
||||||
info!("Stopping Etherdream device...");
|
info!("Stopping Etherdream device...");
|
||||||
match self.stream.queue_commands().stop().submit() {
|
match self.stream
|
||||||
|
.queue_commands()
|
||||||
|
.stop()
|
||||||
|
.submit()
|
||||||
|
{
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!("Failed to stop EtherDream device with error {:?}", err);
|
warn!("Failed to stop EtherDream device with error {:?}", err);
|
||||||
Err(Box::new(err))
|
Err(Box::new(err))
|
||||||
@ -252,73 +243,21 @@ impl Device for EtherdreamDevice {
|
|||||||
let dim_mid = 16000.0;
|
let dim_mid = 16000.0;
|
||||||
let dim_max = 32000.0;
|
let dim_max = 32000.0;
|
||||||
let col_min = Color { r: 0, g: 0, b: 0 };
|
let col_min = Color { r: 0, g: 0, b: 0 };
|
||||||
let col_max = Color {
|
let col_max = Color { r: 255, g: 255, b: 255 };
|
||||||
r: 255,
|
|
||||||
g: 255,
|
|
||||||
b: 255,
|
|
||||||
};
|
|
||||||
|
|
||||||
vec![
|
vec![
|
||||||
Point {
|
Point { x: -dim_max, y: dim_max, color: col_min },
|
||||||
x: -dim_max,
|
Point { x: -dim_max, y: dim_max, color: col_max },
|
||||||
y: dim_max,
|
Point { x: dim_max, y: dim_max, color: col_max },
|
||||||
color: col_min,
|
Point { x: dim_max, y: -dim_max, color: col_max },
|
||||||
},
|
Point { x: -dim_max, y: -dim_max, color: col_max },
|
||||||
Point {
|
Point { x: -dim_max, y: -dim_mid, color: col_min },
|
||||||
x: -dim_max,
|
Point { x: -dim_mid, y: dim_mid, color: col_min },
|
||||||
y: dim_max,
|
Point { x: -dim_mid, y: dim_mid, color: col_max },
|
||||||
color: col_max,
|
Point { x: dim_mid, y: dim_mid, color: col_max },
|
||||||
},
|
Point { x: dim_mid, y: -dim_mid, color: col_max },
|
||||||
Point {
|
Point { x: -dim_mid, y: -dim_mid, color: col_max },
|
||||||
x: dim_max,
|
Point { x: -dim_mid, y: -dim_mid, color: col_min },
|
||||||
y: dim_max,
|
|
||||||
color: col_max,
|
|
||||||
},
|
|
||||||
Point {
|
|
||||||
x: dim_max,
|
|
||||||
y: -dim_max,
|
|
||||||
color: col_max,
|
|
||||||
},
|
|
||||||
Point {
|
|
||||||
x: -dim_max,
|
|
||||||
y: -dim_max,
|
|
||||||
color: col_max,
|
|
||||||
},
|
|
||||||
Point {
|
|
||||||
x: -dim_max,
|
|
||||||
y: -dim_mid,
|
|
||||||
color: col_min,
|
|
||||||
},
|
|
||||||
Point {
|
|
||||||
x: -dim_mid,
|
|
||||||
y: dim_mid,
|
|
||||||
color: col_min,
|
|
||||||
},
|
|
||||||
Point {
|
|
||||||
x: -dim_mid,
|
|
||||||
y: dim_mid,
|
|
||||||
color: col_max,
|
|
||||||
},
|
|
||||||
Point {
|
|
||||||
x: dim_mid,
|
|
||||||
y: dim_mid,
|
|
||||||
color: col_max,
|
|
||||||
},
|
|
||||||
Point {
|
|
||||||
x: dim_mid,
|
|
||||||
y: -dim_mid,
|
|
||||||
color: col_max,
|
|
||||||
},
|
|
||||||
Point {
|
|
||||||
x: -dim_mid,
|
|
||||||
y: -dim_mid,
|
|
||||||
color: col_max,
|
|
||||||
},
|
|
||||||
Point {
|
|
||||||
x: -dim_mid,
|
|
||||||
y: -dim_mid,
|
|
||||||
color: col_min,
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
use crate::conf::HeliosConf;
|
use std::time::SystemTime;
|
||||||
use crate::device::{Device, PlaybackState, Status};
|
///
|
||||||
use crate::errors::{LJError, LJResult};
|
/// Configure udev:
|
||||||
use crate::point::{Color, Point};
|
/// https://github.com/Grix/helios_dac/blob/master/docs/udev_rules_for_linux.md
|
||||||
use chrono::{DateTime, Utc};
|
///
|
||||||
|
use helios_dac::{NativeHeliosDac, NativeHeliosDacController};
|
||||||
use helios_dac::{
|
use helios_dac::{
|
||||||
// Coordinate,
|
// Coordinate,
|
||||||
// Color,
|
// Color,
|
||||||
@ -10,14 +11,12 @@ use helios_dac::{
|
|||||||
Frame,
|
Frame,
|
||||||
// Point as HeliosPoint,
|
// Point as HeliosPoint,
|
||||||
};
|
};
|
||||||
///
|
use crate::conf::HeliosConf;
|
||||||
/// Configure udev:
|
use crate::device::{Device, Status, PlaybackState};
|
||||||
/// https://github.com/Grix/helios_dac/blob/master/docs/udev_rules_for_linux.md
|
use crate::errors::{LJError, LJResult};
|
||||||
///
|
use crate::point::{Color, Point};
|
||||||
use helios_dac::{NativeHeliosDac, NativeHeliosDacController};
|
use chrono::{DateTime, Utc};
|
||||||
use std::time::SystemTime;
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub struct HeliosDevice {
|
pub struct HeliosDevice {
|
||||||
pub conf: HeliosConf,
|
pub conf: HeliosConf,
|
||||||
dac: NativeHeliosDac,
|
dac: NativeHeliosDac,
|
||||||
@ -63,7 +62,10 @@ impl Device for HeliosDevice {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&mut self, line: Vec<Point>, speed: u32) -> LJResult<()> {
|
fn draw(&mut self,
|
||||||
|
line: Vec<Point>,
|
||||||
|
speed: u32,
|
||||||
|
) -> LJResult<()> {
|
||||||
self.state = PlaybackState::IDLE;
|
self.state = PlaybackState::IDLE;
|
||||||
while let Ok(DeviceStatus::NotReady) = self.dac.status() {}
|
while let Ok(DeviceStatus::NotReady) = self.dac.status() {}
|
||||||
self.state = PlaybackState::PLAYING;
|
self.state = PlaybackState::PLAYING;
|
||||||
@ -86,73 +88,21 @@ impl Device for HeliosDevice {
|
|||||||
let dim_mid = 2047.0;
|
let dim_mid = 2047.0;
|
||||||
let dim_max = 4095.0;
|
let dim_max = 4095.0;
|
||||||
let col_min = Color { r: 0, g: 0, b: 0 };
|
let col_min = Color { r: 0, g: 0, b: 0 };
|
||||||
let col_max = Color {
|
let col_max = Color { r: 255, g: 255, b: 255 };
|
||||||
r: 255,
|
|
||||||
g: 255,
|
|
||||||
b: 255,
|
|
||||||
};
|
|
||||||
|
|
||||||
vec![
|
vec![
|
||||||
Point {
|
Point { x: dim_min, y: dim_max, color: col_min },
|
||||||
x: dim_min,
|
Point { x: dim_min, y: dim_max, color: col_max },
|
||||||
y: dim_max,
|
Point { x: dim_max, y: dim_max, color: col_max },
|
||||||
color: col_min,
|
Point { x: dim_max, y: dim_min, color: col_max },
|
||||||
},
|
Point { x: dim_min, y: dim_min, color: col_max },
|
||||||
Point {
|
Point { x: dim_min, y: dim_min, color: col_min },
|
||||||
x: dim_min,
|
Point { x: dim_min, y: dim_mid, color: col_min },
|
||||||
y: dim_max,
|
Point { x: dim_min, y: dim_mid, color: col_max },
|
||||||
color: col_max,
|
Point { x: dim_mid, y: dim_mid, color: col_max },
|
||||||
},
|
Point { x: dim_mid, y: dim_min, color: col_max },
|
||||||
Point {
|
Point { x: dim_min, y: dim_min, color: col_max },
|
||||||
x: dim_max,
|
Point { x: dim_min, y: dim_min, color: col_min },
|
||||||
y: dim_max,
|
|
||||||
color: col_max,
|
|
||||||
},
|
|
||||||
Point {
|
|
||||||
x: dim_max,
|
|
||||||
y: dim_min,
|
|
||||||
color: col_max,
|
|
||||||
},
|
|
||||||
Point {
|
|
||||||
x: dim_min,
|
|
||||||
y: dim_min,
|
|
||||||
color: col_max,
|
|
||||||
},
|
|
||||||
Point {
|
|
||||||
x: dim_min,
|
|
||||||
y: dim_min,
|
|
||||||
color: col_min,
|
|
||||||
},
|
|
||||||
Point {
|
|
||||||
x: dim_min,
|
|
||||||
y: dim_mid,
|
|
||||||
color: col_min,
|
|
||||||
},
|
|
||||||
Point {
|
|
||||||
x: dim_min,
|
|
||||||
y: dim_mid,
|
|
||||||
color: col_max,
|
|
||||||
},
|
|
||||||
Point {
|
|
||||||
x: dim_mid,
|
|
||||||
y: dim_mid,
|
|
||||||
color: col_max,
|
|
||||||
},
|
|
||||||
Point {
|
|
||||||
x: dim_mid,
|
|
||||||
y: dim_min,
|
|
||||||
color: col_max,
|
|
||||||
},
|
|
||||||
Point {
|
|
||||||
x: dim_min,
|
|
||||||
y: dim_min,
|
|
||||||
color: col_max,
|
|
||||||
},
|
|
||||||
Point {
|
|
||||||
x: dim_min,
|
|
||||||
y: dim_min,
|
|
||||||
color: col_min,
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
92
src/main.rs
92
src/main.rs
@ -1,29 +1,28 @@
|
|||||||
mod conf;
|
|
||||||
mod device;
|
|
||||||
mod errors;
|
|
||||||
mod framerate;
|
|
||||||
mod point;
|
|
||||||
///
|
///
|
||||||
/// Configure udev:
|
/// Configure udev:
|
||||||
/// https://github.com/Grix/helios_dac/blob/master/docs/udev_rules_for_linux.md
|
/// https://github.com/Grix/helios_dac/blob/master/docs/udev_rules_for_linux.md
|
||||||
///
|
///
|
||||||
mod redis_ctrl;
|
mod redis_ctrl;
|
||||||
|
mod conf;
|
||||||
|
mod errors;
|
||||||
|
mod point;
|
||||||
mod transformer;
|
mod transformer;
|
||||||
|
mod device;
|
||||||
mod worldstate;
|
mod worldstate;
|
||||||
|
mod framerate;
|
||||||
|
|
||||||
use conf::Conf;
|
|
||||||
use device::device_factory;
|
use device::device_factory;
|
||||||
use env_logger::Builder;
|
|
||||||
use errors::LJResult;
|
|
||||||
use framerate::Framerate;
|
|
||||||
use log::{/* warn, */ error, info, LevelFilter};
|
|
||||||
use point::{Color, Point};
|
|
||||||
use redis_ctrl::{Order, RedisCtrl};
|
|
||||||
use std::io::Read;
|
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use redis_ctrl::{RedisCtrl, Order};
|
||||||
|
use conf::Conf;
|
||||||
|
use errors::LJResult;
|
||||||
|
use point::{Point, Color};
|
||||||
use transformer::Transformers;
|
use transformer::Transformers;
|
||||||
|
use log::{LevelFilter, info, /* warn, */ error};
|
||||||
|
use env_logger::Builder;
|
||||||
use worldstate::WorldState;
|
use worldstate::WorldState;
|
||||||
|
use framerate::Framerate;
|
||||||
|
|
||||||
const DEFAULT_CONF_FILE: &str = "settings.toml";
|
const DEFAULT_CONF_FILE: &str = "settings.toml";
|
||||||
|
|
||||||
@ -36,6 +35,7 @@ pub fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn run_all() -> LJResult<()> {
|
fn run_all() -> LJResult<()> {
|
||||||
// Setup handler for interrupt Signals
|
// Setup handler for interrupt Signals
|
||||||
let running = Arc::new(AtomicBool::new(true));
|
let running = Arc::new(AtomicBool::new(true));
|
||||||
@ -45,33 +45,13 @@ fn run_all() -> LJResult<()> {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
// Setup configuration file and set up logs
|
// Setup configuration file and set up logs
|
||||||
let filename = std::env::args()
|
let filename = std::env::args().nth(1).unwrap_or_else(|| {
|
||||||
.nth(1)
|
DEFAULT_CONF_FILE.to_string()
|
||||||
.unwrap_or_else(|| DEFAULT_CONF_FILE.to_string());
|
});
|
||||||
|
|
||||||
// read conf from stdin?
|
let config = Conf::new(&filename);
|
||||||
let config = if filename == "-" {
|
|
||||||
println!("Awaiting JSON config on standard input...");
|
|
||||||
let mut buff = String::new();
|
|
||||||
loop {
|
|
||||||
let mut buff2: Vec<u8> = vec![0; 4096];
|
|
||||||
let Ok(n) = std::io::stdin().read(&mut buff2) else {
|
|
||||||
panic!("read failled");
|
|
||||||
};
|
|
||||||
let s = std::str::from_utf8(&buff2[0..n]).unwrap();
|
|
||||||
buff.push_str(&s);
|
|
||||||
|
|
||||||
if n == 0 || buff2[n - 1] == 0 {
|
|
||||||
let config = toml::from_str(&buff[0..buff.len() - 1])?;
|
|
||||||
break Ok(config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Conf::new(&filename)
|
|
||||||
};
|
|
||||||
init_logging(&config);
|
init_logging(&config);
|
||||||
let config = config?;
|
let config = config?;
|
||||||
|
|
||||||
info!("*** Starting up ***");
|
info!("*** Starting up ***");
|
||||||
|
|
||||||
info!("{:?}", config);
|
info!("{:?}", config);
|
||||||
@ -82,6 +62,7 @@ fn run_all() -> LJResult<()> {
|
|||||||
let mut world_state = rs.init_world_state().unwrap();
|
let mut world_state = rs.init_world_state().unwrap();
|
||||||
info!("WorldState: {:?}", world_state);
|
info!("WorldState: {:?}", world_state);
|
||||||
|
|
||||||
|
|
||||||
// Setup Laser Device based on conf
|
// Setup Laser Device based on conf
|
||||||
let mut tracer = device_factory(&config)?;
|
let mut tracer = device_factory(&config)?;
|
||||||
world_state.grid = tracer.grid();
|
world_state.grid = tracer.grid();
|
||||||
@ -104,13 +85,19 @@ fn run_all() -> LJResult<()> {
|
|||||||
// 3 : Draw GRID point list
|
// 3 : Draw GRID point list
|
||||||
world_state.draw_black = order == Order::Black;
|
world_state.draw_black = order == Order::Black;
|
||||||
world_state.draw_grid = order == Order::Grid;
|
world_state.draw_grid = order == Order::Grid;
|
||||||
let frame = get_next_frame(&config, &transformers, &mut rs, &world_state)?;
|
let frame = get_next_frame(
|
||||||
|
&config,
|
||||||
|
&transformers,
|
||||||
|
&mut rs,
|
||||||
|
&world_state,
|
||||||
|
)?;
|
||||||
// For now, draw all the time
|
// For now, draw all the time
|
||||||
tracer.draw(frame, world_state.kpps)?;
|
tracer.draw(frame, world_state.kpps)?;
|
||||||
}
|
}
|
||||||
Order::Intensity => {
|
Order::Intensity => {
|
||||||
// 6 : Max Intensity Change = reread redis key /intensity
|
// 6 : Max Intensity Change = reread redis key /intensity
|
||||||
world_state.intensity = rs.get_int("intensity")?.try_into()?;
|
world_state.intensity = rs.get_int("intensity")?
|
||||||
|
.try_into()?;
|
||||||
}
|
}
|
||||||
Order::Edh => {
|
Order::Edh => {
|
||||||
// 1 : Get the new EDH = reread redis key /EDH/lasernumber
|
// 1 : Get the new EDH = reread redis key /EDH/lasernumber
|
||||||
@ -130,9 +117,9 @@ fn run_all() -> LJResult<()> {
|
|||||||
Order::Resampler => {
|
Order::Resampler => {
|
||||||
world_state.resampler = rs.get_resampler()?;
|
world_state.resampler = rs.get_resampler()?;
|
||||||
}
|
}
|
||||||
Order::PowerOff => {
|
_ => {
|
||||||
info!("PowerOff command recieved.");
|
// 9 : poweroff LJ
|
||||||
break;
|
info!("Order: {:?}", order);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,7 +137,9 @@ fn init_logging(config: &LJResult<Conf>) {
|
|||||||
LevelFilter::Info
|
LevelFilter::Info
|
||||||
};
|
};
|
||||||
let mut builder = Builder::from_default_env();
|
let mut builder = Builder::from_default_env();
|
||||||
builder.filter(None, level).init();
|
builder
|
||||||
|
.filter(None, level)
|
||||||
|
.init();
|
||||||
info!("Debug mode enabled from configuration file");
|
info!("Debug mode enabled from configuration file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -164,7 +153,9 @@ fn get_next_frame(
|
|||||||
rs: &mut RedisCtrl,
|
rs: &mut RedisCtrl,
|
||||||
world_state: &WorldState,
|
world_state: &WorldState,
|
||||||
) -> LJResult<Vec<Point>> {
|
) -> LJResult<Vec<Point>> {
|
||||||
let format_key = format!("{}{}", world_state.client_key, config.laser_id);
|
let format_key = format!("{}{}",
|
||||||
|
world_state.client_key,
|
||||||
|
config.laser_id);
|
||||||
|
|
||||||
// Handle the grid case
|
// Handle the grid case
|
||||||
|
|
||||||
@ -172,7 +163,9 @@ fn get_next_frame(
|
|||||||
world_state.grid.clone()
|
world_state.grid.clone()
|
||||||
} else {
|
} else {
|
||||||
let redis_line = rs.get_line(&format_key)?;
|
let redis_line = rs.get_line(&format_key)?;
|
||||||
redis_line.into_iter().map(|tpl| tpl.into()).collect()
|
redis_line.into_iter()
|
||||||
|
.map(|tpl| tpl.into())
|
||||||
|
.collect()
|
||||||
};
|
};
|
||||||
|
|
||||||
for transformer in transformers {
|
for transformer in transformers {
|
||||||
@ -183,8 +176,7 @@ fn get_next_frame(
|
|||||||
// info!("Draw Grid -> {}", world_state.draw_grid);
|
// info!("Draw Grid -> {}", world_state.draw_grid);
|
||||||
|
|
||||||
// LIMITER and BLACK
|
// LIMITER and BLACK
|
||||||
line = line
|
line = line.into_iter()
|
||||||
.into_iter()
|
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
let color = if world_state.draw_black {
|
let color = if world_state.draw_black {
|
||||||
Color { r: 0, g: 0, b: 0 }
|
Color { r: 0, g: 0, b: 0 }
|
||||||
@ -195,10 +187,14 @@ fn get_next_frame(
|
|||||||
b: p.color.b.min(world_state.intensity),
|
b: p.color.b.min(world_state.intensity),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Point { color, ..p }
|
Point {
|
||||||
|
color,
|
||||||
|
..p
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
//info!("Line: {:?}", line);
|
//info!("Line: {:?}", line);
|
||||||
Ok(line)
|
Ok(line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
use redis::{Client, Commands, Connection};
|
||||||
|
use ron::de::from_str;
|
||||||
use crate::device::Status;
|
use crate::device::Status;
|
||||||
use crate::errors::{LJError, LJResult};
|
use crate::errors::{LJError, LJResult};
|
||||||
use crate::worldstate::{WorldState, EDH};
|
use crate::worldstate::{WorldState, EDH};
|
||||||
use redis::{Client, Commands, Connection};
|
|
||||||
use ron::de::from_str;
|
|
||||||
// use log::info;
|
// use log::info;
|
||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
@ -17,7 +17,7 @@ pub enum Order {
|
|||||||
Intensity,
|
Intensity,
|
||||||
Kpps,
|
Kpps,
|
||||||
ColorBalance,
|
ColorBalance,
|
||||||
PowerOff,
|
PowerOff
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<u8> for Order {
|
impl TryFrom<u8> for Order {
|
||||||
@ -26,7 +26,7 @@ impl TryFrom<u8> for Order {
|
|||||||
fn try_from(value: u8) -> Result<Self, Self::Error> {
|
fn try_from(value: u8) -> Result<Self, Self::Error> {
|
||||||
use Order::*;
|
use Order::*;
|
||||||
|
|
||||||
if value > 9 {
|
if value > 8 {
|
||||||
return Err("order out of range".to_string());
|
return Err("order out of range".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,29 +41,27 @@ impl TryFrom<u8> for Order {
|
|||||||
7 => Kpps,
|
7 => Kpps,
|
||||||
8 => ColorBalance,
|
8 => ColorBalance,
|
||||||
9 => PowerOff,
|
9 => PowerOff,
|
||||||
_ => unreachable!(),
|
_ => unreachable!()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Line = Vec<(f32, f32, u32)>;
|
pub type Line = Vec<(f32, f32, u32)>;
|
||||||
pub type Resampler = Vec<Vec<(f32, f32)>>;
|
pub type Resampler = Vec<Vec<(f32,f32)>>;
|
||||||
|
|
||||||
pub struct RedisCtrl {
|
pub struct RedisCtrl {
|
||||||
//pub client: Client,
|
pub client: Client,
|
||||||
pub connection: Connection,
|
pub connection: Connection,
|
||||||
laser_id: u8,
|
laser_id: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RedisCtrl {
|
impl RedisCtrl {
|
||||||
pub fn new(url: &str, laser_id: &u8) -> LJResult<Self> {
|
pub fn new(url: &str, laser_id: &u8) -> LJResult<Self> {
|
||||||
let client = Client::open(url).map_err(LJError::RedisConnect)?;
|
let client = Client::open(url)
|
||||||
let connection = client.get_connection().map_err(LJError::RedisConnect)?;
|
.map_err(LJError::RedisConnect)?;
|
||||||
Ok(RedisCtrl {
|
let connection = client.get_connection()
|
||||||
//client,
|
.map_err(LJError::RedisConnect)?;
|
||||||
connection,
|
Ok(RedisCtrl { client, connection, laser_id: *laser_id })
|
||||||
laser_id: *laser_id,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_line(&mut self, key: &str) -> LJResult<Line> {
|
pub fn get_line(&mut self, key: &str) -> LJResult<Line> {
|
||||||
@ -130,11 +128,9 @@ impl RedisCtrl {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_resampler(&mut self) -> LJResult<Resampler> {
|
pub fn get_resampler(&mut self ) -> LJResult<Resampler> {
|
||||||
let val: String = self
|
let val: String = self.connection.get(format!("/resampler/{}", self.laser_id))?;
|
||||||
.connection
|
let resampler : Resampler = from_str(&val)?;
|
||||||
.get(format!("/resampler/{}", self.laser_id))?;
|
|
||||||
let resampler: Resampler = from_str(&val)?;
|
|
||||||
Ok(resampler)
|
Ok(resampler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,27 +1,28 @@
|
|||||||
use crate::point::Point;
|
|
||||||
use crate::transformer::Transformers;
|
|
||||||
use crate::worldstate::WorldState;
|
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
use crate::transformer::Transformers;
|
||||||
|
use crate::point::Point;
|
||||||
|
use crate::worldstate::WorldState;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
/// Converts helios Geometry to Helios
|
/// Converts helios Geometry to Helios
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
||||||
pub struct Intensity {}
|
pub struct Intensity {
|
||||||
|
}
|
||||||
|
|
||||||
impl Transformers for Intensity {
|
impl Transformers for Intensity {
|
||||||
fn apply(&self, point_list: &[Point], ws: &WorldState) -> Vec<Point> {
|
fn apply(&self, point_list: &[Point], ws: &WorldState) -> Vec<Point> {
|
||||||
// debug!("list helios {:?}", point_list);
|
// debug!("list helios {:?}", point_list);
|
||||||
let out = point_list
|
let out = point_list.iter().map(|pt| {
|
||||||
.iter()
|
Point {
|
||||||
.map(|pt| Point {
|
|
||||||
x: pt.x,
|
x: pt.x,
|
||||||
y: pt.y,
|
y: pt.y,
|
||||||
color: pt.color * ws.intensity,
|
color: pt.color * ws.intensity
|
||||||
})
|
}
|
||||||
.collect();
|
}).collect();
|
||||||
//debug!("list intensity {:?}", out);
|
debug!("list intensity {:?}", out);
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user