Compare commits

..

7 Commits

Author SHA1 Message Date
0218eabc34 add dependency information 2021-01-24 16:10:55 +09:00
f413eae2fd omit sending hat if direction is not changed 2021-01-01 21:53:43 +09:00
9454fdc54e implement hitbox compatible SOCD. 2020-09-18 22:17:12 +09:00
20a25ecf26 tmp 2020-09-17 00:23:53 +09:00
dbff5cf2ac tmp 2020-09-15 21:48:26 +09:00
6ab58857c7 tmp 2020-09-15 20:13:43 +09:00
7539e3658a disable rapid fire 2020-09-15 18:29:48 +09:00
2 changed files with 93 additions and 208 deletions

View File

@@ -3,8 +3,5 @@ Arduino Pro Micro でコントローラー自作するときのスケッチ
## 依存ライブラリ ## 依存ライブラリ
- [SwitchControlLibrary](https://github.com/celclow/SwitchControlLibrary) をフォークし[一部改変したもの](https://git.sirrow.work/sirrow/SwitchControlLibrary) - [SwitchControlLibrary](https://github.com/celclow/SwitchControlLibrary) をフォークし[一部改変したもの](https://git.sirrow.work/sirrow/SwitchControlLibrary)
- ArduinoSTL(v1.3.2 で実績あり) - ArduinoSTL
- MsTimer2(v1.1.0 で実績あり) - MsTimer2
## 利用ボードライブラリ
- SparkFun AVR Boards (v1.1.13で実績あり)

View File

@@ -1,21 +1,17 @@
#include <MsTimer2.h> #include <MsTimer2.h>
#include <SwitchControlLibrary.h> #include <SwitchControlLibrary.h>
#define RapidFireTableSize 34 #define RapidFireTableSize 40
int loopCount = 0; int loopCount = 0;
int state = 0; int state = 0;
int rapidFireTable[RapidFireTableSize]; int rapidFireTable[RapidFireTableSize];
bool rapidPressState = 0;
int index = 0; int index = 0;
int val = 1; int val = 1;
int prevVal = 1; int prevVal = 1;
int gameMode = 0; struct arrow {
struct arrow
{
int pinNumber; int pinNumber;
int current; int current;
int prev; int prev;
@@ -24,8 +20,7 @@ struct arrow
Hat arrowSymbol; Hat arrowSymbol;
}; };
struct ButtonInfo struct ButtonInfo {
{
int pinNumber; int pinNumber;
bool prev; bool prev;
bool current; bool current;
@@ -33,38 +28,32 @@ struct ButtonInfo
}; };
struct arrow arrowTable[4]; struct arrow arrowTable[4];
struct arrow oldestArrow;
struct arrow newestArrow;
struct arrow oldestXArrow; struct arrow oldestXArrow;
struct arrow newestXArrow; struct arrow newestXArrow;
struct arrow oldestYArrow; struct arrow oldestYArrow;
struct arrow newestYArrow; struct arrow newestYArrow;
#define ButtonInfoTableSize 9 #define ButtonInfoTableSize 9
struct ButtonInfo buttonInfoTable[ButtonInfoTableSize]; struct ButtonInfo buttonInfoTable[ButtonInfoTableSize];
Hat last = Hat::CENTER; Hat last = Hat::CENTER;
void perms() void perms() {
{ if(val == 0){
if (val == 0) if (rapidFireTable[index] == 1){
{ SwitchControlLibrary().PressButtonA();
if (rapidFireTable[index] == 1) }
{ if (rapidFireTable[index] == 2){
SwitchControlLibrary().PressButtonA(); SwitchControlLibrary().ReleaseButtonA();
rapidPressState = true; }
}
if (rapidFireTable[index] == 2)
{
SwitchControlLibrary().ReleaseButtonA();
rapidPressState = false;
}
} }
index = (index + 1) % RapidFireTableSize; index = (index + 1) % RapidFireTableSize;
} }
void setupButton(ButtonInfo *but, int pinNumber, Button buttonSymbol)
{ void setupButton(ButtonInfo *but, int pinNumber, Button buttonSymbol) {
but->pinNumber = pinNumber; but->pinNumber = pinNumber;
but->buttonSymbol = buttonSymbol; but->buttonSymbol = buttonSymbol;
pinMode(pinNumber, INPUT_PULLUP); pinMode(pinNumber, INPUT_PULLUP);
@@ -75,9 +64,12 @@ void setupButton(ButtonInfo *but, int pinNumber, Button buttonSymbol)
void setup() void setup()
{ {
rapidFireTable[0] = 1; rapidFireTable[0] = 1;
rapidFireTable[RapidFireTableSize / 2] = 2; rapidFireTable[RapidFireTableSize/2] = 2;
SwitchControlLibrary(); SwitchControlLibrary();
//MsTimer2::set(1, perms);
//MsTimer2::start();
setupButton(&(buttonInfoTable[0]), 3, Button::B); setupButton(&(buttonInfoTable[0]), 3, Button::B);
setupButton(&(buttonInfoTable[1]), 4, Button::X); setupButton(&(buttonInfoTable[1]), 4, Button::X);
setupButton(&(buttonInfoTable[2]), 5, Button::Y); setupButton(&(buttonInfoTable[2]), 5, Button::Y);
@@ -99,8 +91,9 @@ void setup()
arrowTable[3].pinNumber = 9; arrowTable[3].pinNumber = 9;
arrowTable[3].arrowSymbol = Hat::RIGHT; arrowTable[3].arrowSymbol = Hat::RIGHT;
for (int i = 0; i < 4; i++)
{
for (int i=0; i<4; i++){
pinMode(arrowTable[i].pinNumber, INPUT_PULLUP); pinMode(arrowTable[i].pinNumber, INPUT_PULLUP);
arrowTable[i].older = NULL; arrowTable[i].older = NULL;
arrowTable[i].newer = NULL; arrowTable[i].newer = NULL;
@@ -118,51 +111,23 @@ void setup()
newestYArrow.older = &oldestYArrow; newestYArrow.older = &oldestYArrow;
newestYArrow.newer = NULL; newestYArrow.newer = NULL;
oldestArrow.older = NULL;
oldestArrow.newer = &newestArrow;
oldestArrow.arrowSymbol = Hat::CENTER;
newestArrow.older = &oldestArrow;
newestArrow.newer = NULL;
if (digitalRead(5) == 0) // check Y button for setting GameMode
{
gameMode = 1;
}
if (digitalRead(4) == 0) // check X button for setting GameMode
{
gameMode = 2;
setupButton(&(buttonInfoTable[7]), 8, Button::L);
arrowTable[2].pinNumber = 19;
setupButton(&(buttonInfoTable[1]), 4, Button::R);
}
if(gameMode == 1){
MsTimer2::set(1, perms);
MsTimer2::start();
}
} }
void handleButtonInput(ButtonInfo *but) void handleButtonInput(ButtonInfo *but){
{ but->current = digitalRead(but->pinNumber);
but->current = digitalRead(but->pinNumber);
if (but->prev == 1 && but->current == 0) if(but->prev == 1 && but->current ==0 ){
{
SwitchControlLibrary().PressButton(but->buttonSymbol); SwitchControlLibrary().PressButton(but->buttonSymbol);
} }
else if (but->prev == 0 && but->current == 1) else if(but->prev == 0 && but->current ==1 ) {
{
SwitchControlLibrary().ReleaseButton(but->buttonSymbol); SwitchControlLibrary().ReleaseButton(but->buttonSymbol);
} }
but->prev = but->current; but->prev = but->current;
} }
void moveHat(Hat dir) void moveHat(Hat dir){
{ if(last != dir){
if (last != dir)
{
SwitchControlLibrary().MoveHat(static_cast<uint8_t>(dir)); SwitchControlLibrary().MoveHat(static_cast<uint8_t>(dir));
last = dir; last = dir;
} }
@@ -170,158 +135,81 @@ void moveHat(Hat dir)
void loop() void loop()
{ {
val = digitalRead(2);
if (gameMode == 1) if(prevVal == 1 && val == 0){
{ SwitchControlLibrary().PressButtonA();
val = digitalRead(2); index = 1;
if (prevVal == 1 && val == 0)
{
SwitchControlLibrary().PressButtonA();
rapidPressState = true;
index = 1;
}
else if (prevVal == 0 && val == 1)
{
if (rapidPressState)
{
SwitchControlLibrary().ReleaseButtonA();
}
}
prevVal = val;
for (int i = 0; i < ButtonInfoTableSize; i++)
{
handleButtonInput(&(buttonInfoTable[i]));
}
for (int i = 0; i < 4; i++)
{
arrowTable[i].current = digitalRead(arrowTable[i].pinNumber);
if (arrowTable[i].prev == 1 && arrowTable[i].current == 0)
{
// add arrow to the tail of linked list
arrowTable[i].older = newestArrow.older;
arrowTable[i].newer = &newestArrow;
newestArrow.older->newer = &(arrowTable[i]);
newestArrow.older = &(arrowTable[i]);
}
else if (arrowTable[i].prev == 0 && arrowTable[i].current == 1)
{
arrowTable[i].newer->older = arrowTable[i].older;
arrowTable[i].older->newer = arrowTable[i].newer;
arrowTable[i].newer = NULL;
arrowTable[i].older = NULL;
}
arrowTable[i].prev = arrowTable[i].current;
}
if (newestArrow.older->arrowSymbol != last)
{
last = newestArrow.older->arrowSymbol;
SwitchControlLibrary().MoveHat(static_cast<uint8_t>(newestArrow.older->arrowSymbol));
}
} }
else else if(prevVal == 0 && val == 1){
{ SwitchControlLibrary().ReleaseButtonA();
val = digitalRead(2); }
if (prevVal == 1 && val == 0) prevVal = val;
{
SwitchControlLibrary().PressButtonA();
index = 1;
}
else if (prevVal == 0 && val == 1)
{
SwitchControlLibrary().ReleaseButtonA();
}
prevVal = val;
for (int i = 0; i < ButtonInfoTableSize; i++)
{
handleButtonInput(&(buttonInfoTable[i]));
}
for (int i = 0; i < 4; i++) for(int i=0; i<ButtonInfoTableSize; i++){
{ handleButtonInput(&(buttonInfoTable[i]));
arrowTable[i].current = digitalRead(arrowTable[i].pinNumber); }
}
if (arrowTable[1].current == 0)
{ for (int i=0; i<4; i++){
if (arrowTable[3].current == 0) arrowTable[i].current = digitalRead(arrowTable[i].pinNumber);
{ }
if (arrowTable[0].current == 0)
{ if(arrowTable[1].current == 0){
moveHat(Hat::TOP); if(arrowTable[3].current == 0){
} if(arrowTable[0].current == 0){
else moveHat(Hat::TOP);
{
if (arrowTable[2].current == 0)
{
moveHat(Hat::BOTTOM);
}
else
{
moveHat(Hat::CENTER);
}
}
} }
else else{
{ if(arrowTable[2].current == 0){
if (arrowTable[0].current == 0) moveHat(Hat::BOTTOM);
{
moveHat(Hat::TOP_LEFT);
} }
else else{
{ moveHat(Hat::CENTER);
if (arrowTable[2].current == 0)
{
moveHat(Hat::BOTTOM_LEFT);
}
else
{
moveHat(Hat::LEFT);
}
} }
} }
} }
else else{
{ if(arrowTable[0].current == 0){
if (arrowTable[3].current == 0) moveHat(Hat::TOP_LEFT);
{
if (arrowTable[0].current == 0)
{
moveHat(Hat::TOP_RIGHT);
}
else
{
if (arrowTable[2].current == 0)
{
moveHat(Hat::BOTTOM_RIGHT);
}
else
{
moveHat(Hat::RIGHT);
}
}
} }
else else{
{ if(arrowTable[2].current == 0){
if (arrowTable[0].current == 0) moveHat(Hat::BOTTOM_LEFT);
{
moveHat(Hat::TOP);
} }
else else{
{ moveHat(Hat::LEFT);
if (arrowTable[2].current == 0)
{
moveHat(Hat::BOTTOM);
}
else
{
moveHat(Hat::CENTER);
}
} }
} }
} }
} }
else{
if(arrowTable[3].current == 0){
if(arrowTable[0].current == 0){
moveHat(Hat::TOP_RIGHT);
}
else{
if(arrowTable[2].current == 0){
moveHat(Hat::BOTTOM_RIGHT);
}
else{
moveHat(Hat::RIGHT);
}
}
}
else{
if(arrowTable[0].current == 0){
moveHat(Hat::TOP);
}
else{
if(arrowTable[2].current == 0){
moveHat(Hat::BOTTOM);
}
else{
moveHat(Hat::CENTER);
}
}
}
}
} }