Skip to content

Commit

Permalink
I can draw in real time - woohoo
Browse files Browse the repository at this point in the history
  • Loading branch information
StachuDotNet committed Aug 22, 2021
1 parent eb0eb19 commit f613d53
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 79 deletions.
8 changes: 0 additions & 8 deletions .run/run on rM maybe.run.xml

This file was deleted.

62 changes: 31 additions & 31 deletions reMarkable.fs.Demo/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ open System.Reflection
open System.Threading
open SixLabors.ImageSharp
open SixLabors.ImageSharp.PixelFormats
open SixLabors.Fonts
open SixLabors.ImageSharp.Drawing.Processing
open SixLabors.ImageSharp.Processing
open reMarkable.fs.UI
open reMarkable.fs.Digitizer
open reMarkable.fs
open reMarkable.fs.Display
open reMarkable.fs.UI.Util

let displayDriver = ReMarkable.Display

let reportOnPerformance() =
printfn "NumberOfCores: %A" ReMarkable.Performance.NumberOfCores
Expand All @@ -27,6 +23,7 @@ let reportOnPerformance() =

let drawBeans() =
let img: Image<Rgb24> = Image.Load(Path.Combine(Path.GetDirectoryName (Assembly.GetExecutingAssembly().Location), "blackPepper.jpeg"))
let width, height = 144, 144

for x in 0 .. 2 .. 13 do
for y in 0 .. 2 .. 17 do
Expand All @@ -35,10 +32,10 @@ let drawBeans() =

ReMarkable.Display.DrawAndRefresh
{ Image = img
SrcArea = Rectangle(0, 0, 144, 144)
SrcArea = Rectangle(0, 0, width, height)
DestPoint = Point(destX, destY)

RefreshArea = Rectangle(destX, destY, 144, 144) |> Some
RefreshArea = Rectangle(destX, destY, width, height) |> Some
WaveformMode = None
DisplayTemp = None
UpdateMode = Some UpdateMode.Partial }
Expand All @@ -50,6 +47,7 @@ let drawGiantRectangle() =
let height = ReMarkable.Display.Height - (y * 2)

let buffer = new Image<Rgb24>(width, height)
buffer.Mutate(fun z -> z.Clear Color.LightGray |> ignore)

ReMarkable.Display.DrawAndRefresh
{ Image = buffer
Expand All @@ -62,7 +60,6 @@ let drawGiantRectangle() =
UpdateMode = Some UpdateMode.Full }

let drawIcon() =

let glyphs = SegoeMdl2Glyphs.SegoeMdl2.Force()
let icon = glyphs.GetIcon(64, SegoeMdl2Glyphs.Glyphs.Warning)

Expand All @@ -73,8 +70,7 @@ let drawIcon() =
|> ignore

let buffer = new Image<Rgb24>(ReMarkable.Display.Width, ReMarkable.Display.Height)
buffer.Mutate(fun z ->
z.Clear(Color.White) |> ignore)
buffer.Mutate(fun z -> z.Clear(Color.White) |> ignore)
buffer.Mutate draw
ReMarkable.Display.DrawAndRefresh
{ Image = buffer
Expand All @@ -90,7 +86,7 @@ let startDigitizerTracker() =
let mutable prevState: StylusState option = None
let mutable lastUpdated = DateTime.Now

ReMarkable.Digitizer_PleaseReadCommentAtDefinition.StylusUpdate.Add(fun state ->
ReMarkable.Digitizer.StylusUpdate.Add(fun state ->
match prevState with
| Some prev ->
let wasNotPressingBefore = prev.Pressure < 10
Expand All @@ -112,27 +108,31 @@ let main _argv =
ReMarkable.Touchscreen.Pressed.Add (printfn "Pressed: %A")
ReMarkable.Touchscreen.Pressed.Add (printfn "Released: %A")

ReMarkable.Digitizer_PleaseReadCommentAtDefinition.StylusUpdate.Add(fun z ->
printfn "%A" z.NormalizedPosition
ReMarkable.Display.Framebuffer.SetPixel {| Color = Color.Black; X = z.NormalizedPosition.X |> int; Y = z.NormalizedPosition.Y |> int |}

let normalizedPosition = z.NormalizedPosition
let x, y = normalizedPosition.X - 1f |> int, normalizedPosition.Y - 1f |> int
let width = 3
let height = 3

let buffer = new Image<Rgb24>(width, height)
buffer.Mutate(fun z -> z.Clear Color.Black |> ignore)

ReMarkable.Display.DrawAndRefresh
{ Image = buffer
SrcArea = Rectangle(0, 0, width, height)
DestPoint = Point(x, y)

RefreshArea = None
WaveformMode = None
DisplayTemp = None
UpdateMode = Some UpdateMode.Full }
drawGiantRectangle()


ReMarkable.Digitizer.StylusUpdate.Add(fun z ->
if z.Distance = 0 then
let normalizedPosition = z.NormalizedPosition
let x, y = normalizedPosition.X - 1f |> int, 1872f - normalizedPosition.Y + 1f |> int
let width = 3
let height = 3

let buffer = new Image<Rgb24>(width, height)
buffer.Mutate(fun z -> z.Fill Color.Black |> ignore)

//printfn "x, y, width, height"
//ReMarkable.Display.Framebuffer.SetPixel {| Color = Color.Black; X = x; Y = y |}

ReMarkable.Display.DrawAndRefresh
{ Image = buffer
SrcArea = Rectangle(0, 0, width, height)
DestPoint = Point(x, y)

RefreshArea = Rectangle(x, y, width, height) |> Some
WaveformMode = Some WaveformMode.Du
DisplayTemp = None
UpdateMode = Some UpdateMode.Partial }
)


Expand Down
2 changes: 1 addition & 1 deletion reMarkable.fs/Display/Framebuffer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type HardwareFramebuffer(devicePath: string, width: int, height: int) =
//let srcArea, destPoint = (this :> IFramebuffer).ConstrainRectangleToPoint(srcArea, destPoint)
//srcArea.Location <- Point(srcArea.Location.X + destPoint.X - x, srcArea.Location.Y + destPoint.Y - y)

printfn "Area , Point: %A, %A" srcArea destPoint
//printfn "Area , Point: %A, %A" srcArea destPoint

let encoder = makeEncoder width srcArea destPoint

Expand Down
70 changes: 35 additions & 35 deletions reMarkable.fs/Display/IDisplayDriver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,41 @@ type UpdateScheme =
| QueueAndMerge = 2

type WaveformMode =
// /// Screen goes to white (clears)
// Init = 0x0,
//
// /// Basically A2 (so partial refresh shouldn't be possible here)
// Glr16 = 0x4,
//
// /// Official -- and enables Regal D Processing
// Gld16 = 0x5,
//
// /// [Direct Update] Grey->white/grey->black -- remarkable uses this for drawing
// Du = 0x1,
//
// /// High fidelity (flashing)
// Gc16 = 0x2,
//
// /// Medium fidelity -- remarkable uses this for UI
// Gc16Fast = 0x3,
//
// /// Medium fidelity from white transition
// Gl16Fast = 0x6,
//
// /// Medium fidelity 4 level of gray direct update
// Du4 = 0x7,
//
// /// Ghost compensation waveform
// Reagl = 0x8,
//
// /// Ghost compensation waveform with dithering
// Reagld = 0x9,
//
// /// 2-bit from white transition
// Gl4 = 0xA,
//
// /// High fidelity for black transition
// Gl16Inv = 0xB,
/// Screen goes to white (clears)
| Init = 0x0u

/// Basically A2 (so partial refresh shouldn't be possible here)
| Glr16 = 0x4u

/// Official -- and enables Regal D Processing
| Gld16 = 0x5u

/// [Direct Update] Grey->white/grey->black -- remarkable uses this for drawing
| Du = 0x1u

/// High fidelity (flashing)
| Gc16 = 0x2u

/// Medium fidelity -- remarkable uses this for UI
| Gc16Fast = 0x3u

/// Medium fidelity from white transition
| Gl16Fast = 0x6u

/// Medium fidelity 4 level of gray direct update
| Du4 = 0x7u

/// Ghost compensation waveform
| Reagl = 0x8u

/// Ghost compensation waveform with dithering
| Reagld = 0x9u

/// 2-bit from white transition
| Gl4 = 0xAu

/// High fidelity for black transition
| Gl16Inv = 0xBu

/// Official
| Auto = 257u
Expand Down
2 changes: 1 addition & 1 deletion reMarkable.fs/Display/RM2ShimDisplayDriver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type RM2ShimDisplayDriver() =
data.QuantBit <- 0
//data.AltData <- null

printfn $"refreshing; ({data.UpdateRegion.X}, {data.UpdateRegion.Y})"
//printfn $"refreshing; ({data.UpdateRegion.X}, {data.UpdateRegion.Y})"

let retCode = Driver.Ioctl(handle :> SafeHandle, IoctlDisplayCommand.SendUpdate, &data)

Expand Down
6 changes: 3 additions & 3 deletions reMarkable.fs/ReMarkable.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module reMarkable.fs.ReMarkable
[<RequireQualifiedAccess>]
module reMarkable.fs.ReMarkable

open System
open System.IO
Expand Down Expand Up @@ -79,8 +80,7 @@ let PowerSupply =
let Wireless = HardwareWirelessMonitor()

/// Holds an instance of a digitizer driver
/// Warning: this is currently a bit broken - namely, the coordinates are off
let Digitizer_PleaseReadCommentAtDefinition =
let Digitizer =
match CurrentDevice with
| Device.RM1
| Device.RM2 ->
Expand Down

0 comments on commit f613d53

Please sign in to comment.