CobraV3 simplification and cleanup

This commit is contained in:
shinya 2025-06-20 16:26:32 +02:00
parent a9227420e8
commit f247a103d2
30 changed files with 0 additions and 2740 deletions

View File

@ -1,22 +0,0 @@
module foglar/monitor
go 1.21
toolchain go1.22.1
require (
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/gopxl/pixel v1.0.0
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
golang.org/x/image v0.13.0
)
require (
github.com/faiface/glhf v0.0.0-20211013000516-57b20770c369 // indirect
github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 // indirect
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
github.com/go-gl/mathgl v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/sys v0.17.0 // indirect
)

View File

@ -1,35 +0,0 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/faiface/glhf v0.0.0-20211013000516-57b20770c369 h1:gv4BgP50atccdK/1tZHDyP6rMwiiutR2HPreR/OyLzI=
github.com/faiface/glhf v0.0.0-20211013000516-57b20770c369/go.mod h1:dDdUO+G9ZnJ9sc8nIUvhLkE45k8PEKW6+A3TdWsfpV0=
github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 h1:baVdMKlASEHrj19iqjARrPbaRisD7EuZEVJj6ZMLl1Q=
github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3/go.mod h1:VEPNJUlxl5KdWjDvz6Q1l+rJlxF2i6xqDeGuGAxa87M=
github.com/go-gl/gl v0.0.0-20210905235341-f7a045908259/go.mod h1:wjpnOv6ONl2SuJSxqCPVaPZibGFdSci9HFocT9qtVYM=
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 h1:zDw5v7qm4yH7N8C8uWd+8Ii9rROdgWxQuGoJ9WDXxfk=
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw=
github.com/go-gl/glfw v0.0.0-20210727001814-0db043d8d5be/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b h1:GgabKamyOYguHqHjSkDACcgoPIz3w0Dis/zJ1wyHHHU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/mathgl v1.0.0/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ=
github.com/go-gl/mathgl v1.1.0 h1:0lzZ+rntPX3/oGrDzYGdowSLC2ky8Osirvf5uAwfIEA=
github.com/go-gl/mathgl v1.1.0/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/gopxl/pixel v1.0.0 h1:ZON6ll6/tI6sO8fwrlj93GVUcXReTST5//iKv6lcd8g=
github.com/gopxl/pixel v1.0.0/go.mod h1:kPUBG2He7/+alwmi5z0IwnpAc6pw2N7eA08cdBfoE/Q=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
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/image v0.0.0-20190321063152-3fc05d484e9f/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.13.0 h1:3cge/F/QTkNLauhf2QoE9zp+7sr+ZcL4HnoZmdwg9sg=
golang.org/x/image v0.13.0/go.mod h1:6mmbMOeV28HuMTgA6OSRkdXKYw/t5W9Uwn2Yv1r3Yxk=
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=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -1,41 +0,0 @@
package gui
import (
"io"
"os"
"github.com/golang/freetype/truetype"
"github.com/gopxl/pixel/text"
"golang.org/x/image/font"
)
func LoadFont(FONT string, SIZE float64) (*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
}
defer file.Close()
bytes, err := io.ReadAll(file)
if err != nil {
return nil, err
}
font, err := truetype.Parse(bytes)
if err != nil {
return nil, err
}
return truetype.NewFace(font, &truetype.Options{
Size: size,
GlyphCacheEntries: 1,
}), nil
}

View File

@ -1,138 +0,0 @@
package main
import (
//"strconv"
"foglar/monitor/gui"
"foglar/monitor/parse"
"foglar/monitor/serial_read"
"github.com/gopxl/pixel"
"github.com/gopxl/pixel/pixelgl"
"github.com/gopxl/pixel/text"
"golang.org/x/image/colornames"
)
const (
LOG_FONT = "gui/JetBrainsMonoNerdFont-Medium.ttf"
INFO_FONT = "gui/JetBrainsMonoNerdFont-Medium.ttf"
LOG_SIZE = 12
INFO_SIZE = 24
)
var (
LOG_POSITION = [2]float64{900, 10}
TEMP_POSITION = [2]float64{600, 100}
PRESSURE_POSITION = [2]float64{200, 100}
ATTITUDE_POSITION = [2]float64{50, 400}
ROLL_POSITION = [2]float64{50, 650}
PITCH_POSITION = [2]float64{350, 650}
YAW_POSITION = [2]float64{650, 650}
)
func run() {
// Initialize serial connection
serialHandler, err := serial_read.NewSerialHandler()
if err != nil {
panic(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 fonts
log_atlas, err := gui.LoadFont(LOG_FONT, LOG_SIZE)
if err != nil {
panic(err)
}
info_atlas, err := gui.LoadFont(INFO_FONT, INFO_SIZE)
if err != nil {
panic(err)
}
// Text
logging_serial := text.New(pixel.V(LOG_POSITION[0], LOG_POSITION[1]), log_atlas)
temperature := text.New(pixel.V(TEMP_POSITION[0], TEMP_POSITION[1]), info_atlas)
pressure := text.New(pixel.V(PRESSURE_POSITION[0], PRESSURE_POSITION[1]), info_atlas)
attitude := text.New(pixel.V(ATTITUDE_POSITION[0], ATTITUDE_POSITION[1]), info_atlas)
roll := text.New(pixel.V(ROLL_POSITION[0], ROLL_POSITION[1]), info_atlas)
pitch := text.New(pixel.V(PITCH_POSITION[0], PITCH_POSITION[1]), info_atlas)
yaw := text.New(pixel.V(YAW_POSITION[0], YAW_POSITION[1]), info_atlas)
var (
temperature_gui string
pressure_gui string
attitude_gui string
roll_gui string
pitch_gui string
yaw_gui string
)
// Window update
for !win.Closed() {
// Read Serial Port
data, err := serialHandler.ReadSerial()
defer serialHandler.Close()
if err != nil {
panic(err)
}
// Parsing data
info := parse.Parser(data)
// Clear screen values
temperature.Clear()
pressure.Clear()
attitude.Clear()
roll.Clear()
pitch.Clear()
yaw.Clear()
// Update information if it is in the parsed block
if _, ok := info[1]; ok {
temperature_gui = info[4]
pressure_gui = info[5]
attitude_gui = info[6]
roll_gui = info[1]
pitch_gui = info[2]
yaw_gui = info[3]
}
win.Clear(colornames.Black)
// Print information to text blocks
logging_serial.WriteString(data)
temperature.WriteString("Temperature: " + temperature_gui)
pressure.WriteString("Pressure: [hPa] " + pressure_gui)
attitude.WriteString("Attitude: [m] " + attitude_gui)
roll.WriteString("Roll: [°]" + roll_gui)
pitch.WriteString("Pitch: [°]" + pitch_gui)
yaw.WriteString("Yaw: [°]" + yaw_gui)
// Draw information to screen
logging_serial.Draw(win, pixel.IM)
temperature.Draw(win, pixel.IM)
pressure.Draw(win, pixel.IM)
attitude.Draw(win, pixel.IM)
roll.Draw(win, pixel.IM)
pitch.Draw(win, pixel.IM)
yaw.Draw(win, pixel.IM)
win.Update()
}
}
func main() {
pixelgl.Run(run)
}

View File

@ -1,34 +0,0 @@
package parse
// TODO: finish reading serial input and parsing it and piping it to the gui component
import (
"log"
"strconv"
"strings"
)
func Parser(s string) map[int]string {
// TODO: check if line isn't comment
// improve reading data
lines := strings.Split(s, "\n")
data_structure := make(map[int]string)
for _, line := range lines {
// find $ and * in text and get value between them
startIndex := strings.Index(line, "$")
endIndex := strings.Index(line, "*")
if startIndex != -1 && endIndex != -1 {
value := line[startIndex+1 : endIndex]
data := strings.Split(strings.TrimSpace(value), ";")
ident, err := strconv.Atoi(strings.TrimSpace(data[0]))
if err != nil {
log.Print(err)
}
info := data[1]
data_structure[ident] = info
}
}
return data_structure
}

View File

@ -1,109 +0,0 @@
package serial_read
import (
"fmt"
"log"
"os"
"strconv"
"github.com/tarm/serial"
)
// TODO:
// - Validation of port and baudrate
// - And input of port and baudrate
// SerialHandler struct
type SerialHandler struct {
port *serial.Port
}
// Initialize new SerialHandler
func NewSerialHandler() (*SerialHandler, error) {
port := inputPort()
baudrate, err := inputBaudrate()
if err != nil {
fmt.Println("Error - Baudrate is not valid number")
}
s, err := serial.OpenPort(&serial.Config{Name: port, Baud: baudrate})
if err != nil {
log.Fatal(err)
return nil, err
}
return &SerialHandler{port: s}, nil
}
// Reads from the serial port and returns the received data as a string
func (sh *SerialHandler) ReadSerial() (string, error) {
buf := make([]byte, 128)
n, err := sh.port.Read(buf)
if err != nil {
log.Fatal(err)
return "", err
}
return string(buf[:n]), nil
}
// Close closes the serial port
func (sh *SerialHandler) Close() error {
return sh.port.Close()
}
func inputPort() string {
var s_port string
for {
fmt.Print("Enter port (/dev/ttyACM0): ")
fmt.Scanln(&s_port)
if isPort(s_port) == true {
break
}
fmt.Println("Error - Invalid Port")
}
return s_port
}
func inputBaudrate() (int, error) {
var s_baud string
for {
fmt.Print("Enter baudrate (for example 9600): ")
fmt.Scanln(&s_baud)
if isBaud(s_baud) == true {
break
}
fmt.Println("Error - Invalid Baudrate")
}
return strconv.Atoi(s_baud)
}
func isPort(port string) bool {
_, err := os.Stat(port)
if !os.IsNotExist(err) {
return true
}
return false
}
func isBaud(baud string) bool {
switch baud {
case "4800":
return true
case "9600":
return true
case "115200":
return true
default:
return false
}
}

View File

@ -1,95 +0,0 @@
/*****************************************************************************
* | File : DEV_Config.c
* | Author : Waveshare team
* | Function : Hardware underlying interface
* | Info :
* Used to shield the underlying layers of each master
* and enhance portability
*----------------
* | This version: V1.0
* | Date : 2018-11-22
* | Info :
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#include "DEV_Config.h"
#include <SofwareSerial>
SoftwareSerial mySerial(0, 1); // RX, TX
/******************************************************************************
function:
Uart receiving and sending
******************************************************************************/
UBYTE DEV_Uart_ReceiveByte()
{
while(1){
if(mySerial.available()){
return mySerial.read();
}
}
}
void DEV_Uart_SendByte(char data)
{
mySerial.write(data);
}
void DEV_Uart_SendString(char *data)
{
UWORD i;
for(i=0; data[i] != '\0'; i++){
mySerial.write(data[i]);
}
}
void DEV_Uart_ReceiveString(char *data, UWORD Num)
{
UWORD i;
while(1){
if(mySerial.available()){
data[i] = mySerial.read();
i++;
//Serial.print(data[i]);
if(i >= Num){
break;
}
}
}
data[Num-1] = '\0';
}
void DEV_Set_GPIOMode(UWORD Pin, UWORD mode)
{
if(mode == 1){
pinMode(Pin, INPUT);
}
else if(mode == 0){
pinMode(Pin, OUTPUT);
}
}
void DEV_Set_Baudrate(UDOUBLE Baudrate)
{
mySerial.begin(Baudrate);
}

View File

@ -1,41 +0,0 @@
#ifndef _DEV_CONFIG_H_
#define _DEV_CONFIG_H_
#include <avr/pgmspace.h>
#include <stdint.h>
#include <stdio.h>
#include <SPI.h>
#define UBYTE uint8_t
#define UWORD uint16_t
#define UDOUBLE uint32_t
/**
* GPIO config
**/
#define DEV_FORCE 4
#define DEV_STANDBY 5
/**
* GPIO read and write
**/
#define DEV_Digital_Write(_pin, _value) digitalWrite(_pin, _value == 0? LOW:HIGH)
#define DEV_Digital_Read(_pin) digitalRead(_pin)
/**
* delay x ms
**/
#define DEV_Delay_ms(__xms) delay(__xms)
/*-----------------------------------------------------------------------------*/
UBYTE DEV_Uart_ReceiveByte(void);
void DEV_Uart_SendByte(char data);
void DEV_Uart_SendString(char *data);
void DEV_Uart_ReceiveString(char *data, UWORD Num);
void DEV_Set_Baudrate(UDOUBLE Baudrate);
void DEV_Set_GPIOMode(UWORD Pin, UWORD mode);
#endif

View File

@ -1,244 +0,0 @@
#include "L76X.h"
char const Temp[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
static const double pi = 3.14159265358979324;
static const double a = 6378245.0;
static const double ee = 0.00669342162296594323;
static const double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
static char buff_t[BUFFSIZE]={0};
GNRMC GPS;
/******************************************************************************
function:
Latitude conversion
******************************************************************************/
static double transformLat(double x,double y)
{
double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 *sqrt(abs(x));
ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0;
ret += (20.0 * sin(y * pi) + 40.0 * sin(y / 3.0 * pi)) * 2.0 / 3.0;
ret += (160.0 * sin(y / 12.0 * pi) + 320 * sin(y * pi / 30.0)) * 2.0 / 3.0;
return ret;
}
/******************************************************************************
function:
Longitude conversion
******************************************************************************/
static double transformLon(double x,double y)
{
double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(abs(x));
ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0;
ret += (20.0 * sin(x * pi) + 40.0 * sin(x / 3.0 * pi)) * 2.0 / 3.0;
ret += (150.0 * sin(x / 12.0 * pi) + 300.0 * sin(x / 30.0 * pi)) * 2.0 / 3.0;
return ret;
}
/******************************************************************************
function:
GCJ-02 international standard converted to Baidu map BD-09 standard
******************************************************************************/
static Coordinates bd_encrypt(Coordinates gg)
{
Coordinates bd;
double x = gg.Lon, y = gg.Lat;
double z = sqrt(x * x + y * y) + 0.00002 * sin(y * x_pi);
double theta = atan2(y, x) + 0.000003 * cos(x * x_pi);
bd.Lon = z * cos(theta) + 0.0065;
bd.Lat = z * sin(theta) + 0.006;
return bd;
}
/******************************************************************************
function:
GPS's WGS-84 standard is converted into GCJ-02 international standard
******************************************************************************/
static Coordinates transform(Coordinates gps)
{
Coordinates gg;
double dLat = transformLat(gps.Lon - 105.0, gps.Lat - 35.0);
double dLon = transformLon(gps.Lon - 105.0, gps.Lat - 35.0);
double radLat = gps.Lat / 180.0 * pi;
double magic = sin(radLat);
magic = 1 - ee * magic * magic;
double sqrtMagic = sqrt(magic);
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
dLon = (dLon * 180.0) / (a / sqrtMagic * cos(radLat) * pi);
gg.Lat = gps.Lat + dLat;
gg.Lon = gps.Lon + dLon;
return gg;
}
/******************************************************************************
function:
Send a command to the L76XAutomatic calculation of the code
parameter:
data The end of the command ends with \0 or it will go wrong,
no need to increase the validation code.
******************************************************************************/
void L76X_Send_Command(char *data)
{
char Check = data[1], Check_char[3]={0};
UBYTE i = 0;
DEV_Uart_SendByte('\r');
DEV_Uart_SendByte('\n');
//printf(" 1i = %d Check =%x \n", i, Check);
for(i=2; data[i] != '\0'; i++){
Check ^= data[i]; //Calculate the check value
}
//printf(" i = %d Check =%x \n", i, Check);
Check_char[0] = Temp[Check/16%16];
Check_char[1] = Temp[Check%16];
Check_char[2] = '\0';
DEV_Uart_SendString(data);
DEV_Uart_SendByte('*');
DEV_Uart_SendString(Check_char);
DEV_Uart_SendByte('\r');
DEV_Uart_SendByte('\n');
}
void L76X_Exit_BackupMode()
{
DEV_Set_GPIOMode(DEV_FORCE, 0);
DEV_Digital_Write(DEV_FORCE, 1);
DEV_Delay_ms(1000);
DEV_Digital_Write(DEV_FORCE, 0);
DEV_Set_GPIOMode(DEV_FORCE, 1);
}
/******************************************************************************
function:
Analyze GNRMC data in L76x, latitude and longitude, time
******************************************************************************/
GNRMC L76X_Gat_GNRMC()
{
UWORD add = 0, x = 0, z = 0, i = 0;
UDOUBLE Time = 0, latitude = 0, longitude = 0;
GPS.Status = 0;
GPS.Time_H = 0;
GPS.Time_M = 0;
GPS.Time_S = 0;
DEV_Uart_ReceiveString(buff_t, BUFFSIZE);
Serial.print(buff_t);
add = 0;
while(add < BUFFSIZE){
if(buff_t[add] == '$' && buff_t[add+1] == 'G' && (buff_t[add+2] == 'N' || buff_t[add+2] == 'P')\
&& buff_t[add+3] == 'R' && buff_t[add+4] == 'M' && buff_t[add+5] == 'C'){
x = 0;
for(z = 0; x < 12; z++){
if(buff_t[add+z]=='\0'){
break;
}
if(buff_t[add+z]==','){
x++;
if(x == 1){//The first comma is followed by time
Time = 0;
for(i = 0; buff_t[add+z+i+1] != '.'; i++){
if(buff_t[add+z+i+1]=='\0'){
break;
}
if(buff_t[add+z+i+1] == ',')
break;
Time = (buff_t[add+z+i+1]-'0') + Time*10;
}
GPS.Time_H = Time/10000+8;
GPS.Time_M = Time/100%100;
GPS.Time_S = Time%100;
if(GPS.Time_H >= 24)
GPS.Time_H = GPS.Time_H - 24;
}else if(x == 2){
//A indicates that it has been positioned
//V indicates that there is no positioning.
if(buff_t[add+z+1] == 'A'){
GPS.Status = 1;
}else{
GPS.Status = 0;
}
}else if(x == 3){
latitude = 0;
//If you need to modify, please re-edit the calculation method below.
for(i = 0; buff_t[add+z+i+1] != ','; i++){
if(buff_t[add+z+i+1] == '\0'){
break;
}
if(buff_t[add+z+i+1] == '.'){
continue;
}
latitude = (buff_t[add+z+i+1]-'0') + latitude*10;
}
GPS.Lat = latitude/10000000.0;
}else if(x == 4){
GPS.Lat_area = buff_t[add+z+1];
}
else if(x == 5){
longitude = 0;
for(i = 0; buff_t[add+z+i+1] != ','; i++){
if(buff_t[add+z+i+1] == '\0'){
break;
}
if(buff_t[add+z+i+1] == '.')
continue;
longitude = (buff_t[add+z+i+1]-'0') + longitude*10;
}
GPS.Lon = longitude/10000000.0;
}else if(x == 6){
GPS.Lon_area = buff_t[add+z+1];
}
}
}
add = 0;
break;
}
if(buff_t[add+5] == '\0'){
add = 0;
break;
}
add++;
if(add > BUFFSIZE){
add = 0;
break;
}
}
return GPS;
}
/******************************************************************************
function:
Convert GPS latitude and longitude into Baidu map coordinates
******************************************************************************/
Coordinates L76X_Baidu_Coordinates()
{
Coordinates temp;
temp.Lat =((int)(GPS.Lat)) + (GPS.Lat - ((int)(GPS.Lat)))*100 / 60;
temp.Lon =((int)(GPS.Lon)) + (GPS.Lon - ((int)(GPS.Lon)))*100 / 60;
temp = transform(temp);
temp = bd_encrypt(temp);
return temp;
}
/******************************************************************************
function:
Convert GPS latitude and longitude into Google Maps coordinates
******************************************************************************/
Coordinates L76X_Google_Coordinates()
{
Coordinates temp;
GPS.Lat =((int)(GPS.Lat)) + (GPS.Lat - ((int)(GPS.Lat)))*100 / 60;
GPS.Lon =((int)(GPS.Lon)) + (GPS.Lon - ((int)(GPS.Lon)))*100 / 60;
temp = transform(temp);
return temp;
}

View File

@ -1,83 +0,0 @@
#ifndef _L76X_H_
#define _L76X_H_
#include "DEV_Config.h"
#include <math.h>
#include <stdlib.h>
#define BUFFSIZE 800
//Startup mode
#define HOT_START "$PMTK101"
#define WARM_START "$PMTK102"
#define COLD_START "$PMTK103"
#define FULL_COLD_START "$PMTK104"
//Standby mode -- Exit requires high level trigger
#define SET_PERPETUAL_STANDBY_MODE "$PMTK161"
#define SET_PERIODIC_MODE "$PMTK225"
#define SET_NORMAL_MODE "$PMTK225,0"
#define SET_PERIODIC_BACKUP_MODE "$PMTK225,1,1000,2000"
#define SET_PERIODIC_STANDBY_MODE "$PMTK225,2,1000,2000"
#define SET_PERPETUAL_BACKUP_MODE "$PMTK225,4"
#define SET_ALWAYSLOCATE_STANDBY_MODE "$PMTK225,8"
#define SET_ALWAYSLOCATE_BACKUP_MODE "$PMTK225,9"
//Set the message interval,100ms~10000ms
#define SET_POS_FIX "$PMTK220"
#define SET_POS_FIX_100MS "$PMTK220,100"
#define SET_POS_FIX_200MS "$PMTK220,200"
#define SET_POS_FIX_400MS "$PMTK220,400"
#define SET_POS_FIX_800MS "$PMTK220,800"
#define SET_POS_FIX_1S "$PMTK220,1000"
#define SET_POS_FIX_2S "$PMTK220,2000"
#define SET_POS_FIX_4S "$PMTK220,4000"
#define SET_POS_FIX_8S "$PMTK220,8000"
#define SET_POS_FIX_10S "$PMTK220,10000"
//Switching time output
#define SET_SYNC_PPS_NMEA_OFF "$PMTK255,0"
#define SET_SYNC_PPS_NMEA_ON "$PMTK255,1"
//Baud rate
#define SET_NMEA_BAUDRATE "$PMTK251"
#define SET_NMEA_BAUDRATE_115200 "$PMTK251,115200"
#define SET_NMEA_BAUDRATE_57600 "$PMTK251,57600"
#define SET_NMEA_BAUDRATE_38400 "$PMTK251,38400"
#define SET_NMEA_BAUDRATE_19200 "$PMTK251,19200"
#define SET_NMEA_BAUDRATE_14400 "$PMTK251,14400"
#define SET_NMEA_BAUDRATE_9600 "$PMTK251,9600"
#define SET_NMEA_BAUDRATE_4800 "$PMTK251,4800"
//To restore the system default setting
#define SET_REDUCTION "$PMTK314,-1"
//Set NMEA sentence output frequencies
#define SET_NMEA_OUTPUT "$PMTK314,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
typedef struct {
double Lon; //GPS Latitude and longitude
double Lat;
char Lon_area;
char Lat_area;
UBYTE Time_H; //Time
UBYTE Time_M;
UBYTE Time_S;
UBYTE Status; //1:Successful positioning 0Positioning failed
}GNRMC;
typedef struct {
double Lon;
double Lat;
}Coordinates;
void L76X_Send_Command(char *data);
Coordinates L76X_Baidu_Coordinates(void);
Coordinates L76X_Google_Coordinates(void);
GNRMC L76X_Gat_GNRMC(void);
void L76X_Exit_BackupMode(void);
#endif

View File

@ -1,32 +0,0 @@
# Sender module
## Stages of flight
1. Preflight - Remove before flight button or smthing like that
- no communication, blocked parachute ejection, all systems down
2. Ready - Signal from groundstation
- sys check (modules calibration, battery check, atd...), blocked parachute ejection, wait for launch pin removed, only send data, do not save them
3. Launch - Removed pin from the rocket
- launch, all systems sending and saving data on sd card
4. Apogee - Detected that rocket is in apogee with accelerometer
- parachute ejection, all systems working, gps check and height check
5. Return - Rocket has no velocity
- all not needed systems shutdown/sleep, buzz on, gps sending location, battery check, turn off gyro and accelerometer
## Modules
- nRF24L01 - Communication with groundstation
- L76K GPS - GPS sensor for gps data
- 10 DOF IMU - Gyroscope/Accelerometer, Temperature, atd.
- ?INA-219 - Battery data
- ?SD card reader - Write all recieved data to the SD card
- ?Buzzer - To find our rocket after launch
## Tasks
- Ejection mechanism
- PCB for our computer
- force parachute ejection
- if cable connected return back to ready stage
- send signal of listening
- wait for recieve

View File

@ -1,743 +0,0 @@
/**
******************************************************************************
* @file Waveshare_10Dof-D.cpp
* @author Waveshare Team
* @version V1.0
* @date Dec-2018
* @brief T
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, WAVESHARE SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2018 Waveshare</center></h2>
******************************************************************************
*/
#include "Waveshare_10Dof-D.h"
#include <Wire.h>
IMU_ST_SENSOR_DATA gstGyroOffset ={0,0,0};
#ifdef __cplusplus
extern "C" {
#endif
void imuAHRSupdate(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz);
float invSqrt(float x);
void icm20948init(void);
bool icm20948Check(void);
void icm20948GyroRead(int16_t* ps16X, int16_t* ps16Y, int16_t* ps16Z);
void icm20948AccelRead(int16_t* ps16X, int16_t* ps16Y, int16_t* ps16Z);
void icm20948MagRead(int16_t* ps16X, int16_t* ps16Y, int16_t* ps16Z);
bool icm20948MagCheck(void);
void icm20948CalAvgValue(uint8_t *pIndex, int16_t *pAvgBuffer, int16_t InVal, int32_t *pOutVal);
void icm20948GyroOffset(void);
void icm20948ReadSecondary(uint8_t u8I2CAddr, uint8_t u8RegAddr, uint8_t u8Len, uint8_t *pu8data);
void icm20948WriteSecondary(uint8_t u8I2CAddr, uint8_t u8RegAddr, uint8_t u8data);
bool icm20948Check(void);
bool bmp280Check(void);
void bmp280Init(void);
/******************************************************************************
* interface driver *
******************************************************************************/
uint8_t I2C_ReadOneByte(uint8_t DevAddr, uint8_t RegAddr)
{
uint8_t value;
Wire.beginTransmission(DevAddr);
Wire.write((byte)RegAddr);
Wire.endTransmission();
Wire.requestFrom(DevAddr, (byte)1);
value = Wire.read();
return value;
}
void I2C_WriteOneByte(uint8_t DevAddr, uint8_t RegAddr, uint8_t value)
{
Wire.beginTransmission(DevAddr);
Wire.write(RegAddr);
Wire.write(value);
Wire.endTransmission();
}
/******************************************************************************
* IMU module *
******************************************************************************/
#define Kp 4.50f // proportional gain governs rate of convergence to accelerometer/magnetometer
#define Ki 1.0f // integral gain governs rate of convergence of gyroscope biases
float angles[3];
float q0, q1, q2, q3;
void imuInit(IMU_EN_SENSOR_TYPE *penMotionSensorType, IMU_EN_SENSOR_TYPE *penPressureType)
{
bool bRet = false;
Wire.begin();
bRet = icm20948Check();
if( true == bRet)
{
*penMotionSensorType = IMU_EN_SENSOR_TYPE_ICM20948;
icm20948init();
}
else
{
*penMotionSensorType = IMU_EN_SENSOR_TYPE_NULL;
}
bRet = bmp280Check();
if( true == bRet)
{
*penPressureType = IMU_EN_SENSOR_TYPE_BMP280;
bmp280Init();
}
else
{
*penPressureType = IMU_EN_SENSOR_TYPE_NULL;
}
q0 = 1.0f;
q1 = 0.0f;
q2 = 0.0f;
q3 = 0.0f;
return;
}
void imuDataGet(IMU_ST_ANGLES_DATA *pstAngles,
IMU_ST_SENSOR_DATA *pstGyroRawData,
IMU_ST_SENSOR_DATA *pstAccelRawData,
IMU_ST_SENSOR_DATA *pstMagnRawData)
{
float MotionVal[9];
int16_t s16Gyro[3], s16Accel[3], s16Magn[3];
icm20948AccelRead(&s16Accel[0], &s16Accel[1], &s16Accel[2]);
icm20948GyroRead(&s16Gyro[0], &s16Gyro[1], &s16Gyro[2]);
icm20948MagRead(&s16Magn[0], &s16Magn[1], &s16Magn[2]);
MotionVal[0]=s16Gyro[0]/32.8;
MotionVal[1]=s16Gyro[1]/32.8;
MotionVal[2]=s16Gyro[2]/32.8;
MotionVal[3]=s16Accel[0];
MotionVal[4]=s16Accel[1];
MotionVal[5]=s16Accel[2];
MotionVal[6]=s16Magn[0];
MotionVal[7]=s16Magn[1];
MotionVal[8]=s16Magn[2];
imuAHRSupdate((float)MotionVal[0] * 0.0175, (float)MotionVal[1] * 0.0175, (float)MotionVal[2] * 0.0175,
(float)MotionVal[3], (float)MotionVal[4], (float)MotionVal[5],
(float)MotionVal[6], (float)MotionVal[7], MotionVal[8]);
pstAngles->fPitch = asin(-2 * q1 * q3 + 2 * q0* q2)* 57.3; // pitch
pstAngles->fRoll = atan2(2 * q2 * q3 + 2 * q0 * q1, -2 * q1 * q1 - 2 * q2* q2 + 1)* 57.3; // roll
pstAngles->fYaw = atan2(-2 * q1 * q2 - 2 * q0 * q3, 2 * q2 * q2 + 2 * q3 * q3 - 1) * 57.3;
pstGyroRawData->s16X = s16Gyro[0];
pstGyroRawData->s16Y = s16Gyro[1];
pstGyroRawData->s16Z = s16Gyro[2];
pstAccelRawData->s16X = s16Accel[0];
pstAccelRawData->s16Y = s16Accel[1];
pstAccelRawData->s16Z = s16Accel[2];
pstMagnRawData->s16X = s16Magn[0];
pstMagnRawData->s16Y = s16Magn[1];
pstMagnRawData->s16Z = s16Magn[2];
return;
}
void imuAHRSupdate(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz)
{
float norm;
float hx, hy, hz, bx, bz;
float vx, vy, vz, wx, wy, wz;
float exInt = 0.0, eyInt = 0.0, ezInt = 0.0;
float ex, ey, ez, halfT = 0.024f;
float q0q0 = q0 * q0;
float q0q1 = q0 * q1;
float q0q2 = q0 * q2;
float q0q3 = q0 * q3;
float q1q1 = q1 * q1;
float q1q2 = q1 * q2;
float q1q3 = q1 * q3;
float q2q2 = q2 * q2;
float q2q3 = q2 * q3;
float q3q3 = q3 * q3;
norm = invSqrt(ax * ax + ay * ay + az * az);
ax = ax * norm;
ay = ay * norm;
az = az * norm;
norm = invSqrt(mx * mx + my * my + mz * mz);
mx = mx * norm;
my = my * norm;
mz = mz * norm;
// compute reference direction of flux
hx = 2 * mx * (0.5f - q2q2 - q3q3) + 2 * my * (q1q2 - q0q3) + 2 * mz * (q1q3 + q0q2);
hy = 2 * mx * (q1q2 + q0q3) + 2 * my * (0.5f - q1q1 - q3q3) + 2 * mz * (q2q3 - q0q1);
hz = 2 * mx * (q1q3 - q0q2) + 2 * my * (q2q3 + q0q1) + 2 * mz * (0.5f - q1q1 - q2q2);
bx = sqrt((hx * hx) + (hy * hy));
bz = hz;
// estimated direction of gravity and flux (v and w)
vx = 2 * (q1q3 - q0q2);
vy = 2 * (q0q1 + q2q3);
vz = q0q0 - q1q1 - q2q2 + q3q3;
wx = 2 * bx * (0.5 - q2q2 - q3q3) + 2 * bz * (q1q3 - q0q2);
wy = 2 * bx * (q1q2 - q0q3) + 2 * bz * (q0q1 + q2q3);
wz = 2 * bx * (q0q2 + q1q3) + 2 * bz * (0.5 - q1q1 - q2q2);
// error is sum of cross product between reference direction of fields and direction measured by sensors
ex = (ay * vz - az * vy) + (my * wz - mz * wy);
ey = (az * vx - ax * vz) + (mz * wx - mx * wz);
ez = (ax * vy - ay * vx) + (mx * wy - my * wx);
if(ex != 0.0f && ey != 0.0f && ez != 0.0f)
{
exInt = exInt + ex * Ki * halfT;
eyInt = eyInt + ey * Ki * halfT;
ezInt = ezInt + ez * Ki * halfT;
gx = gx + Kp * ex + exInt;
gy = gy + Kp * ey + eyInt;
gz = gz + Kp * ez + ezInt;
}
q0 = q0 + (-q1 * gx - q2 * gy - q3 * gz) * halfT;
q1 = q1 + (q0 * gx + q2 * gz - q3 * gy) * halfT;
q2 = q2 + (q0 * gy - q1 * gz + q3 * gx) * halfT;
q3 = q3 + (q0 * gz + q1 * gy - q2 * gx) * halfT;
norm = invSqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3);
q0 = q0 * norm;
q1 = q1 * norm;
q2 = q2 * norm;
q3 = q3 * norm;
}
float invSqrt(float x)
{
float halfx = 0.5f * x;
float y = x;
long i = *(long*)&y; //get bits for floating value
i = 0x5f3759df - (i >> 1); //gives initial guss you
y = *(float*)&i; //convert bits back to float
y = y * (1.5f - (halfx * y * y)); //newtop step, repeating increases accuracy
return y;
}
/******************************************************************************
* icm20948 sensor device *
******************************************************************************/
void icm20948init(void)
{
/* user bank 0 register */
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_REG_BANK_SEL, REG_VAL_REG_BANK_0);
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_PWR_MIGMT_1, REG_VAL_ALL_RGE_RESET);
delay(10);
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_PWR_MIGMT_1, REG_VAL_RUN_MODE);
/* user bank 2 register */
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_REG_BANK_SEL, REG_VAL_REG_BANK_2);
I2C_WriteOneByte( I2C_ADD_ICM20948, REG_ADD_GYRO_SMPLRT_DIV, 0x07);
I2C_WriteOneByte( I2C_ADD_ICM20948, REG_ADD_GYRO_CONFIG_1,
REG_VAL_BIT_GYRO_DLPCFG_6 | REG_VAL_BIT_GYRO_FS_1000DPS | REG_VAL_BIT_GYRO_DLPF);
I2C_WriteOneByte( I2C_ADD_ICM20948, REG_ADD_ACCEL_SMPLRT_DIV_2, 0x07);
I2C_WriteOneByte( I2C_ADD_ICM20948, REG_ADD_ACCEL_CONFIG,
REG_VAL_BIT_ACCEL_DLPCFG_6 | REG_VAL_BIT_ACCEL_FS_2g | REG_VAL_BIT_ACCEL_DLPF);
/* user bank 0 register */
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_REG_BANK_SEL, REG_VAL_REG_BANK_0);
delay(100);
/* offset */
icm20948GyroOffset();
icm20948MagCheck();
icm20948WriteSecondary( I2C_ADD_ICM20948_AK09916|I2C_ADD_ICM20948_AK09916_WRITE,
REG_ADD_MAG_CNTL2, REG_VAL_MAG_MODE_20HZ);
return;
}
bool icm20948Check(void)
{
bool bRet = false;
if(REG_VAL_WIA == I2C_ReadOneByte(I2C_ADD_ICM20948, REG_ADD_WIA))
{
bRet = true;
}
return bRet;
}
void icm20948GyroRead(int16_t* ps16X, int16_t* ps16Y, int16_t* ps16Z)
{
uint8_t u8Buf[6];
int16_t s16Buf[3] = {0};
uint8_t i;
int32_t s32OutBuf[3] = {0};
static ICM20948_ST_AVG_DATA sstAvgBuf[3];
static int16_t ss16c = 0;
ss16c++;
u8Buf[0]=I2C_ReadOneByte(I2C_ADD_ICM20948,REG_ADD_GYRO_XOUT_L);
u8Buf[1]=I2C_ReadOneByte(I2C_ADD_ICM20948,REG_ADD_GYRO_XOUT_H);
s16Buf[0]= (u8Buf[1]<<8)|u8Buf[0];
u8Buf[0]=I2C_ReadOneByte(I2C_ADD_ICM20948,REG_ADD_GYRO_YOUT_L);
u8Buf[1]=I2C_ReadOneByte(I2C_ADD_ICM20948,REG_ADD_GYRO_YOUT_H);
s16Buf[1]= (u8Buf[1]<<8)|u8Buf[0];
u8Buf[0]=I2C_ReadOneByte(I2C_ADD_ICM20948,REG_ADD_GYRO_ZOUT_L);
u8Buf[1]=I2C_ReadOneByte(I2C_ADD_ICM20948,REG_ADD_GYRO_ZOUT_H);
s16Buf[2]= (u8Buf[1]<<8)|u8Buf[0];
for(i = 0; i < 3; i ++)
{
icm20948CalAvgValue(&sstAvgBuf[i].u8Index, sstAvgBuf[i].s16AvgBuffer, s16Buf[i], s32OutBuf + i);
}
*ps16X = s32OutBuf[0] - gstGyroOffset.s16X;
*ps16Y = s32OutBuf[1] - gstGyroOffset.s16Y;
*ps16Z = s32OutBuf[2] - gstGyroOffset.s16Z;
return;
}
void icm20948AccelRead(int16_t* ps16X, int16_t* ps16Y, int16_t* ps16Z)
{
uint8_t u8Buf[2];
int16_t s16Buf[3] = {0};
uint8_t i;
int32_t s32OutBuf[3] = {0};
static ICM20948_ST_AVG_DATA sstAvgBuf[3];
u8Buf[0]=I2C_ReadOneByte(I2C_ADD_ICM20948,REG_ADD_ACCEL_XOUT_L);
u8Buf[1]=I2C_ReadOneByte(I2C_ADD_ICM20948,REG_ADD_ACCEL_XOUT_H);
s16Buf[0]= (u8Buf[1]<<8)|u8Buf[0];
u8Buf[0]=I2C_ReadOneByte(I2C_ADD_ICM20948,REG_ADD_ACCEL_YOUT_L);
u8Buf[1]=I2C_ReadOneByte(I2C_ADD_ICM20948,REG_ADD_ACCEL_YOUT_H);
s16Buf[1]= (u8Buf[1]<<8)|u8Buf[0];
u8Buf[0]=I2C_ReadOneByte(I2C_ADD_ICM20948,REG_ADD_ACCEL_ZOUT_L);
u8Buf[1]=I2C_ReadOneByte(I2C_ADD_ICM20948,REG_ADD_ACCEL_ZOUT_H);
s16Buf[2]= (u8Buf[1]<<8)|u8Buf[0];
for(i = 0; i < 3; i ++)
{
icm20948CalAvgValue(&sstAvgBuf[i].u8Index, sstAvgBuf[i].s16AvgBuffer, s16Buf[i], s32OutBuf + i);
}
*ps16X = s32OutBuf[0];
*ps16Y = s32OutBuf[1];
*ps16Z = s32OutBuf[2];
return;
}
void icm20948MagRead(int16_t* ps16X, int16_t* ps16Y, int16_t* ps16Z)
{
uint8_t counter = 20;
uint8_t u8Data[MAG_DATA_LEN];
int16_t s16Buf[3] = {0};
uint8_t i;
int32_t s32OutBuf[3] = {0};
static ICM20948_ST_AVG_DATA sstAvgBuf[3];
while( counter>0 )
{
delay(10);
icm20948ReadSecondary( I2C_ADD_ICM20948_AK09916|I2C_ADD_ICM20948_AK09916_READ,
REG_ADD_MAG_ST2, 1, u8Data);
if ((u8Data[0] & 0x01) != 0)
break;
counter--;
}
if(counter != 0)
{
icm20948ReadSecondary( I2C_ADD_ICM20948_AK09916|I2C_ADD_ICM20948_AK09916_READ,
REG_ADD_MAG_DATA,
MAG_DATA_LEN,
u8Data);
s16Buf[0] = ((int16_t)u8Data[1]<<8) | u8Data[0];
s16Buf[1] = ((int16_t)u8Data[3]<<8) | u8Data[2];
s16Buf[2] = ((int16_t)u8Data[5]<<8) | u8Data[4];
}
for(i = 0; i < 3; i ++)
{
icm20948CalAvgValue(&sstAvgBuf[i].u8Index, sstAvgBuf[i].s16AvgBuffer, s16Buf[i], s32OutBuf + i);
}
*ps16X = s32OutBuf[0];
*ps16Y = -s32OutBuf[1];
*ps16Z = -s32OutBuf[2];
return;
}
void icm20948ReadSecondary(uint8_t u8I2CAddr, uint8_t u8RegAddr, uint8_t u8Len, uint8_t *pu8data)
{
uint8_t i;
uint8_t u8Temp;
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_REG_BANK_SEL, REG_VAL_REG_BANK_3); //swtich bank3
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_I2C_SLV0_ADDR, u8I2CAddr);
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_I2C_SLV0_REG, u8RegAddr);
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_I2C_SLV0_CTRL, REG_VAL_BIT_SLV0_EN|u8Len);
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_REG_BANK_SEL, REG_VAL_REG_BANK_0); //swtich bank0
u8Temp = I2C_ReadOneByte(I2C_ADD_ICM20948,REG_ADD_USER_CTRL);
u8Temp |= REG_VAL_BIT_I2C_MST_EN;
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_USER_CTRL, u8Temp);
delay(5);
u8Temp &= ~REG_VAL_BIT_I2C_MST_EN;
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_USER_CTRL, u8Temp);
for(i=0; i<u8Len; i++)
{
*(pu8data+i) = I2C_ReadOneByte(I2C_ADD_ICM20948, REG_ADD_EXT_SENS_DATA_00+i);
}
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_REG_BANK_SEL, REG_VAL_REG_BANK_3); //swtich bank3
u8Temp = I2C_ReadOneByte(I2C_ADD_ICM20948,REG_ADD_I2C_SLV0_CTRL);
u8Temp &= ~((REG_VAL_BIT_I2C_MST_EN)&(REG_VAL_BIT_MASK_LEN));
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_I2C_SLV0_CTRL, u8Temp);
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_REG_BANK_SEL, REG_VAL_REG_BANK_0); //swtich bank0
}
void icm20948WriteSecondary(uint8_t u8I2CAddr, uint8_t u8RegAddr, uint8_t u8data)
{
uint8_t u8Temp;
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_REG_BANK_SEL, REG_VAL_REG_BANK_3); //swtich bank3
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_I2C_SLV1_ADDR, u8I2CAddr);
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_I2C_SLV1_REG, u8RegAddr);
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_I2C_SLV1_DO, u8data);
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_I2C_SLV1_CTRL, REG_VAL_BIT_SLV0_EN|1);
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_REG_BANK_SEL, REG_VAL_REG_BANK_0); //swtich bank0
u8Temp = I2C_ReadOneByte(I2C_ADD_ICM20948,REG_ADD_USER_CTRL);
u8Temp |= REG_VAL_BIT_I2C_MST_EN;
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_USER_CTRL, u8Temp);
delay(5);
u8Temp &= ~REG_VAL_BIT_I2C_MST_EN;
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_USER_CTRL, u8Temp);
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_REG_BANK_SEL, REG_VAL_REG_BANK_3); //swtich bank3
u8Temp = I2C_ReadOneByte(I2C_ADD_ICM20948,REG_ADD_I2C_SLV0_CTRL);
u8Temp &= ~((REG_VAL_BIT_I2C_MST_EN)&(REG_VAL_BIT_MASK_LEN));
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_I2C_SLV0_CTRL, u8Temp);
I2C_WriteOneByte(I2C_ADD_ICM20948, REG_ADD_REG_BANK_SEL, REG_VAL_REG_BANK_0); //swtich bank0
return;
}
void icm20948CalAvgValue(uint8_t *pIndex, int16_t *pAvgBuffer, int16_t InVal, int32_t *pOutVal)
{
uint8_t i;
*(pAvgBuffer + ((*pIndex) ++)) = InVal;
*pIndex &= 0x07;
*pOutVal = 0;
for(i = 0; i < 8; i ++)
{
*pOutVal += *(pAvgBuffer + i);
}
*pOutVal >>= 3;
}
void icm20948GyroOffset(void)
{
uint8_t i;
int16_t s16Gx = 0, s16Gy = 0, s16Gz = 0;
int32_t s32TempGx = 0, s32TempGy = 0, s32TempGz = 0;
for(i = 0; i < 32; i ++)
{
icm20948GyroRead(&s16Gx, &s16Gy, &s16Gz);
s32TempGx += s16Gx;
s32TempGy += s16Gy;
s32TempGz += s16Gz;
delay(10);
}
gstGyroOffset.s16X = s32TempGx >> 5;
gstGyroOffset.s16Y = s32TempGy >> 5;
gstGyroOffset.s16Z = s32TempGz >> 5;
return;
}
bool icm20948MagCheck(void)
{
bool bRet = false;
uint8_t u8Ret[2];
icm20948ReadSecondary( I2C_ADD_ICM20948_AK09916|I2C_ADD_ICM20948_AK09916_READ,
REG_ADD_MAG_WIA1, 2,u8Ret);
if( (u8Ret[0] == REG_VAL_MAG_WIA1) && ( u8Ret[1] == REG_VAL_MAG_WIA2) )
{
bRet = true;
}
return bRet;
}
/******************************************************************************
* BMP280 sensor device *
******************************************************************************/
typedef struct {
uint16_t T1; /*<calibration T1 data*/
int16_t T2; /*<calibration T2 data*/
int16_t T3; /*<calibration T3 data*/
uint16_t P1; /*<calibration P1 data*/
int16_t P2; /*<calibration P2 data*/
int16_t P3; /*<calibration P3 data*/
int16_t P4; /*<calibration P4 data*/
int16_t P5; /*<calibration P5 data*/
int16_t P6; /*<calibration P6 data*/
int16_t P7; /*<calibration P7 data*/
int16_t P8; /*<calibration P8 data*/
int16_t P9; /*<calibration P9 data*/
int32_t T_fine; /*<calibration t_fine data*/
}BMP280_HandleTypeDef;
typedef struct
{
uint8_t Index;
int32_t AvgBuffer[8];
}BMP280_AvgTypeDef;
#define dig_T1 bmp280.T1
#define dig_T2 bmp280.T2
#define dig_T3 bmp280.T3
#define dig_P1 bmp280.P1
#define dig_P2 bmp280.P2
#define dig_P3 bmp280.P3
#define dig_P4 bmp280.P4
#define dig_P5 bmp280.P5
#define dig_P6 bmp280.P6
#define dig_P7 bmp280.P7
#define dig_P8 bmp280.P8
#define dig_P9 bmp280.P9
#define t_fine bmp280.T_fine
#define MSLP 101325 // Mean Sea Level Pressure = 1013.25 hPA (1hPa = 100Pa = 1mbar)
BMP280_HandleTypeDef bmp280;
int32_t gs32Pressure0 = MSLP;
bool bmp280Check(void)
{
bool bRet = false;
if(0x58 == I2C_ReadOneByte(BMP280_ADDR, BMP280_REGISTER_CHIPID))
{
bRet = true;
}
return bRet;
}
void bmp280ReadCalibration(void)
{
uint8_t lsb, msb;
/* read the temperature calibration parameters */
lsb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_T1_LSB_REG);
msb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_T1_MSB_REG);
dig_T1 = msb << 8 | lsb;
lsb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_T2_LSB_REG);
msb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_T2_MSB_REG);
dig_T2 = msb << 8 | lsb;
lsb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_T3_LSB_REG);
msb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_T3_MSB_REG);
dig_T3 = msb << 8 | lsb;
/* read the pressure calibration parameters */
lsb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_P1_LSB_REG);
msb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_P1_MSB_REG);
dig_P1 = msb << 8 | lsb;
lsb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_P2_LSB_REG);
msb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_P2_MSB_REG);
dig_P2 = msb << 8 | lsb;
lsb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_P3_LSB_REG);
msb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_P3_MSB_REG);
dig_P3 = msb << 8 | lsb;
lsb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_P4_LSB_REG);
msb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_P4_MSB_REG);
dig_P4 = msb << 8 | lsb;
lsb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_P5_LSB_REG);
msb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_P5_MSB_REG);
dig_P5 = msb << 8 | lsb;
lsb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_P6_LSB_REG);
msb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_P6_MSB_REG);
dig_P6 = msb << 8 | lsb;
lsb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_P7_LSB_REG);
msb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_P7_MSB_REG);
dig_P7 = msb << 8 | lsb;
lsb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_P8_LSB_REG);
msb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_P8_MSB_REG);
dig_P8 = msb << 8 | lsb;
lsb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_P9_LSB_REG);
msb = I2C_ReadOneByte(BMP280_ADDR, BMP280_DIG_P9_MSB_REG);
dig_P9 = msb << 8 | lsb;
}
void bmp280Init(void)
{
I2C_WriteOneByte(BMP280_ADDR, BMP280_REGISTER_CONTROL, 0xFF);
I2C_WriteOneByte(BMP280_ADDR, BMP280_REGISTER_CONFIG, 0x14);
bmp280ReadCalibration();
}
float bmp280CompensateTemperature(int32_t adc_T)
{
int64_t var1, var2, temperature;
var1 = ((((adc_T>>3) - ((int64_t)dig_T1 <<1))) *((int64_t)dig_T2)) >> 11;
var2 = (((((adc_T>>4) - ((int64_t)dig_T1)) *((adc_T>>4) - ((int64_t)dig_T1))) >> 12) *
((int64_t)dig_T3)) >> 14;
t_fine = var1 + var2;
temperature = (t_fine * 5 + 128) >> 8;
return (float)temperature;
}
float bmp280CompensatePressure(int32_t adc_P)
{
int64_t var1, var2;
uint64_t pressure;
#if 1
var1 = ((int64_t)t_fine) - 128000;
var2 = var1 * var1 * (int64_t)dig_P6;
var2 = var2 + ((var1*(int64_t)dig_P5)<<17);
var2 = var2 + (((int64_t)dig_P4)<<35);
var1 = ((var1 * var1 * (int64_t)dig_P3)>>8) + ((var1 * (int64_t)dig_P2)<<12);
var1 = (((((int64_t)1)<<47)+var1))*((int64_t)dig_P1)>>33;
if (var1 == 0) {
return 0; // avoid exception caused by division by zero
}
pressure = 1048576.0 - adc_P;
pressure = (((pressure<<31) - var2)*3125) / var1;
var1 = (((int64_t)dig_P9) * (pressure>>13) * (pressure>>13)) >> 25;
var2 = (((int64_t)dig_P8) * pressure) >> 19;
pressure = ((pressure + var1 + var2) >> 8) + (((int64_t)dig_P7)<<4);
return (float)pressure/256;
#else
var1 = (((int64_t)t_fine)>>1) - (int64_t)64000;
var2 = (((var1>>2) * (var1>>2)) >> 11 ) *((int64_t)dig_P6);
var2 = var2 + ((var1 *((int64_t)dig_P5))<<1);
var2 = (var2>>2) + (((int64_t)dig_P4)<<16);
var1 = (((dig_P3 * (((var1>>2) * (var1>>2))>>13))>>3) + ((((int64_t)dig_P2) * var1)>>1))>>18;
var1 = ((((32768+var1))*((int64_t)dig_P1))>>15);
if(var1 ==0)
{
return 0;
}
pressure = (1048576.0 - adc_P) - (var2>>12)*3125;
if(pressure < 0x80000000)
{
pressure = (pressure<<1)/((uint64_t)var1);
}
else
{
pressure = (pressure/(uint64_t)var1)*2;
}
var1 = (((int64_t)dig_P9) *((int64_t)(((pressure>>3)*(pressure>>3))>>13)))>>12;
var2 = (((int64_t)(pressure>>2))*((int64_t)dig_P8))>>13;
pressure = (uint64_t)((int64_t)pressure) +((var1 + var2 + dig_P7)>>4);
return (float)pressure;
#endif
}
void bmp280TandPGet(float *temperature, float *pressure)
{
uint8_t lsb, msb, xlsb;
int32_t adc_P,adc_T;
xlsb = I2C_ReadOneByte(BMP280_ADDR, BMP280_TEMP_XLSB_REG);
lsb = I2C_ReadOneByte(BMP280_ADDR, BMP280_TEMP_LSB_REG);
msb = I2C_ReadOneByte(BMP280_ADDR, BMP280_TEMP_MSB_REG);
//adc_T = (msb << 12) | (lsb << 4) | (xlsb >> 4);
adc_T = msb;
adc_T <<= 8;
adc_T |= lsb;
adc_T <<= 8;
adc_T |= xlsb;
adc_T >>= 4;
//adc_T = 415148;
*temperature = bmp280CompensateTemperature(adc_T);
xlsb = I2C_ReadOneByte(BMP280_ADDR, BMP280_PRESS_XLSB_REG);
lsb = I2C_ReadOneByte(BMP280_ADDR, BMP280_PRESS_LSB_REG);
msb = I2C_ReadOneByte(BMP280_ADDR, BMP280_PRESS_MSB_REG);
//adc_P = (msb << 12) | (lsb << 4) | (xlsb >> 4);
adc_P = msb;
adc_P <<= 8;
adc_P |= lsb;
adc_P <<= 8;
adc_P |= xlsb;
adc_P >>= 4;
//adc_P = 51988;
*pressure = bmp280CompensatePressure(adc_P);
}
void bmp280CalAvgValue(uint8_t *pIndex, int32_t *pAvgBuffer, int32_t InVal, int32_t *pOutVal)
{
uint8_t i;
*(pAvgBuffer + ((*pIndex) ++)) = InVal;
*pIndex &= 0x07;
*pOutVal = 0;
for(i = 0; i < 8; i ++)
{
*pOutVal += *(pAvgBuffer + i);
}
*pOutVal >>= 3;
}
void bmp280CalculateAbsoluteAltitude(int32_t *pAltitude, int32_t PressureVal)
{
*pAltitude = 4433000 * (1 - pow((PressureVal / (float)gs32Pressure0), 0.1903));
}
void pressSensorDataGet(int32_t *ps32Temperature, int32_t *ps32Pressure, int32_t *ps32Altitude)
{
float CurPressure, CurTemperature;
int32_t CurAltitude;
static BMP280_AvgTypeDef BMP280_Filter[3];
bmp280TandPGet(&CurTemperature, &CurPressure);
bmp280CalAvgValue(&BMP280_Filter[0].Index, BMP280_Filter[0].AvgBuffer, (int32_t)(CurPressure), ps32Pressure);
bmp280CalculateAbsoluteAltitude(&CurAltitude, (*ps32Pressure));
bmp280CalAvgValue(&BMP280_Filter[1].Index, BMP280_Filter[1].AvgBuffer, CurAltitude, ps32Altitude);
bmp280CalAvgValue(&BMP280_Filter[2].Index, BMP280_Filter[2].AvgBuffer, (int32_t)CurTemperature, ps32Temperature);
return;
}
#ifdef __cplusplus
}
#endif

