Compare commits
2 commits
aa2f2e4803
...
b330ddab37
Author | SHA1 | Date | |
---|---|---|---|
b330ddab37 | |||
8d80dd2604 |
6 changed files with 127 additions and 8 deletions
59
README.md
59
README.md
|
@ -69,7 +69,64 @@ mise à jour et suivi des dépendances.
|
||||||
La structure du code assume une carte Teensy. En particulier, il est conçu pour la
|
La structure du code assume une carte Teensy. En particulier, il est conçu pour la
|
||||||
[Teensy 4.1](https://www.pjrc.com/store/teensy41.html).
|
[Teensy 4.1](https://www.pjrc.com/store/teensy41.html).
|
||||||
|
|
||||||
|
# Interfaçage avec l'application Unity
|
||||||
|
|
||||||
|
Afin de permettre la détection automatique de l'objet, la communication se fait
|
||||||
|
par Human Interface Device (HID).
|
||||||
|
La communication HID est possible grâce aux bibliothèques de Teensyduino qui
|
||||||
|
fournissent des fonctionnalités de base.
|
||||||
|
Ces fonctionnalités ne sont pas idéales et gâchent pas mal de bande passante,
|
||||||
|
en effet par défaut on ne peut qu'envoyer des rapports HIDs de 64 octets, malgré
|
||||||
|
le besoin de n'en consommer que quelques-uns dans le cas général.
|
||||||
|
Faute de vouloir modifier les bibliothèques Teensyduino, nous nous contenterons
|
||||||
|
de ce gâchis, la Teensy étant absurdement rapide de toute façon.
|
||||||
|
|
||||||
|
## Protocole
|
||||||
|
|
||||||
|
Le protocole est constitué de messages avec un octet d'en-tête, puis d'un message
|
||||||
|
de longueur définie par l'en-tête, potentiellement variable jusqu'au maximum de
|
||||||
|
64 octets (avec en-tête).
|
||||||
|
|
||||||
|
### Changement de figurine
|
||||||
|
|
||||||
|
**En-tête** : `@`
|
||||||
|
**Longueur** : 1 octet
|
||||||
|
**Description** : Message envoyé lors de la dépose ou du retrait d'une figurine.
|
||||||
|
Il contient l'ID de la figurine sur les bits 0-5 de l'octet, si la figurine
|
||||||
|
est un personnage (1) ou une année (0) sur le bit 6 et si la figurine a été posée
|
||||||
|
(0) ou retirée (1) sur le bit 7.
|
||||||
|
Ainsi, si on interprète l'octet comme un nombre signé, si le nombre est négatif
|
||||||
|
on sait que la figurine a été retirée.
|
||||||
|
|
||||||
|
#### Schéma
|
||||||
|
```
|
||||||
|
Octet 1
|
||||||
|
┌─┬─┬───────────┐
|
||||||
|
│D│C│ Figure ID │
|
||||||
|
└─┴─┴───────────┘
|
||||||
|
7 0 - Bits
|
||||||
|
```
|
||||||
|
`D`: bit 7, 1 si enlevé, 0 sinon
|
||||||
|
`C`: bit 6, 1 si personnage, 0 si année
|
||||||
|
|
||||||
|
### Message informatif
|
||||||
|
|
||||||
|
**En-tête** : `#`
|
||||||
|
**Longueur** : 1+[1-62] octets
|
||||||
|
**Description** : Message générique à titre informatif, utile pour la communication
|
||||||
|
d'informations lors du développement ou de débug.
|
||||||
|
Le premier octet est fixe et donne la longueur du reste du message, le message
|
||||||
|
est du texte encodé en ASCII.
|
||||||
|
|
||||||
|
#### Schéma
|
||||||
|
```
|
||||||
|
┌───┬── ── ── ──┐
|
||||||
|
│Len│ Message │
|
||||||
|
└───┴── ── ── ──┘
|
||||||
|
0 1 Len - Octets
|
||||||
|
```
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
Les éléments dans ce dépôts sont Open Source, sous license
|
Les éléments dans ce dépôt sont Open Source, sous license
|
||||||
[Apache License V2.0](https://apache.org/licenses/LICENSE-2.0).
|
[Apache License V2.0](https://apache.org/licenses/LICENSE-2.0).
|
||||||
|
|
20
include/Com.h
Normal file
20
include/Com.h
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
//
|
||||||
|
// Created by Teo-CD on 24/09/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef JIN_BARBAPAPA_COM_H
|
||||||
|
#define JIN_BARBAPAPA_COM_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle communication with a connected device and provide convenience
|
||||||
|
* functions for the fixed protocols.
|
||||||
|
*/
|
||||||
|
namespace Com {
|
||||||
|
void sendFigUpdate(int8_t event);
|
||||||
|
void sendComment(const char* message, ...);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //JIN_BARBAPAPA_COM_H
|
|
@ -17,3 +17,5 @@ lib_deps =
|
||||||
adafruit/Adafruit PCD8544 Nokia 5110 LCD library
|
adafruit/Adafruit PCD8544 Nokia 5110 LCD library
|
||||||
adafruit/Adafruit GFX Library
|
adafruit/Adafruit GFX Library
|
||||||
adafruit/Adafruit BusIO
|
adafruit/Adafruit BusIO
|
||||||
|
; Should be uncommented in production in order to use HID.
|
||||||
|
;build_flags = -D USB_RAWHID
|
||||||
|
|
39
src/Com.cpp
Normal file
39
src/Com.cpp
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
//
|
||||||
|
// Created by Teo-CD on 24/09/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "Com.h"
|
||||||
|
|
||||||
|
namespace Com {
|
||||||
|
byte buffer[64];
|
||||||
|
/**
|
||||||
|
* Will flush buffer through either HID or Serial depending on build
|
||||||
|
* options.
|
||||||
|
* HID is the expected production usage as the interactive software will
|
||||||
|
* use it for auto-detection.
|
||||||
|
*/
|
||||||
|
inline void flushBuffer() {
|
||||||
|
#ifdef USB_RAWHID
|
||||||
|
usb_rawhid_send(buffer, 0);
|
||||||
|
#else
|
||||||
|
Serial.write((const char*)buffer);
|
||||||
|
#endif
|
||||||
|
/* Clear the buffer. */
|
||||||
|
memset(buffer, 0, 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendFigUpdate(int8_t event) {
|
||||||
|
buffer[0] = '@';
|
||||||
|
buffer[1] = event;
|
||||||
|
flushBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendComment(const char *message, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, message);
|
||||||
|
buffer[0] = '#';
|
||||||
|
buffer[1] = vsnprintf((char *)(buffer + 2), 62, message, args);
|
||||||
|
va_end(args);
|
||||||
|
flushBuffer();
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,9 +37,9 @@ int8_t RFID::checkTags() {
|
||||||
// Serial.printf("UID 0x%lX is gone\n", *(uint32_t *)node->uid.uidByte);
|
// Serial.printf("UID 0x%lX is gone\n", *(uint32_t *)node->uid.uidByte);
|
||||||
// If we don't, assume the tag is gone and remove it from the list.
|
// If we don't, assume the tag is gone and remove it from the list.
|
||||||
removeActiveTag(node, previousNode);
|
removeActiveTag(node, previousNode);
|
||||||
// Return the negative ID to signal it has gone.
|
// Return the ID with the sign bit set to signal it has gone.
|
||||||
// If other tags are gone we can check on the next loop.
|
// If other tags are gone we can check on the next loop.
|
||||||
return -node->tag_ID;
|
return node->tag_ID | 1<<7;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
11
src/main.cpp
11
src/main.cpp
|
@ -3,6 +3,7 @@
|
||||||
#include "Pinout.h"
|
#include "Pinout.h"
|
||||||
|
|
||||||
#include "RFID.h"
|
#include "RFID.h"
|
||||||
|
#include "Com.h"
|
||||||
|
|
||||||
__attribute__((noreturn)) int main() {
|
__attribute__((noreturn)) int main() {
|
||||||
pinMode(pin_DBG_LED_1, OUTPUT);
|
pinMode(pin_DBG_LED_1, OUTPUT);
|
||||||
|
@ -36,7 +37,7 @@ __attribute__((noreturn)) int main() {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("# System is powered up, running set-up.");
|
Com::sendComment("# System is powered up, running set-up.");
|
||||||
|
|
||||||
/* TODO: Setups once module structure is up. */
|
/* TODO: Setups once module structure is up. */
|
||||||
RFID rfid;
|
RFID rfid;
|
||||||
|
@ -45,11 +46,11 @@ __attribute__((noreturn)) int main() {
|
||||||
|
|
||||||
/* Main loop */
|
/* Main loop */
|
||||||
while (true) {
|
while (true) {
|
||||||
int8_t tagID;
|
int8_t tagEvent;
|
||||||
|
|
||||||
tagID = rfid.checkTags();
|
tagEvent = rfid.checkTags();
|
||||||
if (tagID) {
|
if (tagEvent) {
|
||||||
Serial.printf("Check tag result : %d\n", tagID);
|
Com::sendFigUpdate(tagEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue