Skip to content

Commit

Permalink
Shake up deps (#209)
Browse files Browse the repository at this point in the history
* note

Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com>

* bump many deps

Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com>

* really bump em

Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com>

* cleanup: drop our atomic crate usage

Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com>

---------

Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com>
  • Loading branch information
fenollp authored Jul 27, 2024
1 parent 343d67d commit 4b9dd6a
Show file tree
Hide file tree
Showing 9 changed files with 391 additions and 573 deletions.
763 changes: 269 additions & 494 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ authors = [
[workspace.dependencies]
anyhow = "1"
async-stream = "0.3"
atomic = "0.5"
chrono = "0.4"
clap = { version = "4", features = ["derive", "env"] }
crc-any = { version = "2", default-features = false, features = ["heapless"] }
env_logger = "0.10"
drawings.path = "drawings"
env_logger = "0.11"
futures = { version = "0.3", default-features = false, features = ["alloc"] }
itertools = "0.12"
itertools = "0.13"
log = "0.4"
nom = "5"
once_cell = "1"
prost = "0.12"
nom = "5" # TODO: bump
pb.path = "pb"
prost = "0.13"
protoc-bin-vendored = "3"
qrcode-generator = "4"
quick-xml = { version = "0.22", features = ["serialize"] }
quick-xml = { version = "0.22", features = ["serialize"] } # TODO: bump
rand = "0.8"
ringbuffer = "0.15"
serde = { version = "1", features = ["derive"] }
serde-jsonlines = { version = "0.5", features = ["async"] }
serde-jsonlines = { version = "0.6", features = ["async"] }
serde_json = "1"
tokio = { version = "1", features = ["rt-multi-thread", "time", "fs", "macros", "net"] }
tokio-stream = { version = "0.1", features = ["net"] }
tonic = "0.11"
tonic-build = "0.11"
tonic = "0.12"
tonic-build = "0.12"
tower = "0.4"
uuid = { version = "1", features = ["v4"] }

Expand Down
2 changes: 1 addition & 1 deletion drawings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ repository.workspace = true
edition.workspace = true

[dependencies]
pb.path = "../pb"
pb.workspace = true
6 changes: 2 additions & 4 deletions marauder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ edition.workspace = true
[dependencies]
anyhow.workspace = true
async-stream.workspace = true
atomic.workspace = true
chrono.workspace = true
clap.workspace = true
crc-any.workspace = true
drawings.path = "../drawings"
drawings.workspace = true
env_logger.workspace = true
itertools.workspace = true
libremarkable.workspace = true
log.workspace = true
nom.workspace = true
once_cell.workspace = true
pb.path = "../pb"
pb.workspace = true
prost.workspace = true
qrcode-generator.workspace = true
quick-xml.workspace = true
Expand Down
85 changes: 39 additions & 46 deletions marauder/src/bin/marauder.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
#[macro_use]
extern crate log;
extern crate env_logger;

use std::{
collections::VecDeque,
process::Command,
sync::{
atomic::{AtomicBool, Ordering},
Mutex,
atomic::{AtomicBool, AtomicI32, AtomicU8, Ordering},
LazyLock, Mutex,
},
thread::sleep,
time::Duration,
};

use atomic::Atomic;
use chrono::{DateTime, Local};
use libremarkable::{
appctx,
appctx::ApplicationContext,
appctx::{self, ApplicationContext},
battery,
framebuffer::{
cgmath, cgmath::EuclideanSpace, common::*, storage, FramebufferDraw, FramebufferIO,
FramebufferRefresh, PartialRefreshMode,
cgmath::{self, EuclideanSpace},
common::*,
storage::{self, CompressedCanvasState},
FramebufferDraw, FramebufferIO, FramebufferRefresh, PartialRefreshMode,
},
image,
image::GenericImage,
image::{self, GenericImage},
input::{
GPIOEvent, InputDevice, InputEvent, MultitouchEvent, PhysicalButton, WacomEvent, WacomPen,
},
ui_extensions::element::{UIConstraintRefresh, UIElement, UIElementHandle, UIElementWrapper},
};
// use rand::Rng;
use marauder::modes::draw::DrawMode;
use marauder::{modes::touch::TouchMode, strokes::Strokes, unipen};
use once_cell::sync::Lazy;
// use marauder::shapes::*;
use log::{debug, error, info};
use marauder::{
modes::{draw::DrawMode, touch::TouchMode},
strokes::Strokes,
unipen,
};

// This region will have the following size at rest:
// raw: 5896 kB
Expand All @@ -48,16 +44,16 @@ const CANVAS_REGION: mxcfb_rect = mxcfb_rect {

type PosNpress = (cgmath::Point2<f32>, i32); // position and pressure

static G_TOUCH_MODE: Lazy<Atomic<TouchMode>> = Lazy::new(|| Atomic::new(TouchMode::OnlyUI));
static G_DRAW_MODE: Lazy<Atomic<DrawMode>> = Lazy::new(|| Atomic::new(DrawMode::default()));
static UNPRESS_OBSERVED: Lazy<AtomicBool> = Lazy::new(|| AtomicBool::new(false));
static WACOM_IN_RANGE: Lazy<AtomicBool> = Lazy::new(|| AtomicBool::new(false));
static WACOM_HISTORY: Lazy<Mutex<VecDeque<PosNpress>>> = Lazy::new(|| Mutex::new(VecDeque::new()));
static DRAWING: Lazy<AtomicBool> = Lazy::new(|| AtomicBool::new(false));
static SAVED_CANVAS: Lazy<Mutex<Option<storage::CompressedCanvasState>>> =
Lazy::new(|| Mutex::new(None));
static SAVED_CANVAS_PREV: Lazy<Mutex<Option<storage::CompressedCanvasState>>> =
Lazy::new(|| Mutex::new(None));
static G_TOUCH_MODE: LazyLock<AtomicU8> = LazyLock::new(|| AtomicU8::new(TouchMode::OnlyUI.into()));
static G_DRAW_MODE: LazyLock<AtomicI32> = LazyLock::new(Default::default);
static UNPRESS_OBSERVED: LazyLock<AtomicBool> = LazyLock::new(Default::default);
static WACOM_IN_RANGE: LazyLock<AtomicBool> = LazyLock::new(Default::default);
static WACOM_HISTORY: LazyLock<Mutex<VecDeque<PosNpress>>> = LazyLock::new(Default::default);
static DRAWING: LazyLock<AtomicBool> = LazyLock::new(Default::default);
static SAVED_CANVAS: LazyLock<Mutex<Option<CompressedCanvasState>>> =
LazyLock::new(Default::default);
static SAVED_CANVAS_PREV: LazyLock<Mutex<Option<CompressedCanvasState>>> =
LazyLock::new(Default::default);

// ####################
// ## Button Handlers
Expand All @@ -72,7 +68,7 @@ fn on_undo(app: &mut ApplicationContext, _: UIElementHandle) {
let framebuffer = app.get_framebuffer_ref();
// TODO: restore & refresh only the subset region that was just drawn onto
match framebuffer.restore_region(CANVAS_REGION, &decompressed) {
Err(e) => error!("Error while restoring region: {0}", e),
Err(e) => error!("Error while restoring region: {e}"),
Ok(_) => {
framebuffer.partial_refresh(
&CANVAS_REGION,
Expand Down Expand Up @@ -106,7 +102,7 @@ fn save_canvas(app: &mut ApplicationContext) {
let mut prev = SAVED_CANVAS_PREV.lock().unwrap();
*prev = Some((*compressed_state).clone());
}
*hist = Some(storage::CompressedCanvasState::new(
*hist = Some(CompressedCanvasState::new(
buff.as_slice(),
CANVAS_REGION.height,
CANVAS_REGION.width,
Expand Down Expand Up @@ -219,11 +215,11 @@ fn on_invert_canvas(app: &mut ApplicationContext, element: UIElementHandle) {
}

fn on_toggle_eraser(app: &mut ApplicationContext, _: UIElementHandle) {
let (new_mode, next_name) = match G_DRAW_MODE.load(Ordering::Relaxed) {
let (new_mode, next_name) = match DrawMode::from(G_DRAW_MODE.load(Ordering::Relaxed)) {
DrawMode::Erase(s) => (DrawMode::Draw(s), "Switch to BLACK".to_owned()),
DrawMode::Draw(s) => (DrawMode::Erase(s), "Switch to WHITE".to_owned()),
};
G_DRAW_MODE.store(new_mode, Ordering::Relaxed);
G_DRAW_MODE.store(new_mode.into(), Ordering::Relaxed);

let element = app.get_element_by_name("colorToggle").unwrap();
if let UIElement::Text { ref mut text, .. } = element.write().inner {
Expand All @@ -233,8 +229,8 @@ fn on_toggle_eraser(app: &mut ApplicationContext, _: UIElementHandle) {
}

fn on_tap_touchdraw_mode(app: &mut ApplicationContext, _: UIElementHandle) {
let new_val = G_TOUCH_MODE.load(Ordering::Relaxed).toggle();
G_TOUCH_MODE.store(new_val, Ordering::Relaxed);
let new_val = TouchMode::from(G_TOUCH_MODE.load(Ordering::Relaxed)).toggle();
G_TOUCH_MODE.store(new_val.into(), Ordering::Relaxed);

let element = app.get_element_by_name("touchdrawMode").unwrap();
if let UIElement::Text { ref mut text, .. } = element.write().inner {
Expand All @@ -250,21 +246,15 @@ fn on_tap_touchdraw_mode(app: &mut ApplicationContext, _: UIElementHandle) {
// ####################

fn change_brush_width(app: &mut ApplicationContext, delta: i32) {
let current = G_DRAW_MODE.load(Ordering::Relaxed);
let current = DrawMode::from(G_DRAW_MODE.load(Ordering::Relaxed));
let current_size = current.get_size() as i32;
let proposed_size = current_size + delta;
let new_size = if proposed_size < 1 {
1
} else if proposed_size > 99 {
99
} else {
proposed_size
};
let new_size = proposed_size.clamp(1, 99);
if new_size == current_size {
return;
}

G_DRAW_MODE.store(current.set_size(new_size as u32), Ordering::Relaxed);
G_DRAW_MODE.store(current.set_size(new_size as u32).into(), Ordering::Relaxed);

let element = app.get_element_by_name("displaySize").unwrap();
if let UIElement::Text { ref mut text, .. } = element.write().inner {
Expand Down Expand Up @@ -342,7 +332,7 @@ fn on_wacom_input(app: &mut ApplicationContext, input: WacomEvent) {
DRAWING.store(true, Ordering::Relaxed);
}

let (col, mult) = match G_DRAW_MODE.load(Ordering::Relaxed) {
let (col, mult) = match G_DRAW_MODE.load(Ordering::Relaxed).into() {
DrawMode::Draw(s) => (color::BLACK, s),
DrawMode::Erase(s) => (color::WHITE, s * 3),
};
Expand Down Expand Up @@ -427,7 +417,7 @@ fn on_touch_handler(app: &mut ApplicationContext, input: MultitouchEvent) {
if !CANVAS_REGION.contains_point(&position.cast().unwrap()) {
return;
}
let rect = match G_TOUCH_MODE.load(Ordering::Relaxed) {
let rect = match G_TOUCH_MODE.load(Ordering::Relaxed).into() {
TouchMode::Bezier => {
let position_float = position.cast().unwrap();
let points = [
Expand Down Expand Up @@ -690,7 +680,10 @@ fn main() {
UIElementWrapper {
position: (1080, 670).into(),
inner: UIElement::Text {
text: format!("size: {0}", G_DRAW_MODE.load(Ordering::Relaxed).get_size()),
text: format!(
"size: {0}",
DrawMode::from(G_DRAW_MODE.load(Ordering::Relaxed)).get_size()
),
border_px: 0,
foreground: color::BLACK,
scale: 45.0,
Expand Down
36 changes: 22 additions & 14 deletions marauder/src/bin/whiteboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
sync::{
atomic::{AtomicBool, AtomicU32, Ordering},
mpsc::{self, Receiver},
Mutex, OnceLock, RwLock,
LazyLock, Mutex, OnceLock, RwLock,
},
time::Duration,
};
Expand All @@ -28,8 +28,10 @@ use libremarkable::{
ui_extensions::element::{UIConstraintRefresh, UIElement, UIElementWrapper},
};
use log::{debug, error, info, warn};
use marauder::{buttons::Button, fonts};
use once_cell::sync::Lazy;
use marauder::{
buttons::Button,
fonts::{self, Font},
};
use pb::proto::hypercards::{
drawing::Color, event, screen_sharing_client::ScreenSharingClient,
whiteboard_client::WhiteboardClient, Drawing, Event, RecvEventsReq, SendEventReq,
Expand Down Expand Up @@ -84,6 +86,12 @@ const TOOLBAR_BAR_WIDTH: u32 = 2;
const TOOLBAR_HEIGHT: u32 = 70 + TOOLBAR_BAR_WIDTH;
const TOOLBAR_REGION: mxcfb_rect =
mxcfb_rect { top: 0, left: 0, height: TOOLBAR_HEIGHT, width: DISPLAYWIDTH as u32 };
// (0,0) --x-> (x=1404,0)
// |
// y
// |
// v
// (0,1872)
const CANVAS_REGION: mxcfb_rect = mxcfb_rect {
top: TOOLBAR_HEIGHT,
left: 0,
Expand All @@ -94,21 +102,21 @@ const CANVAS_REGION: mxcfb_rect = mxcfb_rect {
type SomeRawImage = image::ImageBuffer<image::Rgb<u8>, Vec<u8>>;
type PosNpress = (Point2<f32>, i32); // position and pressure

static PEOPLE_COUNT: Lazy<AtomicU32> = Lazy::new(|| AtomicU32::new(0));
static WACOM_IN_RANGE: Lazy<AtomicBool> = Lazy::new(|| AtomicBool::new(false));
static WACOM_HISTORY: Lazy<Mutex<VecDeque<PosNpress>>> = Lazy::new(|| Mutex::new(VecDeque::new()));
static SCRIBBLES: Lazy<Mutex<Vec<Scribble>>> = Lazy::new(|| Mutex::new(Vec::new()));
static TX: Lazy<Mutex<Option<mpsc::Sender<Drawing>>>> = Lazy::new(|| Mutex::new(None));
static FONT: Lazy<fonts::Font> = Lazy::new(|| fonts::emsdelight_swash_caps().unwrap());
static NEEDS_SHARING: Lazy<AtomicBool> = Lazy::new(|| AtomicBool::new(true));
static QRCODE: Lazy<RwLock<Option<SomeRawImage>>> = Lazy::new(|| RwLock::new(None));
static PEOPLE_COUNT: LazyLock<AtomicU32> = LazyLock::new(Default::default);
static WACOM_IN_RANGE: LazyLock<AtomicBool> = LazyLock::new(Default::default);
static WACOM_HISTORY: LazyLock<Mutex<VecDeque<PosNpress>>> = LazyLock::new(Default::default);
static SCRIBBLES: LazyLock<Mutex<Vec<Scribble>>> = LazyLock::new(Default::default);
static TX: LazyLock<Mutex<Option<mpsc::Sender<Drawing>>>> = LazyLock::new(Default::default);
static FONT: LazyLock<Font> = LazyLock::new(|| fonts::emsdelight_swash_caps().unwrap());
static NEEDS_SHARING: LazyLock<AtomicBool> = LazyLock::new(|| AtomicBool::new(true));
static QRCODE: LazyLock<RwLock<Option<SomeRawImage>>> = LazyLock::new(Default::default);

static ARGS: OnceLock<Args> = OnceLock::new();

static PEN_BLACK: Lazy<AtomicBool> = Lazy::new(|| AtomicBool::new(true));
static PEN_BLACK: LazyLock<AtomicBool> = LazyLock::new(|| AtomicBool::new(true));

static BTN_ERASE: Lazy<Button> = Lazy::new(|| Button::new(1, "erase"));
static BTN_TIMES3: Lazy<Button> = Lazy::new(|| Button::new(2, "times3"));
static BTN_ERASE: LazyLock<Button> = LazyLock::new(|| Button::new(1, "erase"));
static BTN_TIMES3: LazyLock<Button> = LazyLock::new(|| Button::new(2, "times3"));

const DRAWING_PACE: Duration = Duration::from_millis(2);
const INTER_DRAWING_PACE: Duration = Duration::from_millis(8);
Expand Down
19 changes: 19 additions & 0 deletions marauder/src/modes/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,22 @@ impl DrawMode {
}
}
}

impl From<DrawMode> for i32 {
fn from(mode: DrawMode) -> Self {
match mode {
DrawMode::Draw(s) => s as i32,
DrawMode::Erase(s) => -(s as i32),
}
}
}

impl From<i32> for DrawMode {
fn from(mode: i32) -> Self {
if mode >= 0 {
Self::Draw(mode as u32)
} else {
Self::Erase((-mode) as u32)
}
}
}
25 changes: 25 additions & 0 deletions marauder/src/modes/touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,28 @@ impl TouchMode {
}
}
}

impl From<TouchMode> for u8 {
fn from(mode: TouchMode) -> Self {
match mode {
TouchMode::OnlyUI => 1,
TouchMode::Bezier => 2,
TouchMode::Circles => 3,
TouchMode::Diamonds => 4,
TouchMode::FillDiamonds => 5,
}
}
}

impl From<u8> for TouchMode {
fn from(mode: u8) -> Self {
match mode {
1 => Self::OnlyUI,
2 => Self::Bezier,
3 => Self::Circles,
4 => Self::Diamonds,
5 => Self::FillDiamonds,
_ => panic!("Unmapped mode value: {mode}"),
}
}
}
8 changes: 4 additions & 4 deletions scrolls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ edition.workspace = true

[dependencies]
anyhow.workspace = true
drawings.path = "../drawings"
#drawings.workspace = true
env_logger.workspace = true
libremarkable.workspace = true
log.workspace = true
pb.path = "../pb"
pb.workspace = true
ringbuffer.workspace = true
serde-jsonlines.workspace = true
serde.workspace = true
Expand All @@ -22,8 +22,8 @@ tokio.workspace = true
# lyon_geom = "1"
quick-xml = "0.23"
svg-path-parser = "0.1.1"
svgtypes = "0.15"
#svgtypes = "0.15"
# thiserror = "1"
usvg = "0.42"
#usvg = "0.42"
svg2polylines = "0.8"
vsvg = "0.4"

0 comments on commit 4b9dd6a

Please sign in to comment.