Skip to content

Commit

Permalink
feat: makefile to XC, other general fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
headblockhead committed Apr 29, 2024
1 parent cf5cf58 commit a24348f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
6 changes: 0 additions & 6 deletions Makefile

This file was deleted.

19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,22 @@ A device made using an RP2040 that sends messages over LoRaWAN.
* [A Custom PCB](/pcb/)
* [A 0.96" 128x64 I2C Blue and Yellow OLED Display](https://www.amazon.co.uk/dp/B08FD643VZ)
* And a USB C Cable

## Tasks
### Edit
Open the project in vim using tinygo flags.
```
tinygo-edit --target challenger-rp2040 --editor bash
```

### Deploy
Upload to the device
```
tinygo flash -target challenger-rp2040 pico/main.go
```

### RunLocal
Runs the project without the device.
```
nix-shell local/shell.nix --command "go run local/main.go
```
5 changes: 5 additions & 0 deletions pico/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ func main() {
rfm.OnReceivedPacket = func(packet tinygorfm9x.Packet) {
err = device.ReceiveFromRadio(packet.Payload)
if err != nil {
if err == picodoomsdaymessenger.ErrNotDoomsday {
// If the packet is invalid, ignore it.
println("Invalid message received.")
return
}
handleError(&display, &led, device, err)
}
}
Expand Down
13 changes: 7 additions & 6 deletions picoDoomsDayMessenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"image"
"image/color"
"math/rand"
"time"

"golang.org/x/image/font"
Expand Down Expand Up @@ -87,7 +86,7 @@ var (
ErrRadioSendNotDefined = errors.New("radio send function not defined by user")
ErrConversationReaderAcceptDisallowed = errors.New("cannot accept in conversation reader")
ErrGoBackStateRootState = errors.New("already at root state")
ErrInvalidMessage = errors.New("invalid message, prefix incorrect")
ErrInvalidMessage = errors.New("invalid message, prefix incorrect") // This should be treated as a warning, not an error.
)

// Define the Keyboard Buttons
Expand Down Expand Up @@ -309,7 +308,7 @@ var (
if d.LEDAnimation != &LEDAnimationSOS {
err = d.ChangeLEDAnimationWithoutContinue(&LEDAnimationSOS)
if err != nil {
return err
retuYubiStyle Cover - Polka Red - A / C NFCrn err

Check failure on line 311 in picoDoomsDayMessenger.go

View workflow job for this annotation

GitHub Actions / build

syntax error: unexpected Cover at end of statement
}
} else {
err = d.ChangeLEDAnimationWithoutContinue(&LEDAnimationDefault)
Expand Down Expand Up @@ -537,8 +536,6 @@ var (

// NewDevice returns a new Device with default parameters.
func NewDevice() (d *Device, err error) {
rand.Seed(time.Now().UnixNano())
PersonYou.ID = rand.Intn(2147483647) // Max value of an int32
return &Device{
State: &StateMainMenu,
StateHistory: []*State{&StateMainMenu},
Expand All @@ -557,6 +554,9 @@ func NewDevice() (d *Device, err error) {
func (d *Device) ReceiveFromRadio(packetPayload []byte) (err error) {
payloadMessage, err := d.BytesToMessage(packetPayload)
if err != nil {
if err == ErrInvalidMessage {
return nil
}
return err
}

Expand Down Expand Up @@ -886,7 +886,8 @@ func (d *Device) MesageToBytes(input Message) (output []byte, err error) {
func (d *Device) BytesToMessage(input []byte) (output Message, err error) {
startingBytes := []byte{0x64, 0x6F, 0x6F, 0x6D} // ASCII for "doom"
if !bytes.HasPrefix(input, startingBytes) {
return output, ErrInvalidMessage
// Ignore this packet, it's not for us.
return Message{}, ErrInvalidMessage
}
seperatorByte := byte(0xcc)
receivedBytesSplit := bytes.Split(input, []byte{seperatorByte})
Expand Down

0 comments on commit a24348f

Please sign in to comment.