Created GUI window with output

- now you can see the serial output in the graphical user interface
- main and gui packages were updated
- readme edit
This commit is contained in:
foglar 2024-02-11 12:01:56 +01:00
parent b37eea2577
commit 895f56c581
5 changed files with 113 additions and 93 deletions

View File

@ -1,32 +1,53 @@
# CobraV2
## Table of contents
- [CobraV2](#cobrav2)
- [Table of contents](#table-of-contents)
- [Installation and compilation](#installation-and-compilation)
- [Serial monitor tool](#serial-monitor-tool)
- [Monitoring tool](#monitoring-tool)
- [Overview](#overview)
- [Arduino Sender Format](#arduino-sender-format)
- [Modules](#modules)
- [10 DOF IMU](#10-dof-imu)
- [L76K GPS](#l76k-gps)
- [NMEA Sentence](#nmea-sentence)
- [NRF24L01+](#nrf24l01)
- [Wiring](#wiring)
- [10 DOF IMU Sensor](#10-dof-imu-sensor)
- [L76K GPS Module](#l76k-gps-module)
- [NRF24L01+ Module](#nrf24l01-module)
- [Issues / features](#issues--features)
- [Sources](#sources)
## Installation and compilation
### Serial monitor tool
```bash
```shell
git clone https://www.github.com/foglar/cobraV2.git
cd cobraV2/serial_read
go get "github.com/tarm/serial"
# Building serial read code yourself
go build .
```
### Monitor tool
> [!TIP]
> You may have to delete `go.mod` file (if you have other go version) and `go mod init` the project.
> To install all dependencies you can use `go mod tidy` command or you can mannualy install them by `go get [package]` command.
```bash
### Monitoring tool
```shell
git clone https://www.github.com/foglar/cobraV2.git
cd cobraV2/monitor
# Installing required packages
go get "github.com/tarm/serial"
# go get "github.com/gopxl/pixel/v2"
go build .
```
> [!IMPORTANT]
> For cross-compiling you will need to specify a `CC` to compile c-based libraries for pixel2 library.
> Example command: `CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go build .`
> For more information see: [Pixel2 Wiki | Cross Compiling](https://github.com/gopxl/pixel/wiki/%5BWIP%5D-Cross-Compiling)
Upload sender and reciever code on the 2 arduino's
## Overview
@ -83,13 +104,12 @@ $GPGAA,HHMMSS.SS,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx
| $GPGAA | HHMMSS.SS | llll.ll a | yyyyy.yy a | x | xx | x.x | x.x M | x.x M | x.x | xxxx | *hh |
| $GPGAA | 170834 | 4124.8963, N | 08151.6838, W | 1 | 05 | 1.5 | 280.2, M | -34.0, M | blank | blank | *75 |
Fix Quality:
- 0 = Invalid
- 1 = GPS fix
- 2 = DGPS fix
[more about nmea sentences](https://aprs.gids.nl/nmea/)
> [!TIP]
> Fix Quality:
> 0 = Invalid;
> 1 = GPS fix;
> 2 = DGPS fix;
> [more about nmea sentences](https://aprs.gids.nl/nmea/)
### NRF24L01+
@ -153,3 +173,4 @@ Datasheets, documentation and sources
- [NRF24L01+ Guide - Guide](https://navody.dratek.cz/navody-k-produktum/arduino-wifi-modul-nrf24l01.html)
- [NRF24L01+ PA/LNA - Datasheet](doc/nrf24lo1-datasheet.pdf)
- [NRF24L01+ PA/LNA - Demo code](https://img.gme.cz/files/eshop_data/eshop_data/10/775-034/prg.775-034.1.zip)
- [Pixel2 (gui library)](https://github.com/gopxl/pixel)

View File

@ -5,17 +5,25 @@ package gui
import (
"io"
"os"
"time"
"github.com/golang/freetype/truetype"
"github.com/gopxl/pixel"
"github.com/gopxl/pixel/pixelgl"
"github.com/gopxl/pixel/text"
"golang.org/x/image/colornames"
"golang.org/x/image/font"
)
func loadTTF(path string, size float64) (font.Face, error) {
// Declare default font and font size
const FONT string = "gui/JetBrainsMonoNerdFont-Medium.ttf"
const SIZE float64 = 36
func LoadFont() (*text.Atlas, error) {
face, err := LoadTTF(FONT, SIZE)
if err != nil {
return nil, err
}
return text.NewAtlas(face, text.ASCII), nil
}
func LoadTTF(path string, size float64) (font.Face, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
@ -37,39 +45,3 @@ func loadTTF(path string, size float64) (font.Face, error) {
GlyphCacheEntries: 1,
}), nil
}
func run() {
cfg := pixelgl.WindowConfig{
Title: "Cobra Monitor",
Bounds: pixel.R(0, 0, 1024, 768),
}
win, err := pixelgl.NewWindow(cfg)
if err != nil {
panic(err)
}
face, err := loadTTF("gui/JetBrainsMonoNerdFont-Medium.ttf", 36)
if err != nil {
panic(err)
}
atlas := text.NewAtlas(face, text.ASCII)
txt := text.New(pixel.V(100, 500), atlas)
fps := time.Tick(time.Second / 120)
for !win.Closed() {
//txt.WriteString(data)
win.Clear(colornames.Black)
txt.Draw(win, pixel.IM)
win.Update()
<-fps
}
}
func GUI() {
pixelgl.Run(run)
}

View File

@ -1,33 +1,60 @@
package main
import (
//"fmt"
"log"
gui "foglar/monitor/gui"
//p "foglar/monitor/parse"
//"foglar/monitor/serial_read"
//"log"
"foglar/monitor/serial_read"
"github.com/gopxl/pixel"
"github.com/gopxl/pixel/pixelgl"
"github.com/gopxl/pixel/text"
"golang.org/x/image/colornames"
)
func main() {
// // Initialize serial connection
// serialHandler, err := serial_read.NewSerialHandler()
// if err != nil {
// log.Fatal(err)
// }
//
// defer serialHandler.Close()
//
// for {
// // Read serial data
// data, err := serialHandler.ReadSerial()
// if err != nil {
// log.Fatal(err)
// }
//
// fmt.Println("Received data:", data)
// fmt.Println(p.Parser(data))
// }
// Testing GUI interface
gui.GUI()
func run() {
// Initialize serial connection
serialHandler, err := serial_read.NewSerialHandler()
if err != nil {
log.Fatal(err)
}
defer serialHandler.Close()
// Create window
cfg := pixelgl.WindowConfig{
Title: "Cobra Monitor",
Bounds: pixel.R(0, 0, 1024, 768),
}
win, err := pixelgl.NewWindow(cfg)
if err != nil {
panic(err)
}
// Load font
atlas, err := gui.LoadFont()
if err != nil {
panic(err)
}
txt := text.New(pixel.V(100, 500), atlas)
// Window update
for !win.Closed() {
data, err := serialHandler.ReadSerial()
if err != nil {
log.Fatal(err)
}
txt.WriteString(data)
win.Clear(colornames.Black)
txt.Draw(win, pixel.IM)
win.Update()
}
}
func main() {
pixelgl.Run(run)
}

View File

@ -1,10 +1,10 @@
module main
module foglar/serial_read
go 1.21.6
require github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
go 1.20
require (
github.com/mitchellh/go-homedir v1.1.0 // indirect
golang.org/x/sys v0.16.0 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
)
require golang.org/x/sys v0.17.0 // indirect

View File

@ -2,5 +2,5 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 h1:UyzmZLoiDWMRywV4DUYb9Fbt8uiOSooupjTq10vpvnU=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=