View File

@ -1,236 +0,0 @@
/**
******************************************************************************
* @file Waveshare_10Dof-D.h
* @author Waveshare Team
* @version V1.0
* @date Dec-2018
* @brief
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, WAVESHARE SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2018 Waveshare</center></h2>
******************************************************************************
*/
#ifndef __Waveshare_10DOF_D_H__
#define __Waveshare_10DOF_D_H__
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
/* define ICM-20948 Device I2C address*/
#define I2C_ADD_ICM20948 0x68
#define I2C_ADD_ICM20948_AK09916 0x0C
#define I2C_ADD_ICM20948_AK09916_READ 0x80
#define I2C_ADD_ICM20948_AK09916_WRITE 0x00
/* define ICM-20948 Register */
/* user bank 0 register */
#define REG_ADD_WIA 0x00
#define REG_VAL_WIA 0xEA
#define REG_ADD_USER_CTRL 0x03
#define REG_VAL_BIT_DMP_EN 0x80
#define REG_VAL_BIT_FIFO_EN 0x40
#define REG_VAL_BIT_I2C_MST_EN 0x20
#define REG_VAL_BIT_I2C_IF_DIS 0x10
#define REG_VAL_BIT_DMP_RST 0x08
#define REG_VAL_BIT_DIAMOND_DMP_RST 0x04
#define REG_ADD_PWR_MIGMT_1 0x06
#define REG_VAL_ALL_RGE_RESET 0x80
#define REG_VAL_RUN_MODE 0x01 //Non low-power mode
#define REG_ADD_LP_CONFIG 0x05
#define REG_ADD_PWR_MGMT_1 0x06
#define REG_ADD_PWR_MGMT_2 0x07
#define REG_ADD_ACCEL_XOUT_H 0x2D
#define REG_ADD_ACCEL_XOUT_L 0x2E
#define REG_ADD_ACCEL_YOUT_H 0x2F
#define REG_ADD_ACCEL_YOUT_L 0x30
#define REG_ADD_ACCEL_ZOUT_H 0x31
#define REG_ADD_ACCEL_ZOUT_L 0x32
#define REG_ADD_GYRO_XOUT_H 0x33
#define REG_ADD_GYRO_XOUT_L 0x34
#define REG_ADD_GYRO_YOUT_H 0x35
#define REG_ADD_GYRO_YOUT_L 0x36
#define REG_ADD_GYRO_ZOUT_H 0x37
#define REG_ADD_GYRO_ZOUT_L 0x38
#define REG_ADD_EXT_SENS_DATA_00 0x3B
#define REG_ADD_REG_BANK_SEL 0x7F
#define REG_VAL_REG_BANK_0 0x00
#define REG_VAL_REG_BANK_1 0x10
#define REG_VAL_REG_BANK_2 0x20
#define REG_VAL_REG_BANK_3 0x30
/* user bank 1 register */
/* user bank 2 register */
#define REG_ADD_GYRO_SMPLRT_DIV 0x00
#define REG_ADD_GYRO_CONFIG_1 0x01
#define REG_VAL_BIT_GYRO_DLPCFG_2 0x10 /* bit[5:3] */
#define REG_VAL_BIT_GYRO_DLPCFG_4 0x20 /* bit[5:3] */
#define REG_VAL_BIT_GYRO_DLPCFG_6 0x30 /* bit[5:3] */
#define REG_VAL_BIT_GYRO_FS_250DPS 0x00 /* bit[2:1] */
#define REG_VAL_BIT_GYRO_FS_500DPS 0x02 /* bit[2:1] */
#define REG_VAL_BIT_GYRO_FS_1000DPS 0x04 /* bit[2:1] */
#define REG_VAL_BIT_GYRO_FS_2000DPS 0x06 /* bit[2:1] */
#define REG_VAL_BIT_GYRO_DLPF 0x01 /* bit[0] */
#define REG_ADD_ACCEL_SMPLRT_DIV_2 0x11
#define REG_ADD_ACCEL_CONFIG 0x14
#define REG_VAL_BIT_ACCEL_DLPCFG_2 0x10 /* bit[5:3] */
#define REG_VAL_BIT_ACCEL_DLPCFG_4 0x20 /* bit[5:3] */
#define REG_VAL_BIT_ACCEL_DLPCFG_6 0x30 /* bit[5:3] */
#define REG_VAL_BIT_ACCEL_FS_2g 0x00 /* bit[2:1] */
#define REG_VAL_BIT_ACCEL_FS_4g 0x02 /* bit[2:1] */
#define REG_VAL_BIT_ACCEL_FS_8g 0x04 /* bit[2:1] */
#define REG_VAL_BIT_ACCEL_FS_16g 0x06 /* bit[2:1] */
#define REG_VAL_BIT_ACCEL_DLPF 0x01 /* bit[0] */
/* user bank 3 register */
#define REG_ADD_I2C_SLV0_ADDR 0x03
#define REG_ADD_I2C_SLV0_REG 0x04
#define REG_ADD_I2C_SLV0_CTRL 0x05
#define REG_VAL_BIT_SLV0_EN 0x80
#define REG_VAL_BIT_MASK_LEN 0x07
#define REG_ADD_I2C_SLV0_DO 0x06
#define REG_ADD_I2C_SLV1_ADDR 0x07
#define REG_ADD_I2C_SLV1_REG 0x08
#define REG_ADD_I2C_SLV1_CTRL 0x09
#define REG_ADD_I2C_SLV1_DO 0x0A
/* define ICM-20948 Register end */
/* define ICM-20948 MAG Register */
#define REG_ADD_MAG_WIA1 0x00
#define REG_VAL_MAG_WIA1 0x48
#define REG_ADD_MAG_WIA2 0x01
#define REG_VAL_MAG_WIA2 0x09
#define REG_ADD_MAG_ST2 0x10
#define REG_ADD_MAG_DATA 0x11
#define REG_ADD_MAG_CNTL2 0x31
#define REG_VAL_MAG_MODE_PD 0x00
#define REG_VAL_MAG_MODE_SM 0x01
#define REG_VAL_MAG_MODE_10HZ 0x02
#define REG_VAL_MAG_MODE_20HZ 0x04
#define REG_VAL_MAG_MODE_50HZ 0x05
#define REG_VAL_MAG_MODE_100HZ 0x08
#define REG_VAL_MAG_MODE_ST 0x10
/* define ICM-20948 MAG Register end */
#define MAG_DATA_LEN 6
/*
* BMP280 I2c address
*/
#define BMP280_AD0_LOW 0x76 //address pin low (GND)
#define BMP280_AD0_HIGH 0x77 //address pin high (VCC)
#define BMP280_ADDR BMP280_AD0_HIGH // default I2C address
/*
* BMP280 register address
*/
#define BMP280_REGISTER_DIG_T1 0x88
#define BMP280_REGISTER_DIG_T2 0x8A
#define BMP280_REGISTER_DIG_T3 0x8C
#define BMP280_REGISTER_DIG_P1 0x8E
#define BMP280_REGISTER_DIG_P2 0x90
#define BMP280_REGISTER_DIG_P3 0x92
#define BMP280_REGISTER_DIG_P4 0x94
#define BMP280_REGISTER_DIG_P5 0x96
#define BMP280_REGISTER_DIG_P6 0x98
#define BMP280_REGISTER_DIG_P7 0x9A
#define BMP280_REGISTER_DIG_P8 0x9C
#define BMP280_REGISTER_DIG_P9 0x9E
#define BMP280_REGISTER_CHIPID 0xD0
#define BMP280_REGISTER_VERSION 0xD1
#define BMP280_REGISTER_SOFTRESET 0xE0
#define BMP280_REGISTER_STATUS 0xF3
#define BMP280_REGISTER_CONTROL 0xF4
#define BMP280_REGISTER_CONFIG 0xF5
#define BMP280_TEMP_XLSB_REG 0xFC /*Temperature XLSB Register */
#define BMP280_TEMP_LSB_REG 0xFB /*Temperature LSB Register */
#define BMP280_TEMP_MSB_REG 0xFA /*Temperature LSB Register */
#define BMP280_PRESS_XLSB_REG 0xF9 /*Pressure XLSB Register */
#define BMP280_PRESS_LSB_REG 0xF8 /*Pressure LSB Register */
#define BMP280_PRESS_MSB_REG 0xF7 /*Pressure MSB Register */
/*calibration parameters */
#define BMP280_DIG_T1_LSB_REG 0x88
#define BMP280_DIG_T1_MSB_REG 0x89
#define BMP280_DIG_T2_LSB_REG 0x8A
#define BMP280_DIG_T2_MSB_REG 0x8B
#define BMP280_DIG_T3_LSB_REG 0x8C
#define BMP280_DIG_T3_MSB_REG 0x8D
#define BMP280_DIG_P1_LSB_REG 0x8E
#define BMP280_DIG_P1_MSB_REG 0x8F
#define BMP280_DIG_P2_LSB_REG 0x90
#define BMP280_DIG_P2_MSB_REG 0x91
#define BMP280_DIG_P3_LSB_REG 0x92
#define BMP280_DIG_P3_MSB_REG 0x93
#define BMP280_DIG_P4_LSB_REG 0x94
#define BMP280_DIG_P4_MSB_REG 0x95
#define BMP280_DIG_P5_LSB_REG 0x96
#define BMP280_DIG_P5_MSB_REG 0x97
#define BMP280_DIG_P6_LSB_REG 0x98
#define BMP280_DIG_P6_MSB_REG 0x99
#define BMP280_DIG_P7_LSB_REG 0x9A
#define BMP280_DIG_P7_MSB_REG 0x9B
#define BMP280_DIG_P8_LSB_REG 0x9C
#define BMP280_DIG_P8_MSB_REG 0x9D
#define BMP280_DIG_P9_LSB_REG 0x9E
#define BMP280_DIG_P9_MSB_REG 0x9F
#ifdef __cplusplus
extern "C" {
#endif
typedef enum
{
IMU_EN_SENSOR_TYPE_NULL = 0,
IMU_EN_SENSOR_TYPE_ICM20948,
IMU_EN_SENSOR_TYPE_BMP280,
IMU_EN_SENSOR_TYPE_MAX
}IMU_EN_SENSOR_TYPE;
typedef struct imu_st_angles_data_tag
{
float fYaw;
float fPitch;
float fRoll;
}IMU_ST_ANGLES_DATA;
typedef struct imu_st_sensor_data_tag
{
int16_t s16X;
int16_t s16Y;
int16_t s16Z;
}IMU_ST_SENSOR_DATA;
typedef struct icm20948_st_avg_data_tag
{
uint8_t u8Index;
int16_t s16AvgBuffer[8];
}ICM20948_ST_AVG_DATA;
void imuInit(IMU_EN_SENSOR_TYPE *penMotionSensorType, IMU_EN_SENSOR_TYPE *penPressureType);
void imuDataGet(IMU_ST_ANGLES_DATA *pstAngles,
IMU_ST_SENSOR_DATA *pstGyroRawData,
IMU_ST_SENSOR_DATA *pstAccelRawData,
IMU_ST_SENSOR_DATA *pstMagnRawData);
void pressSensorDataGet(int32_t *ps32Temperature, int32_t *ps32Pressure, int32_t *ps32Altitude);
uint8_t I2C_ReadOneByte(uint8_t DevAddr, uint8_t RegAddr);
void I2C_WriteOneByte(uint8_t DevAddr, uint8_t RegAddr, uint8_t value);
#ifdef __cplusplus
}
#endif
#endif //__Waveshare_10DOF_D_H__

