add response for protocol status

This commit is contained in:
Noa Aarts 2024-12-11 12:47:40 +01:00
parent 4a230a08c2
commit 232fe6b6e2
Signed by: noa
GPG key ID: 1850932741EFF672
3 changed files with 41 additions and 0 deletions

View file

@ -53,6 +53,12 @@ fn increment_counter(amount: u64) {
COUNTER.fetch_add(amount, std::sync::atomic::Ordering::Relaxed);
}
#[derive(Debug, PartialEq)]
pub enum ProtocolStatus {
Enabled(&'static str),
Disabled(&'static str),
}
#[derive(Debug, PartialEq)]
pub enum Protocol {
Text,
@ -72,6 +78,7 @@ pub enum Command {
#[derive(Debug, PartialEq)]
pub enum Response {
Help,
Protocols(Vec<ProtocolStatus>),
Size(Coordinate, Coordinate),
GetPixel(Coordinate, Coordinate, [u8; 3]),
}

View file

@ -106,6 +106,23 @@ To set a pixel using RGB, use ({SET_PX_RGB_BIN:02X}) (u8 canvas) (x as u16_le) (
);
writer.write_all(help_text.as_bytes()).await
}
Response::Protocols(protos) => {
for protocol in protos {
match protocol {
crate::ProtocolStatus::Enabled(proto) => {
writer
.write_all(format!("Enabled: {}\n", proto).as_bytes())
.await?;
}
crate::ProtocolStatus::Disabled(proto) => {
writer
.write_all(format!("Disabled: {}\n", proto).as_bytes())
.await?;
}
}
}
Ok(())
}
Response::Size(x, y) => {
writer.write_u16(x).await?;
writer.write_u16(y).await

View file

@ -146,6 +146,23 @@ impl<W: AsyncWriteExt + std::marker::Unpin> Responder<W> for TextParser {
async fn unparse(&self, response: Response, writer: &mut W) -> io::Result<()> {
match response {
Response::Help => writer.write_all(HELP_TEXT).await,
Response::Protocols(protos) => {
for protocol in protos {
match protocol {
crate::ProtocolStatus::Enabled(proto) => {
writer
.write_all(format!("Enabled: {}\n", proto).as_bytes())
.await?;
}
crate::ProtocolStatus::Disabled(proto) => {
writer
.write_all(format!("Disabled: {}\n", proto).as_bytes())
.await?;
}
}
}
Ok(())
}
Response::Size(x, y) => writer.write_all(format!("SIZE {x} {y}\n").as_bytes()).await,
Response::GetPixel(x, y, color) => {
writer