Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MiniMatrixRPi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MiniMatrixTeam
MiniMatrixRPi
Commits
de947f1b
Commit
de947f1b
authored
Jun 12, 2021
by
ftomi
Browse files
Options
Downloads
Patches
Plain Diff
spisender periodic async
parent
4c8af8a9
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
test_anim/spisender.cpp
+52
-0
52 additions, 0 deletions
test_anim/spisender.cpp
test_anim/spisender.h
+14
-3
14 additions, 3 deletions
test_anim/spisender.h
with
66 additions
and
3 deletions
test_anim/spisender.cpp
+
52
−
0
View file @
de947f1b
#include
"spisender.h"
#include
"spisender.h"
#include
"ola_receiver.h"
#include
"wiringPi.h"
#include
"wiringPi.h"
#include
"wiringPiSPI.h"
#include
"wiringPiSPI.h"
#include
<unistd.h>
#include
<unistd.h>
#include
<stdint.h>
#include
<stdint.h>
pthread_mutex_t
SpiSender
::
mutex_frame
=
PTHREAD_MUTEX_INITIALIZER
;
SpiSender
::
SpiSender
()
SpiSender
::
SpiSender
()
{
{
wiringPiSetup
();
wiringPiSetup
();
...
@@ -17,11 +20,20 @@ SpiSender::SpiSender()
...
@@ -17,11 +20,20 @@ SpiSender::SpiSender()
fd
=
wiringPiSPISetup
(
SPI_CHANNEL
,
SPI_SPEED
);
fd
=
wiringPiSPISetup
(
SPI_CHANNEL
,
SPI_SPEED
);
uint8_t
dummy
=
0
;
uint8_t
dummy
=
0
;
wiringPiSPIDataRW
(
SPI_CHANNEL
,
&
dummy
,
1
);
wiringPiSPIDataRW
(
SPI_CHANNEL
,
&
dummy
,
1
);
exit_flag
=
false
;
pthread_attr_t
attr
;
pthread_attr_init
(
&
attr
);
pthread_attr_setdetachstate
(
&
attr
,
PTHREAD_CREATE_JOINABLE
);
pthread_create
(
&
sender_thread
,
&
attr
,
SpiSender
::
sender_caller
,
(
void
*
)
this
);
pthread_attr_destroy
(
&
attr
);
}
}
SpiSender
::~
SpiSender
()
SpiSender
::~
SpiSender
()
{
{
close
(
fd
);
close
(
fd
);
exit_flag
=
true
;
pthread_join
(
sender_thread
,
NULL
);
}
}
bool
SpiSender
::
sendFrame
(
const
SpiFrame
&
frame
)
const
bool
SpiSender
::
sendFrame
(
const
SpiFrame
&
frame
)
const
...
@@ -37,4 +49,44 @@ bool SpiSender::canSend() const
...
@@ -37,4 +49,44 @@ bool SpiSender::canSend() const
{
{
return
digitalRead
(
readyPin
);
return
digitalRead
(
readyPin
);
}
}
void
*
SpiSender
::
sender_caller
(
void
*
arg
)
{
SpiSender
*
sender
=
(
SpiSender
*
)
arg
;
printf
(
"Spi thread started.
\n
"
);
sender
->
sender_loop
();
pthread_exit
(
NULL
);
}
void
SpiSender
::
sender_loop
()
{
while
(
!
exit_flag
)
{
if
(
canSend
())
{
pthread_mutex_lock
(
&
mutex_frame
);
sendFrame
(
SpiFrame
(
frame
));
pthread_mutex_unlock
(
&
mutex_frame
);
}
//printf("Frame sent.\n");
usleep
(
6000
);
}
printf
(
"SpiSender thread exit"
);
}
void
SpiSender
::
exit
()
{
exit_flag
=
true
;
}
void
SpiSender
::
updateFrame
(
const
MxFrame
&
newFrame
,
int
startY
,
int
endY
)
{
pthread_mutex_lock
(
&
mutex_frame
);
for
(
size_t
y
=
startY
;
y
<=
endY
;
y
++
)
{
for
(
size_t
x
=
0
;
x
<
32
;
x
++
)
{
frame
.
pixels
[
y
][
x
]
=
newFrame
.
pixels
[
y
][
x
];
}
}
pthread_mutex_unlock
(
&
mutex_frame
);
}
This diff is collapsed.
Click to expand it.
test_anim/spisender.h
+
14
−
3
View file @
de947f1b
...
@@ -2,22 +2,33 @@
...
@@ -2,22 +2,33 @@
#define SPISENDER_H
#define SPISENDER_H
#include
"spiframe.h"
#include
"spiframe.h"
#include
<pthread.h>
#include
<atomic>
class
SpiSender
class
SpiSender
{
{
private:
private:
const
int
readyPin
=
6
;
// WiringPi PIN. (22 on header)
const
int
readyPin
=
6
;
// WiringPi PIN. (22 on header)
const
int
resetPin
=
5
;
// WiringPi PIN. (18 on header)
const
int
resetPin
=
5
;
// WiringPi PIN. (18 on header)
const
int
SPI_SPEED
=
1800000
;
const
int
SPI_SPEED
=
1800000
0
;
const
int
SPI_CHANNEL
=
0
;
const
int
SPI_CHANNEL
=
0
;
int
fd
=
0
;
int
fd
=
0
;
bool
firstFrame
=
true
;
bool
firstFrame
=
true
;
bool
sendFrame
(
const
SpiFrame
&
frame
)
const
;
bool
canSend
()
const
;
MxFrame
frame
;
pthread_t
sender_thread
;
static
pthread_mutex_t
mutex_frame
;
std
::
atomic
<
bool
>
exit_flag
;
static
void
*
sender_caller
(
void
*
arg
);
void
sender_loop
();
public:
public:
SpiSender
();
SpiSender
();
~
SpiSender
();
~
SpiSender
();
bool
sendFrame
(
const
SpiFrame
&
frame
)
const
;
void
exit
()
;
bool
canSend
()
const
;
void
updateFrame
(
const
MxFrame
&
newFrame
,
int
startY
=
0
,
int
endY
=
25
)
;
};
};
#endif // SPISENDER_H
#endif // SPISENDER_H
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