View File

@ -1,235 +0,0 @@
#include <SPI.h>
#include <SD.h>
#include <nRF24L01.h>
#include <RF24.h>
//#include <Adafruit_INA219.h>
#include "DEV_Config.h"
//#include "L76X.h"
//#include "Waveshare_10Dof-D.h"
// Define pin numbers for modules
const int NRF_CE_PIN = 9;
const int NRF_CS_PIN = 8;
const byte address[6] = "00001";
//const int GPS_TX_PIN = 0;
//const int GPS_RX_PIN = 1;
//const String INA219_SDA_PIN = "A4";
//const String INA219_SCL_PIN = "A5";
const int BUZZER_PIN = 7;
const int READY_STAGE_PIN = 5;
const int LAUNCH_STAGE_PIN = 6;
// Create objects for modules
RF24 radio(NRF_CE_PIN, NRF_CS_PIN);
//GNRMC GPS1;
//Adafruit_INA219 ina219;
File dataFile;
// Flight stages
enum FlightStage {
READY,
ARM,
ASCENT,
DESCENT,
LANDED
};
FlightStage current_stage = READY;
void setup() {
// Initialize Serial
Serial.begin(115200);
Serial.println("# Welcome to CobraV2 operating system for rocket");
delay(1000);
// Buzzer pin
pinMode(BUZZER_PIN, OUTPUT);
pinMode(READY_STAGE_PIN, INPUT);
// Start with preflight stage
current_stage = READY;
delay(1000);
}
void loop() {
switch (current_stage) {
case READY:
ready_stage();
break;
case ARM:
arm_stag();
break;
case ASCENT:
ascent_stage();
break;
case DESCENT:
descent_stage();
break;
case LANDED:
landed_stage();
break;
}
}
void ready_stage() {
Serial.println("# READY stage");
int counter = 0;
while (true) {
int state = digitalRead(READY_STAGE_PIN);
if (state == HIGH) {
counter = 0;
} else {
counter += 1;
delay(300);
}
if (counter == 10) {
Serial.println("# Pin disconnected");
break;
}
}
current_stage = READY;
}
void arm_stage() {
// System check
// Block parachute ejection
// Wait for launch pin removed
// Start sending data
Serial.println("# READY stage");
// Radio
if (!radio.begin()) {
Serial.println("# Fail nRF24L01 init");
} else {
radio.openWritingPipe(address);
radio.stopListening(); // Set module as transmitter
const char msg[] = "# Radio connection activated";
radio.write(&msg, sizeof(msg));
Serial.println("# Success nRF24L01 init");
}
// GPS
//DEV_Set_Baudrate(9600);
//DEV_Delay_ms(500);
// IMU
//IMU_EN_SENSOR_TYPE enMotionSensorType, enPressureType;
//imuInit(&enMotionSensorType, &enPressureType);
//if (IMU_EN_SENSOR_TYPE_ICM20948 == enMotionSensorType) {
// Serial.println("# Success ICM-20948 init");
// Serial.println(IMU_EN_SENSOR_TYPE_ICM20948);
//} else {
// Serial.println("# Fail ICM-20948 init");
//}
//if (IMU_EN_SENSOR_TYPE_BMP280 == enPressureType) {
// Serial.println("# Success BMP280 init");
//} else {
// Serial.println("# Fail BMP280 init");
// Serial.println(enPressureType);
//}
// INA219
// if (!ina219.begin()) {
// Serial.println("# Fail INA219 sensor init");
// } else {
// Serial.println("# Success INA219 sensor init");
// }
// SD card
if (!SD.begin(4)) {
Serial.println("# Fail SD module init");
} else {
Serial.println("# Success SD module init");
}
if (SD.exists("data.txt")) {
Serial.println("# File exists");
} else {
Serial.println("# File does not exist");
}
dataFile = SD.open("data.txt", FILE_WRITE);
if (dataFile) {
Serial.println("# File opened");
dataFile.println("# CobraV2 flight data");
} else {
Serial.println("# Error opening file");
}
// Buzzer
tone(BUZZER_PIN, 1000);
delay(1000);
noTone(BUZZER_PIN);
// Check battery level
// float batteryLevel = getBatteryLevel();
// Serial.print("# Battery level: ");
// Serial.print(batteryLevel);
// Serial.println("%");
// Check for launch pin
int counter = 0;
while (true) {
int state = digitalRead(LAUNCH_STAGE_PIN);
if (state == HIGH) {
counter = 0;
} else {
counter += 1;
delay(300);
}
if (counter == 10) {
Serial.println("# Pin disconnected");
break;
}
}
current_stage = ASCENT;
}
void ascent_stage() {
// Launch
// Start sending and saving data on SD card
// Check for apogee
// Eject parachute
}
void descent_stage() {
// Detect apogee with accelerometer
// Eject parachute
// GPS and height check
}
void landed_stage() {
// Check for zero velocity
// Shut down unneeded systems
// Buzz on
// Send GPS location
// Battery check
// Turn off gyro and accelerometer
}
//float getBatteryLevel() {
// // Read bus voltage from INA219
// float busVoltage = ina219.getBusVoltage_V();
//
// // Assuming fully charged battery voltage is 4.2V and empty is 3.0V
// float maxVoltage = 4.2;
// float minVoltage = 3.0;
//
// // Map the bus voltage to a battery level percentage
// float batteryLevel = map(busVoltage, minVoltage, maxVoltage, 0, 100);
//
// // Constrain the battery level to be within 0 and 100
// batteryLevel = constrain(batteryLevel, 0, 100);
//
// return batteryLevel;
//}

View File

@ -1,4 +0,0 @@
# Problems
- Arduino Nano Couldn't power up the sd card reader, need to input 5V to micro SD card reader.
- Couldn't make Arduino Nano work with nRF24 - maybe same issue

View File

@ -1,27 +0,0 @@
# Sender module
## Stages of flight
1. Preflight - Remove before flight button or smthing like that
- no communication, blocked parachute ejection, all systems down
2. Ready - Signal from groundstation
- sys check (modules calibration, battery check, atd...), blocked parachute ejection, wait for launch pin removed, only send data, do not save them
3. Launch - Removed pin from the rocket
- launch, all systems sending and saving data on sd card
4. Apogee - Detected that rocket is in apogee with accelerometer
- parachute ejection, all systems working, gps check and height check
5. Return - Rocket has no velocity
- all not needed systems shutdown/sleep, buzz on, gps sending location, battery check, turn off gyro and accelerometer
## Modules
- nRF24L01 - Communication with groundstation
- SD card reader - Write all recieved data to the SD card
- Buzzer - To find our rocket after launch
- Servo motors - Ejection of parachute
## Tasks
- PCB for our computer
- send signal of listening
- wait for recieve

View File

@ -1,263 +0,0 @@
#include <SPI.h>
#include <SD.h>
#include <Servo.h>
#include "Arduino_BMI270_BMM150.h"
const int BUZZER_PIN = 2;
const int SERVO_A_PIN = 7;
const int CHIP_SELECT = 4;
// Create objects for modules
File dataFile;
Servo A;
// Flight stages
enum FlightStage
{
READY,
ARM,
ASCENT,
DESCENT,
LANDED
};
FlightStage current_stage = READY;
void setup()
{
// Initialize Serial
Serial.begin(115200);
//while (!Serial)
// ;
//Serial.println("# Welcome to CobraV2");
delay(1000);
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(BUZZER_PIN, LOW);
A.attach(SERVO_A_PIN);
A.write(80);
// Start with preflight stage
current_stage = READY;
delay(1000);
}
void loop()
{
switch (current_stage)
{
case READY:
ready_stage();
break;
case ARM:
arm_stage();
break;
case ASCENT:
ascent_stage();
break;
case DESCENT:
descent_stage();
break;
case LANDED:
landed_stage();
break;
}
}
void beep()
{
digitalWrite(BUZZER_PIN, HIGH);
delay(1000);
digitalWrite(BUZZER_PIN, LOW);
}
void ready_stage()
{
Serial.println("# READY stage");
analogWrite(LED_BUILTIN, HIGH);
beep();
if (!IMU.begin())
{
Serial.println("Failed to initialize IMU!");
while (1)
;
}
// SD card
//if (!SD.begin(CHIP_SELECT))
//{
// Serial.println("# Fail SD module init");
//}
//else
//{
// Serial.println("# Success SD module init");
//}
//
//if (SD.exists("data.txt"))
//{
// Serial.println("# File exists");
//}
//else
//{
// Serial.println("# File does not exist");
// dataFile = SD.open("data.txt", FILE_WRITE);
//}
//
//if (dataFile)
//{
// Serial.println("# File opened");
// dataFile.println("# CobraV2 flight data");
//}
//else
//{
// Serial.println("# Error opening file");
//}
Serial.print("# Accelerometer sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println(" Hz");
//dataFile.print("# Accelerometer sample rate = ");
//dataFile.println(IMU.accelerationSampleRate());
//dataFile.close();
current_stage = ARM;
}
void arm_stage()
{
// System check
// Block parachute ejection
// Wait for launch pin removed
// Start sending data
Serial.println("# ARM stage");
beep();
beep();
// Accelerometer Gyroscope
int counter = 0;
float x, y, z;
bool toggle = false;
//dataFile = SD.open("data.txt", FILE_WRITE);
//dataFile.println("# ARM stage");
while (true)
{
if (IMU.accelerationAvailable())
{
IMU.readAcceleration(x, y, z);
Serial.print(x);
Serial.print(", ");
Serial.print(y);
Serial.print(", ");
Serial.println(z);
//dataFile.print(x);
//dataFile.print(" ");
//dataFile.print(y);
//dataFile.print(" ");
//dataFile.println(z);
if (x > 1)
{
Serial.println("# Launch Detect");
counter++;
}
else
{
counter = 0;
}
}
if (counter < 15)
{
Serial.println("# Launching");
//dataFile.println("# Launching");
break;
}
if (toggle)
{
digitalWrite(LED_BUILTIN, HIGH);
}
else
{
digitalWrite(LED_BUILTIN, LOW);
}
toggle = !toggle;
}
current_stage = ASCENT;
//dataFile.close();
}
void ascent_stage()
{
Serial.println("# ASCENT Stage");
unsigned long StartTime = millis();
int FailOrientationCounter = 0;
//File dataFile = SD.open("data.txt", FILE_WRITE);
//dataFile.println("# ASCENT stage");
while (true)
{
unsigned long CurrentTime = millis();
unsigned long ElapsedTime = CurrentTime - StartTime;
Serial.println(ElapsedTime);
if (IMU.gyroscopeAvailable())
{
float x, y, z;
IMU.readGyroscope(x, y, z);
}
if ((ElapsedTime > 9000))
{
dataFile.println("# Apogee detected by time");
break;
}
}
current_stage = DESCENT;
//dataFile.close();
}
void descent_stage()
{
Serial.println("# DESCENT stage");
//File dataFile = SD.open("data.txt", FILE_WRITE);
//dataFile.println("# DESCENT stage");
A.write(80);
delay(1000);
A.write(180);
Serial.println("# Parachute deployed");
unsigned long StartTime = millis();
while (true)
{
unsigned long CurrentTime = millis();
unsigned long ElapsedTime = CurrentTime - StartTime;
if (ElapsedTime > 300000)
{
//dataFile.println("# Landing detected");
break;
}
}
current_stage = LANDED;
//dataFile.close();
}
void landed_stage()
{
while (true)
{
Serial.println("# LANDED stage");
beep();
delay(200);
}
}

View File

@ -1,10 +0,0 @@
module foglar/serial_read
go 1.20
require (
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

@ -1,6 +0,0 @@
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
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.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

View File

@ -1,148 +0,0 @@
package main
import (
"fmt"
"github.com/tarm/serial"
"log"
"os"
"strconv"
"time"
)
func portInput() string {
var port string
for true {
port = ""
fmt.Print("Enter port to listen on (for example - '/dev/ttyACM0'): ")
fmt.Scanln(&port)
if port == "" {
port = "/dev/ttyACM0"
}
_, err := os.Stat(port)
if !os.IsNotExist(err) {
break
}
fmt.Println("Invalid port")
}
return port
}
func baudrateInput() int {
var baudrate int
var s_baudrate string
fmt.Print("Enter baudrate (for example - '9600'): ")
fmt.Scanln(&s_baudrate)
baudrate = baudrateCheck(s_baudrate)
return baudrate
}
func baudrateCheck(s_baudrate string) int {
var baudrate int
switch s_baudrate {
case "4800":
baudrate = 4800
case "9600":
baudrate = 9600
case "115200":
baudrate = 115200
default:
baudrate = 9600
}
return baudrate
}
func UserInput() (string, int) {
port := portInput()
baudrate := baudrateInput()
return port, baudrate
}
func getTime() string {
return time.Now().Format("2006-1-2_15:4:5")
}
func main() {
args := os.Args[1:]
var port string
var baudrate int
// parsing command line arguments
if len(args) == 0 {
port, baudrate = UserInput()
} else {
i := 0
for i < len(args) {
if args[i] == "-p" && i+1 < len(args) {
port = args[i+1]
}
if args[i] == "-h" || args[i] == "--help" {
fmt.Println("-h, --help - prints this message")
fmt.Println("-p [port] - listens on port")
fmt.Println("-b [baudrate] - sets the baudrate")
fmt.Println("-d - runs the script with default values")
os.Exit(0)
}
if args[i] == "-b" && i+1 < len(args) {
var err error
baudrate, err = strconv.Atoi(args[i+1])
if err != nil {
fmt.Println("Invalid baudrate")
os.Exit(1)
}
}
if args[i] == "-d" {
port = "/dev/ACM0"
baudrate = 9600
}
i++
}
_, err := os.Stat(port)
if port == "" || os.IsNotExist(err) {
port = portInput()
}
if baudrate == 0 {
baudrate = baudrateInput()
}
}
// Listen on port
fmt.Printf("Listening on port %s with baudrate %d:\n", port, baudrate)
c := &serial.Config{Name: port, Baud: baudrate}
// Create file
filename := getTime() + ".txt"
f, err := os.Create(filename)
if err != nil {
log.Fatal(err)
}
defer f.Close()
// Open port
s, err := serial.OpenPort(c)
if err != nil {
log.Fatal(err)
}
var n int
for {
// create a buffer
buf := make([]byte, 254)
// Read length of serial input
n, err = s.Read(buf)
if err != nil {
log.Fatal(err)
}
// Print as a string
fmt.Print(string(buf[:n]))
f.WriteString(string(buf[:n]))
}
}

View File

@ -1,38 +0,0 @@
//go:build !windows
// +build !windows
package main
import (
"fmt"
"github.com/mitchellh/go-homedir"
"log"
"os"
)
var (
HOME string
PATH string
)
// Check if the directory exists
func init() {
var err error
HOME, err = homedir.Dir()
if err != nil {
log.Fatal(err)
}
PATH = HOME + "/.config/serial-monitor/"
if _, err := os.Stat(PATH); os.IsNotExist(err) {
// Directory does not exist, create it
err := os.MkdirAll(PATH, os.ModePerm)
if err != nil {
fmt.Println("Error creating directory:", err)
} else {
fmt.Println("Directory created:", PATH)
}
}
}

View File

@ -1,24 +0,0 @@
//go:build windows
// +build windows
package main
import (
"github.com/mitchellh/go-homedir"
"log"
)
var (
HOME string
PATH string
)
func init() {
var err error
HOME, err = homedir.Dir()
if err != nil {
log.Fatal(err)
}
PATH = HOME + "\\Downloads"
}

View File

@ -1,3 +0,0 @@
# gui_app_test
- preview of the gui app without connection to arduino

View File

@ -1,20 +0,0 @@
module test/test
go 1.21
toolchain go1.22.1
require (
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/gopxl/pixel v1.0.0
golang.org/x/image v0.15.0
)
require (
github.com/faiface/glhf v0.0.0-20211013000516-57b20770c369 // indirect
github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 // indirect
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
github.com/go-gl/mathgl v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
)

View File

@ -1,31 +0,0 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/faiface/glhf v0.0.0-20211013000516-57b20770c369 h1:gv4BgP50atccdK/1tZHDyP6rMwiiutR2HPreR/OyLzI=
github.com/faiface/glhf v0.0.0-20211013000516-57b20770c369/go.mod h1:dDdUO+G9ZnJ9sc8nIUvhLkE45k8PEKW6+A3TdWsfpV0=
github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 h1:baVdMKlASEHrj19iqjARrPbaRisD7EuZEVJj6ZMLl1Q=
github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3/go.mod h1:VEPNJUlxl5KdWjDvz6Q1l+rJlxF2i6xqDeGuGAxa87M=
github.com/go-gl/gl v0.0.0-20210905235341-f7a045908259/go.mod h1:wjpnOv6ONl2SuJSxqCPVaPZibGFdSci9HFocT9qtVYM=
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 h1:zDw5v7qm4yH7N8C8uWd+8Ii9rROdgWxQuGoJ9WDXxfk=
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw=
github.com/go-gl/glfw v0.0.0-20210727001814-0db043d8d5be/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b h1:GgabKamyOYguHqHjSkDACcgoPIz3w0Dis/zJ1wyHHHU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/mathgl v1.0.0/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ=
github.com/go-gl/mathgl v1.1.0 h1:0lzZ+rntPX3/oGrDzYGdowSLC2ky8Osirvf5uAwfIEA=
github.com/go-gl/mathgl v1.1.0/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/gopxl/pixel v1.0.0 h1:ZON6ll6/tI6sO8fwrlj93GVUcXReTST5//iKv6lcd8g=
github.com/gopxl/pixel v1.0.0/go.mod h1:kPUBG2He7/+alwmi5z0IwnpAc6pw2N7eA08cdBfoE/Q=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/image v0.0.0-20190321063152-3fc05d484e9f/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8=
golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

Binary file not shown.

View File

@ -1,78 +0,0 @@
package main
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) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
bytes, err := io.ReadAll(file)
if err != nil {
return nil, err
}
font, err := truetype.Parse(bytes)
if err != nil {
return nil, err
}
return truetype.NewFace(font, &truetype.Options{
Size: size,
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)
}
win.SetSmooth(true)
face, err := loadTTF("intuitive.ttf", 80)
if err != nil {
panic(err)
}
atlas := text.NewAtlas(face, text.ASCII)
txt := text.New(pixel.V(50, 500), atlas)
txt.Color = colornames.Lightgrey
fps := time.Tick(time.Second / 120)
for !win.Closed() {
txt.WriteString(win.Typed())
if win.JustPressed(pixelgl.KeyEnter) || win.Repeated(pixelgl.KeyEnter) {
txt.WriteRune('\n')
}
win.Clear(colornames.Darkcyan)
txt.Draw(win, pixel.IM.Moved(win.Bounds().Center().Sub(txt.Bounds().Center())))
win.Update()
<-fps
}
}
func main() {
pixelgl.Run(run)
}