Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
boytacean
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
João Magalhães
boytacean
Commits
d8b80f0f
Verified
Commit
d8b80f0f
authored
1 year ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
chore: made image buffer local variable
parent
eefec196
No related branches found
No related tags found
1 merge request
!23
Support for serial data transfer 🔌
Pipeline
#2516
failed
1 year ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/devices/printer.rs
+6
-24
6 additions, 24 deletions
src/devices/printer.rs
with
6 additions
and
24 deletions
src/devices/printer.rs
+
6
−
24
View file @
d8b80f0f
...
@@ -118,7 +118,6 @@ pub struct PrinterDevice {
...
@@ -118,7 +118,6 @@ pub struct PrinterDevice {
data
:
[
u8
;
0x280
],
data
:
[
u8
;
0x280
],
image
:
[
u8
;
160
*
200
],
image
:
[
u8
;
160
*
200
],
image_offset
:
u16
,
image_offset
:
u16
,
image_buffer
:
Vec
<
u8
>
,
callback
:
fn
(
image_buffer
:
&
Vec
<
u8
>
)
callback
:
fn
(
image_buffer
:
&
Vec
<
u8
>
)
}
}
...
@@ -136,7 +135,6 @@ impl PrinterDevice {
...
@@ -136,7 +135,6 @@ impl PrinterDevice {
data
:
[
0x00
;
0x280
],
data
:
[
0x00
;
0x280
],
image
:
[
0x00
;
160
*
200
],
image
:
[
0x00
;
160
*
200
],
image_offset
:
0
,
image_offset
:
0
,
image_buffer
:
Vec
::
new
(),
callback
:
|
_
|
{}
callback
:
|
_
|
{}
}
}
}
}
...
@@ -153,48 +151,34 @@ impl PrinterDevice {
...
@@ -153,48 +151,34 @@ impl PrinterDevice {
self
.data
=
[
0x00
;
0x280
];
self
.data
=
[
0x00
;
0x280
];
self
.image
=
[
0x00
;
160
*
200
];
self
.image
=
[
0x00
;
160
*
200
];
self
.image_offset
=
0
;
self
.image_offset
=
0
;
self
.clear_image_buffer
()
}
}
pub
fn
set_callback
(
&
mut
self
,
callback
:
fn
(
image_buffer
:
&
Vec
<
u8
>
))
{
pub
fn
set_callback
(
&
mut
self
,
callback
:
fn
(
image_buffer
:
&
Vec
<
u8
>
))
{
self
.callback
=
callback
;
self
.callback
=
callback
;
}
}
pub
fn
image_buffer
(
&
self
)
->
&
Vec
<
u8
>
{
&
self
.image_buffer
}
pub
fn
image_buffer_mut
(
&
mut
self
)
->
&
mut
Vec
<
u8
>
{
&
mut
self
.image_buffer
}
pub
fn
clear_image_buffer
(
&
mut
self
)
{
self
.image_buffer
.clear
();
}
fn
run_command
(
&
mut
self
,
command
:
PrinterCommand
)
{
fn
run_command
(
&
mut
self
,
command
:
PrinterCommand
)
{
match
command
{
match
command
{
PrinterCommand
::
Init
=>
{
PrinterCommand
::
Init
=>
{
self
.status
=
0x00
;
self
.status
=
0x00
;
self
.byte_out
=
self
.status
;
self
.byte_out
=
self
.status
;
self
.image_offset
=
0
;
self
.image_offset
=
0
;
self
.image_buffer
.clear
();
}
}
PrinterCommand
::
Print
=>
{
PrinterCommand
::
Print
=>
{
let
mut
image_buffer
=
Vec
::
new
();
let
palette_index
=
self
.data
[
2
];
let
palette_index
=
self
.data
[
2
];
for
index
in
0
..
self
.image_offset
{
for
index
in
0
..
self
.image_offset
{
let
value
=
self
.image
[
index
as
usize
];
let
value
=
self
.image
[
index
as
usize
];
let
pixel_offset
=
(
palette_index
>>
(
value
<<
1
))
&
0x03
;
let
pixel_offset
=
(
palette_index
>>
(
value
<<
1
))
&
0x03
;
let
pixel
=
PRINTER_PALETTE
[
pixel_offset
as
usize
];
let
pixel
=
PRINTER_PALETTE
[
pixel_offset
as
usize
];
self
.
image_buffer
.push
(
pixel
[
0
]);
image_buffer
.push
(
pixel
[
0
]);
self
.
image_buffer
.push
(
pixel
[
1
]);
image_buffer
.push
(
pixel
[
1
]);
self
.
image_buffer
.push
(
pixel
[
2
]);
image_buffer
.push
(
pixel
[
2
]);
self
.
image_buffer
.push
(
pixel
[
3
]);
image_buffer
.push
(
pixel
[
3
]);
}
}
(
self
.callback
)(
&
self
.
image_buffer
);
(
self
.callback
)(
&
image_buffer
);
self
.byte_out
=
self
.status
;
self
.byte_out
=
self
.status
;
self
.status
=
0x06
;
self
.status
=
0x06
;
...
@@ -222,8 +206,6 @@ impl PrinterDevice {
...
@@ -222,8 +206,6 @@ impl PrinterDevice {
// mark it as done, resetting the status back to
// mark it as done, resetting the status back to
// the original value
// the original value
if
self
.status
==
0x06
{
if
self
.status
==
0x06
{
// @TODO: check if this value should be 0x04 instead
// this seems to be a bug with the print demo
self
.status
=
0x00
;
self
.status
=
0x00
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment