-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: tugpoat <[email protected]>
- Loading branch information
Showing
8 changed files
with
263 additions
and
11 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/* | ||
YACardEmu | ||
---------------- | ||
Copyright (C) 2020-2023 wutno (https://github.com/GXTX) | ||
Copyright (C) 2022-2023 tugpoat (https://github.com/tugpoat) | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License along | ||
with this program; if not, write to the Free Software Foundation, Inc., | ||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#include "C1231BR.h" | ||
|
||
C1231BR::C1231BR(CardIo::Settings* settings) : CardIo(settings) | ||
{ | ||
} | ||
|
||
void C1231BR::UpdateRStatus() | ||
{ | ||
// We "grab" the card for the user | ||
if (localStatus.position == CardPosition::POS_IN_FRONT) { | ||
m_cardSettings->insertedCard = false; | ||
MoveCard(MovePositions::NO_CARD); | ||
} | ||
|
||
// We require the user to "insert" a card if we're waiting | ||
if (m_cardSettings->insertedCard && localStatus.position == CardPosition::NO_CARD) { | ||
MoveCard(MovePositions::READ_WRITE_HEAD); | ||
|
||
if (runningCommand && status.s == S::WAITING_FOR_CARD) { | ||
// Make sure the user can actually insert a card | ||
localStatus.shutter = true; | ||
status.s = S::RUNNING_COMMAND; | ||
} | ||
} | ||
} | ||
|
||
bool C1231BR::HasCard() | ||
{ | ||
return localStatus.position != CardPosition::NO_CARD; | ||
} | ||
|
||
void C1231BR::DispenseCard() | ||
{ | ||
localStatus.position = CardPosition::POS_THERM_DISP; | ||
} | ||
|
||
void C1231BR::EjectCard() | ||
{ | ||
if (localStatus.position != CardPosition::NO_CARD) { | ||
localStatus.shutter = true; | ||
localStatus.position = CardPosition::POS_IN_FRONT; | ||
} | ||
} | ||
|
||
uint8_t C1231BR::GetRStatus() | ||
{ | ||
return localStatus.GetByte(); | ||
} | ||
|
||
void C1231BR::Command_10_Initalize() | ||
{ | ||
enum Mode { | ||
Standard = 0x30, // We actually eject anyway.. | ||
EjectAfter = 0x31, | ||
ResetSpecifications = 0x32, | ||
}; | ||
|
||
Mode mode = static_cast<Mode>(currentPacket[0]); | ||
|
||
switch (currentStep) { | ||
case 1: | ||
if (mode == Mode::EjectAfter) { | ||
localStatus.shutter = true; | ||
} | ||
if (HasCard()) { | ||
EjectCard(); | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
if (currentStep > 1) { | ||
runningCommand = false; | ||
} | ||
} | ||
|
||
void C1231BR::Command_D0_ShutterControl() | ||
{ | ||
// Only actions are to close and open the shutter | ||
enum Action { | ||
Close = 0x30, | ||
Open = 0x31, | ||
}; | ||
|
||
Action action = static_cast<Action>(currentPacket[0]); | ||
|
||
if (action == Action::Open) { | ||
localStatus.shutter = true; | ||
} else { | ||
localStatus.shutter = false; | ||
} | ||
|
||
runningCommand = false; | ||
} | ||
|
||
void C1231BR::MoveCard(CardIo::MovePositions position) | ||
{ | ||
switch (position) { | ||
case MovePositions::NO_CARD: | ||
localStatus.position = CardPosition::NO_CARD; | ||
break; | ||
case MovePositions::READ_WRITE_HEAD: | ||
localStatus.position = CardPosition::POS_MAG; | ||
break; | ||
case MovePositions::THERMAL_HEAD: | ||
localStatus.position = CardPosition::POS_THERM; | ||
break; | ||
case MovePositions::DISPENSER_THERMAL: | ||
localStatus.position = CardPosition::POS_THERM_DISP; | ||
break; | ||
case MovePositions::EJECT: | ||
localStatus.position = CardPosition::POS_IN_FRONT; | ||
break; | ||
default: break; | ||
} | ||
} | ||
|
||
CardIo::MovePositions C1231BR::GetCardPos() | ||
{ | ||
switch (localStatus.position) { | ||
case CardPosition::NO_CARD: | ||
return MovePositions::NO_CARD; | ||
case CardPosition::POS_MAG: | ||
return MovePositions::READ_WRITE_HEAD; | ||
case CardPosition::POS_THERM: | ||
return MovePositions::THERMAL_HEAD; | ||
case CardPosition::POS_THERM_DISP: | ||
return MovePositions::DISPENSER_THERMAL; | ||
case CardPosition::POS_IN_FRONT: | ||
return MovePositions::EJECT; | ||
default: | ||
return MovePositions::NO_CARD; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
YACardEmu | ||
---------------- | ||
Copyright (C) 2020-2023 wutno (https://github.com/GXTX) | ||
Copyright (C) 2022-2023 tugpoat (https://github.com/tugpoat) | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License along | ||
with this program; if not, write to the Free Software Foundation, Inc., | ||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#ifndef C1231BR_H | ||
#define C1231BR_H | ||
|
||
#include <atomic> | ||
#include <ctime> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
#include "CardIo.h" | ||
|
||
class C1231BR : public CardIo { | ||
public: | ||
C1231BR(CardIo::Settings* settings); | ||
|
||
protected: | ||
enum class CardPosition { | ||
NO_CARD = 0b00000, | ||
POS_MAG = 0b11000, | ||
POS_THERM = 0b00111, | ||
POS_THERM_DISP = 0b11100, | ||
POS_IN_FRONT = 0b00001, | ||
}; | ||
|
||
struct LocalStatus { | ||
bool shutter = true; | ||
bool dispenser = true; // report full dispenser | ||
CardPosition position = CardPosition::NO_CARD; | ||
|
||
uint8_t GetByte() | ||
{ | ||
return 1 << (shutter ? 7 : 6) | (dispenser ? 1 : 0) << 5 | static_cast<uint8_t>(position); | ||
} | ||
}; | ||
|
||
LocalStatus localStatus{}; | ||
bool HasCard() override; | ||
void DispenseCard() override; | ||
void EjectCard() override; | ||
void UpdateRStatus() override; | ||
uint8_t GetRStatus() override; | ||
|
||
void Command_10_Initalize() override; | ||
void Command_D0_ShutterControl() override; | ||
|
||
void MoveCard(CardIo::MovePositions position) override; | ||
CardIo::MovePositions GetCardPos() override; | ||
}; | ||
|
||
#endif // C1231BR |
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
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
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
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
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