Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
NaiveWang committed Oct 17, 2019
2 parents d1682e8 + c046d8a commit 1357769
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 7 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
68 changes: 68 additions & 0 deletions device/JetsonNano/rg_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import Jetson.GPIO as GPIO
import time
'''
TM1640 driver and demo, ported from Arduino
'''
alphabet = [
[0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, 0x00, 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, 0x00, 0x00],
[0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, 0x00, 0x00],
[0x42, 0x61, 0x51, 0x49, 0x46, 0x00, 0x00, 0x00, 0x42, 0x61, 0x51, 0x49, 0x46, 0x00, 0x00, 0x00],
[0x22, 0x41, 0x49, 0x49, 0x36, 0x00, 0x00, 0x00, 0x22, 0x41, 0x49, 0x49, 0x36, 0x00, 0x00, 0x00],

[0x18, 0x14, 0x12, 0x7F, 0x10, 0x00, 0x00, 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00, 0x00, 0x00],
[0x4F, 0x49, 0x49, 0x49, 0x31, 0x00, 0x00, 0x00, 0x4F, 0x49, 0x49, 0x49, 0x31, 0x00, 0x00, 0x00],
[0x3E, 0x49, 0x49, 0x49, 0x32, 0x00, 0x00, 0x00, 0x3E, 0x49, 0x49, 0x49, 0x32, 0x00, 0x00, 0x00],
[0x01, 0x01, 0x71, 0x09, 0x07, 0x00, 0x00, 0x00, 0x01, 0x01, 0x71, 0x09, 0x07, 0x00, 0x00, 0x00],

[0x36, 0x49, 0x49, 0x49, 0x36, 0x00, 0x00, 0x00, 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, 0x00, 0x00],
[0x26, 0x49, 0x49, 0x49, 0x3E, 0x00, 0x00, 0x00, 0x26, 0x49, 0x49, 0x49, 0x3E, 0x00, 0x00, 0x00],
[0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, 0x00, 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, 0x00, 0x00],
[0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff]]

din=13
clk=11

def start():
GPIO.output(clk, GPIO.HIGH)
GPIO.output(din, GPIO.HIGH)
GPIO.output(din, GPIO.LOW)
GPIO.output(clk, GPIO.LOW)
def stop():
GPIO.output(clk, GPIO.HIGH)
GPIO.output(din, GPIO.LOW)
GPIO.output(din, GPIO.HIGH)
def write_byte(byte):
GPIO.output(clk, GPIO.LOW)
for i in range(8):
if byte & 0x01 == 0x01:
GPIO.output(din, GPIO.HIGH)
else:
GPIO.output(din, GPIO.LOW)
GPIO.output(clk, GPIO.HIGH)
GPIO.output(clk, GPIO.LOW)
byte>>=1

def cmd(byte):
start()
write_byte(byte)
stop()
def write_block(idx):
start()
write_byte(0xc0)
for i in range(16):
write_byte(alphabet[idx][i])
stop()

def init():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(din, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(clk, GPIO.OUT, initial=GPIO.HIGH)
cmd(0x40)
cmd(0x8c)
init()

for i in range(12):
write_block(i)
time.sleep(0.3)

GPIO.cleanup()
19 changes: 19 additions & 0 deletions device/JetsonNano/time_led.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
I2C=0
SET="i2cset -y $I2C"
declare -a dz=("0x3f" "0x30" "0x5b" "0x79" "0x74" "0x6d" "0x6f" "0x38" "0xff" "0x7d")
echo "start at iic bus $I2C"

$SET 0x24 0x01

while true
do
DATE4=$( date "+%H%M" )
echo $DATE4

$SET 0x34 ${dz[${DATE4:0:1}]}
$SET 0x35 ${dz[${DATE4:1:1}]}
$SET 0x36 ${dz[${DATE4:2:1}]}
$SET 0x37 ${dz[${DATE4:3:1}]}
sleep 1
done
40 changes: 38 additions & 2 deletions examples/hud01/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,41 @@ This is a tutorial for building a hud for Diry Rally

## Wire Setup

## Build Arduino
## Setup Driver & Play
Arduino uno is the same as nano

![image]()

* 8x8 LED

>**CLK -> D8**
>**DIN -> D7**
>**VCC -> 5V**
>**GND -> GND**
* 4 digits

>**SCL -> A5**
>**SDA -> A4**
>**VCC -> VCC**
>**GND -> GND**
* Voltmeter

> **+ -> D6**
> **- -> GND**
## Build Arduino & Start

0. Set up wire
1. Connect Arduino board to your computer.
2. Open, Compile & Upload `hud_dev` project. ( you may encounter a perimission issue, no fuss, just `chmod a+rw` to `/dev/ttyUSBx`port). If it was wired and set properly, the dots of the matrix should be all up either red or green execlusively and the 4 digits LED should be like `----`. ![snapshot]()
3. Assume you have configured your Dirt game properly, configure Arduino port in `driver.py` and start it by `python driver.py` or `python3 driver.py`, now it started to listen on UDP port.

4. Open Dirt game, the hud start to read data while waiting for loading maps
28 changes: 23 additions & 5 deletions subscriber/dummy_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,45 @@
#include <sys/socket.h>
#include <arpa/inet.h>

const short default_port=20777;
char* default_host="0.0.0.0";
const int default_delay=1000;//1000ms

int main(int argc, char **argv)
//input port as the second arg
{
int i, sock, conn;
short port;
char* host;
int delay;
float telemetry[64]; //4*64=256
int broadcastPermission = 1;
//load port
//sgetchar();
sscanf(argv[1], "%d", &port);
printf("port==%d\n", port);
//initialize Diry Dally fake telemetries
if(argc == 4)
{
host = argv[1];
sscanf(argv[2], "%d", &port);
sscanf(argv[3], "%d", &delay);
}
else
{
host = default_host;
port = default_port;
delay = default_delay;
}

printf("host:port==%s:%d broadcast per %dms\n", host, port, delay);
//initialize Diry Dally fake telemetries
delay*=1000;

struct sockaddr_in saddr, baddr;

setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (void *) &broadcastPermission,
sizeof(broadcastPermission));

saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = inet_addr("0.0.0.0");
saddr.sin_addr.s_addr = inet_addr(host);
saddr.sin_port = htons(port);

sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
Expand All @@ -44,7 +62,7 @@ int main(int argc, char **argv)
telemetry[37]=(rand()%1024)*1.f; // current rpm is 700, yield a 70% engine
printf("sended %f %f %f %f\n", telemetry[33], telemetry[7], telemetry[63], telemetry[37]);
sendto(sock, telemetry, 256, 0, &saddr, sizeof(saddr));
usleep(100000);
usleep(delay);
}

return 0;
Expand Down

0 comments on commit 1357769

Please sign in to comment.