This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func checkStatusAndUpdate() error { | |
s, err = getSerialPort(getPNPDeviceID()) | |
if err != nil { | |
return err | |
} | |
status, err := elite.GetStatusFromPath(filepath.FromSlash(getLogDir())) | |
if err != nil { | |
return err | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const baudRate = 9600 | |
type serialPort struct { | |
MaxBaudRate int | |
DeviceID string | |
} | |
func getSerialPort(pnp string) (*serial.Port, error) { | |
var dst []serialPort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
c := &serial.Config{Name: "COM45", Baud: 115200} | |
s, err := serial.OpenPort(c) | |
if err != nil { | |
log.Fatal(err) | |
} | |
n, err := s.Write([]byte("test")) | |
if err != nil { | |
log.Fatal(err) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ExpandFlags parses the RawFlags and sets the Flags values accordingly. | |
func (status *Status) ExpandFlags() { | |
status.Flags.Docked = status.RawFlags&FlagDocked != 0 | |
status.Flags.Landed = status.RawFlags&FlagLanded != 0 | |
status.Flags.LandingGearDown = status.RawFlags&FlagLandingGearDown != 0 | |
// etc. | |
} | |
func GetStatus() (*Status, error) { | |
// Build the file path from the user's home directory. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Status represents the current state of the player and ship. | |
type Status struct { | |
Timestamp string `json:"timestamp"` | |
Event string `json:"event"` | |
// Naming this 'RawFlags' since it will only really by used until | |
// the values are extracted into the Flags below. | |
RawFlags uint32 `json:"Flags"` | |
// The actual flag values will be set by parsing RawFlags. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get the states of the physical switches and write them to the Toggleswitch objects. | |
// Assuming for now that all global variables referenced here are declared and initialized. | |
void updateKeys() { | |
if (!kpd.getKeys()) { | |
return; | |
} | |
for (int i = 0; i < LIST_MAX; i++) { | |
if (kpd.key[i].kchar == NO_KEY) { | |
continue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void serialRx() { | |
if (!Serial.available()) { | |
return; | |
} | |
DynamicJsonBuffer jsonBuffer(512); | |
JsonObject &root = jsonBuffer.parseObject(Serial); | |
if (!root.success()) { | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Global variable to hold the flags from the game state. | |
#define NO_FLAGS 0 | |
unsigned long currentFlags = NO_FLAGS; | |
// Each button press will last about 100ms. | |
#define BUTTON_HOLD_TIME 100 | |
struct Toggleswitch { | |
byte currState; // State of the physical switch. | |
byte lastState; // Last known state of the physical switch. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"timestamp": "2017-12-07T10:31:37Z", | |
"event": "Status", | |
"Flags": 16842765, | |
"Pips": [2,8,2], | |
"FireGroup": 0, | |
"Fuel": { | |
"FuelMain": 15.146626, | |
"FuelReservoir": 0.382796 | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ArduinoJson.h> | |
#include <Key.h> | |
#include <Keypad.h> | |
// Allow 5 seconds of lag from the device, to the game, and back to the device. | |
#define BUTTON_SYNC_TIME 5000 | |
// Each button press will last about 100ms. | |
#define BUTTON_HOLD_TIME 100 |
NewerOlder