changes to adafruit library to interface with nfc shield, also fixes an issue in the library (zip)
This commit is contained in:
parent
b0778df859
commit
55dd4311d2
4 changed files with 48 additions and 9 deletions
|
@ -99,5 +99,7 @@
|
|||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_SIZE/@EntryValue" value="4" type="int" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CONTINUOUS_LINE_INDENT/@EntryValue" value="Double" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TAB_WIDTH/@EntryValue" value="4" type="int" />
|
||||
<option name="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASPI_002Eh_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FLocal_003FTemp_003F7e10e8c0_002D08d1_002D4626_002D8c7e_002D9a1cd5f4c818_005Fvma211_005Fspi_002Ezip_002E818_003Fvma211_005Fspi_003FSPI_002Eh/@EntryIndexedValue" />
|
||||
<option name="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASPI_002Eh_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FLocal_003FTemp_003F7e10e8c0_002D08d1_002D4626_002D8c7e_002D9a1cd5f4c818_005Fvma211_005Fspi_002Ezip_002E818_003Fvma211_005Fspi_003FSPI_002Eh/@EntryIndexRemoved" />
|
||||
</component>
|
||||
</project>
|
BIN
libraries/Adafruit-PN532-1.3.3.zip
Normal file
BIN
libraries/Adafruit-PN532-1.3.3.zip
Normal file
Binary file not shown.
BIN
libraries/og_Adafruit-PN532-1.3.3.zip
Normal file
BIN
libraries/og_Adafruit-PN532-1.3.3.zip
Normal file
Binary file not shown.
|
@ -1,6 +1,7 @@
|
|||
#include <LiquidCrystal.h>
|
||||
#include <PN532.h>
|
||||
#include <Wire.h>
|
||||
#include <SPI.h>
|
||||
#include <Adafruit_PN532.h>
|
||||
|
||||
#include "station.h"
|
||||
#include "statemachine.h"
|
||||
|
@ -10,13 +11,15 @@
|
|||
|
||||
#define PN532_CS 10
|
||||
|
||||
PN532 nfc(PN532_CS);
|
||||
Adafruit_PN532 nfc(PN532_CS);
|
||||
|
||||
const int rs = 9, en = 8, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
|
||||
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
|
||||
|
||||
Station stations[4] = { Station(1680767519, "Yellow"), Station(3346823711, "Green"), Station(3569318175, "Pink"), Station(2174777887, "Blue") };
|
||||
Timer stationDetectionTimer(1000, true);
|
||||
Station* currentStation;
|
||||
|
||||
Timer stationDetectionTimer(3000, true);
|
||||
|
||||
StateMachine stateMachine(new Startup());
|
||||
|
||||
|
@ -28,8 +31,6 @@ void setup(void) {
|
|||
setupNFC();
|
||||
|
||||
lcd.begin(16, 2);
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Test");
|
||||
stationDetectionTimer.start();
|
||||
}
|
||||
|
||||
|
@ -38,14 +39,20 @@ void loop(void) {
|
|||
deltaTime = currentLoopTime - lastLoopTime;
|
||||
|
||||
bool doCheck = stationDetectionTimer.update(deltaTime);
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print(" ");
|
||||
if (doCheck) {
|
||||
lcd.clear();
|
||||
checkStations();
|
||||
lcd.setCursor(7, 1);
|
||||
lcd.print("check");
|
||||
}
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print(String(deltaTime));
|
||||
|
||||
stateMachine.update(Context(stations, deltaTime));
|
||||
|
||||
lastLoopTime = currentLoopTime;
|
||||
delay(100);
|
||||
}
|
||||
|
||||
void setupNFC() {
|
||||
|
@ -62,15 +69,45 @@ void setupNFC() {
|
|||
|
||||
void checkStations() {
|
||||
Station* station = detectStation();
|
||||
lcd.setCursor(0, 0);
|
||||
|
||||
if (station != 0) {
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(" ");
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Station: " + station->getName());
|
||||
if (currentStation == 0) {
|
||||
currentStation = station;
|
||||
stateMachine.putDown(currentStation);
|
||||
}
|
||||
} else {
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(" ");
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("not docked");
|
||||
if (currentStation != 0) {
|
||||
currentStation = 0;
|
||||
stateMachine.pickedUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Station* detectStation() {
|
||||
uint32_t id;
|
||||
id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);
|
||||
uint8_t uid[7];
|
||||
uint8_t uidLength;
|
||||
uint16_t timeout = 100;
|
||||
bool success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength, timeout);
|
||||
|
||||
if (!success) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t id = 0;
|
||||
for (uint8_t i = 0; i < uidLength; i++) {
|
||||
id <<= 8;
|
||||
id |= uid[i];
|
||||
}
|
||||
|
||||
|
||||
Station* found = 0;
|
||||
for (int i = 0; i < sizeof(stations); i++) {
|
||||
Station* currentStation = &stations[i];
|
||||
|
|
Loading…
Reference in a new issue