Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
raspberry_Holographic
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张泽仁
raspberry_Holographic
Commits
e170692d
Commit
e170692d
authored
Nov 03, 2023
by
张泽仁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
develop version 2023.11.3 back from suihua
parent
4c35b5cf
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
297 additions
and
54 deletions
+297
-54
interface.c
raspberrypi_spi/LocalDimming/interface.c
+203
-54
read.c
raspberrypi_spi/LocalDimming/read.c
+39
-0
send.c
raspberrypi_spi/LocalDimming/send.c
+55
-0
No files found.
raspberrypi_spi/LocalDimming/interface.c
View file @
e170692d
/*------------------------------------------------
angle for test below
--------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
...
...
@@ -32,6 +37,7 @@ int fileusb;
int
fileuart
;
int
t
=
0
;
int
spi_fd
;
...
...
@@ -57,7 +63,7 @@ int xfm_Init()
}
printf
(
"/dev/ttyUSB0 Open success
\r\n
"
);
if
((
fileuart
=
serialOpen
(
"/dev/ttyAMA0"
,
1152
00
))
<
0
)
if
((
fileuart
=
serialOpen
(
"/dev/ttyAMA0"
,
96
00
))
<
0
)
{
printf
(
"/dev/ttyAMA0 Open Faild
\r\n
"
);
return
0
;
...
...
@@ -89,11 +95,10 @@ void protocalAck(int fileusb)
}
// get angle and change into 16bits, return;
uint16_
t
getAngle
(
char
*
rece
)
in
t
getAngle
(
char
*
rece
)
{
uint16_
t
angle
;
in
t
angle
;
int
result
=
0
;
int
i
=
0
;
char
*
p
=
rece
;
while
(
*
(
p
+
i
)
!=
'a'
||
*
(
p
+
i
+
1
)
!=
'n'
)
...
...
@@ -116,9 +121,8 @@ uint16_t getAngle(char *rece)
angle
=
result
;
return
angle
;
}
// crc
uint16_t
CrcValueCalc
(
uint8_t
*
cpucData
,
uint16_t
usLength
)
uint16_t
CrcValueCalc
(
uint8_t
*
cpucData
,
uint16_t
usLength
)
//changed
{
uint16_t
crcValue
=
0xffff
;
int
i
;
...
...
@@ -139,10 +143,10 @@ uint16_t CrcValueCalc(uint8_t *cpucData, uint16_t usLength)
}
return
crcValue
;
}
extern
int
get_audio_device_id
();
void
sendMessageHead
(
int
mode
,
char
*
message
)
void
sendMessageHead
(
int
mode
,
char
*
message
)
//changed
{
*
(
message
)
=
0x40
;
*
(
message
+
1
)
=
0x38
;
// head
...
...
@@ -154,11 +158,13 @@ void sendMessageHead(int mode, char* message)
*
(
message
+
6
)
=
0x01
;
//ack
}
else
{
// write
*
(
message
+
2
)
=
0x0
9
;
//length
*
(
message
+
2
)
=
0x0
b
;
//length
*
(
message
+
3
)
=
0x06
;
//instru
*
(
message
+
4
)
=
0x00
;
//reg0
*
(
message
+
5
)
=
0x02
;
//reg1 write angle
*
(
message
+
8
)
=
0x00
;
//ack
*
(
message
+
5
)
=
0x02
;
//reg1 write
*
(
message
+
6
)
=
0x00
;
*
(
message
+
7
)
=
0x00
;
*
(
message
+
8
)
=
0x00
;
}
}
...
...
@@ -166,15 +172,15 @@ void sentMessageAngle(int fileuart, uint16_t angle) //changed
{
char
messageAngle
[
11
];
sendMessageHead
(
1
,
messageAngle
);
messageAngle
[
6
]
=
(
angle
>>
8
)
&
0xff
;
messageAngle
[
7
]
=
angle
&
0xff
;
messageAngle
[
9
]
=
(
angle
>>
8
)
&
0xff
;
messageAngle
[
10
]
=
angle
&
0xff
;
uint16_t
crc
;
crc
=
CrcValueCalc
(
messageAngle
,
9
);
messageAngle
[
9
]
=
(
crc
>>
8
)
&
0xff
;
messageAngle
[
1
0
]
=
crc
&
0xff
;
crc
=
CrcValueCalc
(
messageAngle
,
11
);
messageAngle
[
12
]
=
(
crc
>>
8
)
&
0xff
;
messageAngle
[
1
1
]
=
crc
&
0xff
;
write
(
fileuart
,
messageAngle
,
1
1
);
write
(
fileuart
,
messageAngle
,
1
3
);
}
char
*
readMessageAngle
(
int
fileuart
)
...
...
@@ -272,6 +278,110 @@ void waitforReady_test(int fileuart) //test_version
}
}
int
last
=
0
;
int
reality
=
0
;
int
dealAngle
(
int
angle
)
{
int
result
=
0
;
int
ret
=
0
;
if
(
last
<=
1800
){
int
max
=
last
+
1800
;
if
(
angle
>=
last
&&
angle
<=
max
){
//turn leftji
result
=
angle
-
last
;
//prshortf("sent message = %d\n", reality + result);
}
else
{
//turn right
if
(
last
>
angle
){
result
=
angle
-
last
;
//prshortf("sent message = %d\n", reality + result);
}
else
{
result
=
last
+
(
3600
-
angle
);
result
=
-
result
;
//prshortf("sent message = %d\n", reality + result);
}
}
}
else
{
int
over
=
last
-
1800
;
if
(
angle
>=
over
&&
angle
<=
last
){
//turn right
result
=
angle
-
last
;
//prshortf("sent message = %d\n", reality + result);
}
else
{
//turn left
if
(
angle
<
over
){
result
=
angle
+
3600
-
last
;
//prshortf("sent message = %d\n", reality + result);
}
else
{
result
=
angle
-
last
;
//prshortf("sent message = %d\n", reality + result);
}
}
}
ret
=
reality
+
result
;
return
ret
;
}
void
sentUart
(
char
*
buf
,
int
fileuart
,
int
fileusb
)
{
if
(
count
==
9
)
//9
{
strcat
(
totalbuf
,
buf
);
int
angle
;
angle
=
getAngle
(
totalbuf
);
if
(
g_callback
!=
NULL
)
{
char
buf
[
256
]
=
{
0
};
snprintf
(
buf
,
256
,
"cvlc --play-and-exit --aout alsa --alsa-audio-device hw:%d,0 /usr/local/bin/Videos/vioce_hello_L.wav &"
,
get_audio_device_id
());
//system("mpg321 /usr/local/bin/Videos/aaaa.mp3 &");
//system("cvlc --play-and-exit --aout alsa --alsa-audio-device hw:2,0 /usr/local/bin/Videos/aaaa.mp3 &");
system
(
buf
);
g_callback
(
g_callback_ctx
,
2
);
}
char
message1
[
13
]
=
{
0x40
,
0x38
,
0xb
,
0x6
,
0x0
,
0x2
,
0x1
,
0xff
,
0xff
,
0xff
,
0xa6
,
0xdc
,
0xa6
};
if
(
angle
>=
1420
+
200
)
{
//0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x2, 0xee, 0x9c, 0x24 left 45
char
messageleft
[
13
]
=
{
char
message1
[
13
]
=
{
0x40
,
0x38
,
0xb
,
0x6
,
0x0
,
0x2
,
0x1
,
0xff
,
0xff
,
0xff
,
0xa6
,
0xdc
,
0xa6
};};
write
(
fileuart
,
messageleft
,
13
);
}
else
if
(
angle
<=
1420
-
200
)
{
//0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x2, 0xee, 0x9c, 0x24 right 45
char
messageright
[
13
]
=
{
0x40
,
0x38
,
0xb
,
0x6
,
0x0
,
0x2
,
0x1
,
0x0
,
0x0
,
0x3
,
0x52
,
0x9c
,
0x5
};
write
(
fileuart
,
messageright
,
13
);
}
else
{
char
messageReset1
[
13
]
=
{
0x40
,
0x38
,
0xb
,
0x6
,
0x0
,
0x2
,
0x1
,
0x0
,
0x0
,
0x1
,
0x2c
,
0x1d
,
0x45
};
write
(
fileuart
,
messageReset1
,
13
);
}
count
=
1
;
memset
(
totalbuf
,
0
,
1024
);
serialFlush
(
fileusb
);
}
else
{
count
++
;
strcat
(
totalbuf
,
buf
);
}
}
/*
void sentUart(char *buf, int fileuart, int fileusb) //changed
{
if (count == 9)
...
...
@@ -280,14 +390,36 @@ void sentUart(char *buf, int fileuart, int fileusb) //changed
uint16_t angle;
angle = getAngle(totalbuf);
printf("angle = %x\n", angle);
sentMessageAngle(fileuart, angle);
//sentMessageAngle(fileuart, angle);
// 0x40 0x38 0x0b 0x06 0x00 0x02 0x01 00 -- -- -- 1d 08 0
// 04 b0 1e 7c 120
// char message1[13] = {0x40, 0x38, 0x0b, 0x06, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x08};
// char message2[13] = {0x40, 0x38, 0x0b, 0x06, 0x00, 0x02, 0x01, 0x00, 0x00, 0x04, 0xb0, 0x1e, 0x7c};
// if (t == 0){
// write(fileuart, message1, 13);
// t = 1;
// }
// else{
// write(fileuart, message2, 13);
// t = 0;
// }
count = 1;
memset(totalbuf, 0, 1024);
protocalAck(fileusb);
waitforReady_test
(
fileuart
);
if (g_callback != NULL)
{
char buf[256] = {0};
snprintf(buf, 256, "cvlc --play-and-exit --aout alsa --alsa-audio-device hw:%d,0 /usr/local/bin/Videos/aaaa.mp3 &", get_audio_device_id());
//system("mpg321 /usr/local/bin/Videos/aaaa.mp3 &");
//system("cvlc --play-and-exit --aout alsa --alsa-audio-device hw:2,0 /usr/local/bin/Videos/aaaa.mp3 &");
system(buf);
g_callback(g_callback_ctx, 2);
}
//waitforReady_test(fileuart);
}
else
...
...
@@ -297,13 +429,29 @@ void sentUart(char *buf, int fileuart, int fileusb) //changed
}
}
*/
unsigned
int
time_reset
=
0
;
void
circleReading
()
//changed
{
printf
(
"cicleReading..
\n
"
);
serialFlush
(
fileusb
);
//send zero reset
char
messageReset
[
13
]
=
{
0x40
,
0x38
,
0xb
,
0x6
,
0x0
,
0x2
,
0x1
,
0x0
,
0x0
,
0x1
,
0x2c
,
0x1d
,
0x45
};
write
(
fileuart
,
messageReset
,
13
);
while
(
1
)
{
time_reset
++
;
if
(
time_reset
==
47000
*
300
)
{
write
(
fileuart
,
messageReset
,
13
);
time_reset
=
0
;
continue
;
}
int
recbytenum
=
serialDataAvail
(
fileusb
);
char
buf
[
1024
]
=
{
0
};
if
(
recbytenum
>
1
)
...
...
@@ -322,7 +470,7 @@ void circleReading() //changed
else
{
sentUart
(
buf
,
fileuart
,
fileusb
);
printf
(
" %d
\n
"
,
__LINE__
);
serialFlush
(
fileusb
);
//guarantee buf wont affect next input
//
serialFlush(fileusb); //guarantee buf wont affect next input
}
}
}
...
...
@@ -521,7 +669,8 @@ void eachPicWrite(int num, int pic)
int
ops
=
op
[
i
];
for
(
int
j
=
0
;
j
<
18
;
j
++
)
{
AW20144_Byte_Write
(
chips
,
AW20144_PAGE1
,
num
+
offset
,
LocalDimmingLedData
[
pic
][
i
*
18
+
j
]);
AW20144_Byte_Write
(
chips
,
AW20144_PAGE1
,
num
+
offset
,
0xff
);
//LocalDimmingLedData[pic][i*18 + j]
//AW20144_Byte_Write(chips, AW20144_PAGE1, num+offset, *(a + temp));
//printf("%d\n", num+offset);
//printf("%x\n", *(a + temp));
...
...
@@ -529,38 +678,38 @@ void eachPicWrite(int num, int pic)
num
=
(
num
+
1
)
%
18
;
}
}
}
//
}
/*
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>
#include <stdint.h>
#include <wiringPi.h>
#include<wiringSerial.h>
#include <string.h>
int main()
{
int fileuart;
if ((fileuart = serialOpen("/dev/ttyAMA0", 9600)) < 0)
{
printf("/dev/ttyAMA0 Open Faild\r\n");
// return 0;
}
printf("/dev/ttyAMA0 Open success\r\n");
// void sentUart(char *buf, int fileuart)
// {
// if (count == 9)
// {
// strcat(totalbuf, buf);
// uint16_t angle;
// angle = getAngle(totalbuf);
// printf("angle = %x\n", angle);
// char angleret[2];
// angleret[1] = angle & 0xff;
// angleret[0] = (angle >> 8) & 0xff;
// write(fileuart, angleret, 2);
// count = 1;
// memset(totalbuf, 0, 1024);
// if (g_callback != NULL){
// char buf[256] = {0};
// snprintf(buf, 256, "cvlc --play-and-exit --aout alsa --alsa-audio-device hw:%d,0 /usr/local/bin/Videos/aaaa.mp3 &", get_audio_device_id());
// //system("mpg321 /usr/local/bin/Videos/aaaa.mp3 &");
// //system("cvlc --play-and-exit --aout alsa --alsa-audio-device hw:2,0 /usr/local/bin/Videos/aaaa.mp3 &");
// system(buf);
// g_callback(g_callback_ctx, 2);
// }
// }
// else
// {
// count++;
// strcat(totalbuf, buf);
// }
// }
\ No newline at end of file
char message1[13] = {0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0xff, 0xff, 0xff, 0xa6, 0xdc, 0xa6};
char message2[13] = {0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x1, 0x2c, 0x1d, 0x45};
char message3[13] = {0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x3, 0x52, 0x9c, 0x5};
write(fileuart, message1, 13);
//0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0xff, 0xff, 0xff, 0xf1, 0x9d, 0x58 left
//0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x1, 0x2c, 0x1d, 0x45, 30
//0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x2, 0xee, 0x9c, 0x24 right
return 0;
}*/
\ No newline at end of file
raspberrypi_spi/LocalDimming/read.c
0 → 100644
View file @
e170692d
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>
#include <stdint.h>
#include <wiringPi.h>
#include <string.h>
int
main
()
{
int
fileuart
;
if
((
fileuart
=
serialOpen
(
"/dev/ttyAMA0"
,
9600
))
<
0
)
{
printf
(
"/dev/ttyAMA0 Open Faild
\r\n
"
);
// return 0;
}
printf
(
"/dev/ttyAMA0 Open success
\r\n
"
);
char
message
[
9
]
=
{
0x40
,
0x38
,
0xb
,
0x6
,
0x0
,
0x2
,
0x1
,
0x2b
,
0x58
};
write
(
fileuart
,
message
,
9
);
char
buf
[
100
]
=
{
0
};
int
recbytenum
=
serialDataAvail
(
filedevid
);
for
(
int
i
=
0
;
i
<
recbytenum
;
i
++
)
{
buf
[
i
]
=
serialGetchar
(
filedevid
);
}
for
(
int
i
=
0
;
i
<
recbytenum
;
i
++
)
{
printf
(
"%x "
,
buf
[
i
]);
}
printf
(
"
\n
"
);
int
angle
=
(
buf
[
7
]
<<
24
)
|
(
buf
[
8
]
<<
16
)
|
(
buf
[
9
]
<<
8
)
|
buf
[
10
];
printf
(
"angle = %d
\n
"
,
angle
);
return
0
;
}
\ No newline at end of file
raspberrypi_spi/LocalDimming/send.c
0 → 100644
View file @
e170692d
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include <string.h>
// crc
uint16_t
CrcValueCalc
(
uint8_t
*
cpucData
,
uint16_t
usLength
)
// changed
{
uint16_t
crcValue
=
0xffff
;
int
i
;
while
(
usLength
--
)
{
crcValue
^=
*
cpucData
++
;
for
(
i
=
8
-
1
;
i
>=
0
;
i
--
)
{
if
(
crcValue
&
0x0001
)
{
crcValue
=
(
crcValue
>>
1
)
^
0xa001
;
}
else
{
crcValue
=
crcValue
>>
1
;
}
}
}
return
crcValue
;
}
int
main
()
{
//a 10 b11 c12 d13
unsigned
char
mess
[
13
]
=
{
0x40
,
0x38
,
0x0b
,
0x06
,
0x00
,
0x02
,
0x01
,
0xff
,
0xff
,
0xff
,
0xa6
,
0x00
,
0x00
};
uint16_t
crc
=
CrcValueCalc
(
mess
,
11
);
mess
[
11
]
=
crc
&
0xff
;
mess
[
12
]
=
(
crc
>>
8
)
&
0xff
;
for
(
int
i
=
0
;
i
<
13
;
i
++
)
{
printf
(
"0x%x, "
,
mess
[
i
]);
}
printf
(
"
\n
"
);
return
0
;
}
// 120 0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x4, 0xb0, 0x1e, 0x7c,
// 0 0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x0, 0x0, 0x1d, 0x8,
// 60 0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x2, 0x58, 0x1d, 0x92,
// 90 0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x8, 0x84, 0x1a, 0xab,
// 150 0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x5, 0xdc, 0x1f, 0xc1,
// 30 0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x1, 0x2c, 0x1d, 0x45,
// 85 0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0x0, 0x0, 0x3, 0x52, 0x9c, 0x5
// -25 0x40, 0x38, 0xb, 0x6, 0x0, 0x2, 0x1, 0xff, 0xff, 0xff, 0xe7, 0x1c, 0x96,
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment