mirror of
https://github.com/option8/RetroConnector.git
synced 2024-11-26 22:50:32 +00:00
Merge branch 'master' into pr/4
Conflicts: DSK Image/BLANK-PRODOS.dsk.png DSK Image/DSK-Image.py
This commit is contained in:
commit
7a28946b26
4
.gitignore
vendored
4
.gitignore
vendored
@ -2,3 +2,7 @@
|
|||||||
*/.DS_Store
|
*/.DS_Store
|
||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
IIe-USB/arduino/.DS_Store
|
||||||
|
BIN
DSK Image/BLANK-PRODOS.dsk.png
Normal file
BIN
DSK Image/BLANK-PRODOS.dsk.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
@ -54,10 +54,17 @@ PIXELS = []
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
byte = DSK.read(1) # read a byte
|
byte = DSK.read(1) # read a byte
|
||||||
|
<<<<<<< HEAD
|
||||||
while byte != "": # while the file still has bytes in it
|
while byte != "": # while the file still has bytes in it
|
||||||
byte = DSK.read(1)
|
byte = DSK.read(1)
|
||||||
if len(byte) > 0: # the last byte, for whatever reason, is length 0. Bah.
|
if len(byte) > 0: # the last byte, for whatever reason, is length 0. Bah.
|
||||||
BYTES.append(ord(byte)) # append the number representing the byte (0-255) to the BYTES array
|
BYTES.append(ord(byte)) # append the number representing the byte (0-255) to the BYTES array
|
||||||
|
=======
|
||||||
|
while byte !="": # while the file still has bytes in it
|
||||||
|
BYTES.append(ord(byte)) # append the number representing the byte (0-255) to the BYTES array
|
||||||
|
byte = DSK.read(1)
|
||||||
|
|
||||||
|
>>>>>>> master
|
||||||
except:
|
except:
|
||||||
print("\n\nOops. Is " + INPUTFILE + " a DSK file of 143kb?\n\n")
|
print("\n\nOops. Is " + INPUTFILE + " a DSK file of 143kb?\n\n")
|
||||||
sys.exit(1) # exit on exception - file is empty, etc
|
sys.exit(1) # exit on exception - file is empty, etc
|
||||||
@ -65,11 +72,18 @@ except:
|
|||||||
|
|
||||||
print("\n Starting.\n")
|
print("\n Starting.\n")
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
for TRACK in range(0,TRACKS,1): # for each of the 35 tracks
|
for TRACK in range(0,TRACKS,1): # for each of the 35 tracks
|
||||||
LINE=[] # start a new line of pixels
|
LINE=[] # start a new line of pixels
|
||||||
for SECTOR in range(0,SECTORS*BYTESPERSECTOR,1): # write the bytes for the sectors in that track to the line array
|
for SECTOR in range(0,SECTORS*BYTESPERSECTOR,1): # write the bytes for the sectors in that track to the line array
|
||||||
offset = (SECTOR * TRACK) + SECTOR
|
offset = (SECTOR * TRACK) + SECTOR
|
||||||
LINE.append(BYTES[(SECTOR * TRACK) + SECTOR])
|
LINE.append(BYTES[(SECTOR * TRACK) + SECTOR])
|
||||||
|
=======
|
||||||
|
for TRACK in range(TRACKS): # for each of the 35 tracks
|
||||||
|
LINE=[] # start a new line of pixels
|
||||||
|
for SECTOR in range(SECTORS*BYTESPERSECTOR): # write the bytes for the sectors in that track to the line array
|
||||||
|
LINE.append(BYTES[(SECTORS*BYTESPERSECTOR * TRACK) + SECTOR])
|
||||||
|
>>>>>>> master
|
||||||
|
|
||||||
print(" Track: " + str(TRACK))
|
print(" Track: " + str(TRACK))
|
||||||
PIXELS.append(LINE) # add the array of pixels to the array of arrays
|
PIXELS.append(LINE) # add the array of pixels to the array of arrays
|
||||||
@ -93,7 +107,8 @@ OUTPUTFILE = os.path.join(INPUTFILE + ".png")
|
|||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.call(['convert', 'DiskImageTEMP.png', '-matte', '-virtual-pixel', 'transparent', '-resize', '1024x1024!', '-rotate', '90', '-distort', 'Polar', '512 110 512,512 -180,180', OUTPUTFILE])
|
subprocess.call(['convert', 'DiskImageTEMP.png', '-scale', '100%x300%', '-resize', '3072x!', '(', '-size', '3072x115', 'pattern:horizontal3', '-negate', '-alpha', 'copy', '-fx', '#000', ')', '-composite', '-virtual-pixel', 'HorizontalTile', '-flip', '+distort', 'Polar', '1024 220', '-resize', '50%x50%', OUTPUTFILE])
|
||||||
|
|
||||||
# convert the 4096x35px image to a square, rotate, then rotate around an axis.
|
# convert the 4096x35px image to a square, rotate, then rotate around an axis.
|
||||||
except OSError:
|
except OSError:
|
||||||
print("\n\nOops. This script requires ImageMagick: http://www.imagemagick.org/")
|
print("\n\nOops. This script requires ImageMagick: http://www.imagemagick.org/")
|
||||||
|
@ -14,40 +14,42 @@ Declares the matrix rows/cols of the Apple IIe keyboard.
|
|||||||
More information here:
|
More information here:
|
||||||
http://apple2.info/wiki/index.php?title=Pinouts#Apple_.2F.2Fe_Motherboard_keyboard_connector
|
http://apple2.info/wiki/index.php?title=Pinouts#Apple_.2F.2Fe_Motherboard_keyboard_connector
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Prevent compiler warning about casts from unsigned ints to chars
|
||||||
|
#define C(x) ((char) (x))
|
||||||
|
|
||||||
const byte ROWS = 10; // rows
|
const byte ROWS = 10; // rows
|
||||||
const byte COLS = 8; // columns
|
const byte COLS = 8; // columns
|
||||||
char keys[ROWS][COLS] = {
|
char keys[ROWS][COLS] = {
|
||||||
|
|
||||||
|
|
||||||
{ KEY_ESC, KEY_TAB, KEY_A, KEY_Z, KEYPAD_SLASH , 0 , KEYPAD_ASTERIX, KEY_ESC},
|
{ C(KEY_ESC), C(KEY_TAB), C(KEY_A), C(KEY_Z), C(KEYPAD_SLASH), 0, C(KEYPAD_ASTERIX), C(KEY_ESC)},
|
||||||
|
|
||||||
{ KEY_1, KEY_Q, KEY_D, KEY_X, 0, 0, 0, 0},
|
{ C(KEY_1), C(KEY_Q), C(KEY_D), C(KEY_X), 0, 0, 0, 0},
|
||||||
|
|
||||||
{ KEY_2, KEY_W, KEY_S, KEY_C, KEYPAD_0, KEYPAD_4, KEYPAD_8, 0},
|
{ C(KEY_2), C(KEY_W), C(KEY_S), C(KEY_C), C(KEYPAD_0), C(KEYPAD_4), C(KEYPAD_8), 0},
|
||||||
|
|
||||||
{ KEY_3, KEY_E, KEY_H, KEY_V, KEYPAD_1, KEYPAD_5, KEYPAD_9, KEYPAD_MINUS},
|
{ C(KEY_3), C(KEY_E), C(KEY_H), C(KEY_V), C(KEYPAD_1), C(KEYPAD_5), C(KEYPAD_9), C(KEYPAD_MINUS)},
|
||||||
|
|
||||||
{ KEY_4, KEY_R, KEY_F, KEY_B, KEYPAD_2, KEYPAD_6, KEYPAD_PERIOD, KEYPAD_ENTER},
|
{ C(KEY_4), C(KEY_R), C(KEY_F), C(KEY_B), C(KEYPAD_2), C(KEYPAD_6), C(KEYPAD_PERIOD), C(KEYPAD_ENTER)},
|
||||||
|
|
||||||
{ KEY_6, KEY_Y, KEY_G, KEY_N, KEYPAD_3, KEYPAD_7, KEYPAD_PLUS, 0},
|
{ C(KEY_6), C(KEY_Y), C(KEY_G), C(KEY_N), C(KEYPAD_3), C(KEYPAD_7), C(KEYPAD_PLUS), 0},
|
||||||
|
|
||||||
{ KEY_5, KEY_T, KEY_J, KEY_M, KEY_BACKSLASH, KEY_TILDE, KEY_ENTER, KEY_BACKSPACE},
|
{ C(KEY_5), C(KEY_T), C(KEY_J), C(KEY_M), C(KEY_BACKSLASH), C(KEY_TILDE), C(KEY_ENTER), C(KEY_BACKSPACE)},
|
||||||
|
|
||||||
{ KEY_7, KEY_U, KEY_K, KEY_COMMA, KEY_EQUAL, KEY_P, KEY_UP, KEY_DOWN },
|
{ C(KEY_7), C(KEY_U), C(KEY_K), C(KEY_COMMA), C(KEY_EQUAL), C(KEY_P), C(KEY_UP), C(KEY_DOWN) },
|
||||||
|
|
||||||
{ KEY_8, KEY_I, KEY_SEMICOLON, KEY_PERIOD, KEY_0, KEY_LEFT_BRACE, KEY_SPACE, KEY_LEFT },
|
{ C(KEY_8), C(KEY_I), C(KEY_SEMICOLON), C(KEY_PERIOD), C(KEY_0), C(KEY_LEFT_BRACE), C(KEY_SPACE), C(KEY_LEFT) },
|
||||||
|
|
||||||
{ KEY_9, KEY_O, KEY_L, KEY_SLASH, KEY_MINUS, KEY_RIGHT_BRACE, KEY_QUOTE, KEY_RIGHT },
|
{ C(KEY_9), C(KEY_O), C(KEY_L), C(KEY_SLASH), C(KEY_MINUS), C(KEY_RIGHT_BRACE), C(KEY_QUOTE), C(KEY_RIGHT) },
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
char Fkeys[2][10] = {
|
char Fkeys[2][10] = {
|
||||||
{KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_0 },
|
{C(KEY_1), C(KEY_2), C(KEY_3), C(KEY_4), C(KEY_5), C(KEY_6), C(KEY_7), C(KEY_8), C(KEY_9), C(KEY_0)},
|
||||||
{KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10 }
|
{C(KEY_F1), C(KEY_F2), C(KEY_F3), C(KEY_F4), C(KEY_F5), C(KEY_F6), C(KEY_F7), C(KEY_F8), C(KEY_F9), C(KEY_F10)}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -118,79 +120,88 @@ byte colPins[COLS] = { // X0 - X7
|
|||||||
Keypad KPD = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
|
Keypad KPD = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
|
||||||
|
|
||||||
|
|
||||||
|
// these pins are special in that they are dis/connected to ground, instead of to a row/col
|
||||||
const int SHIFTPin = 21; // the pin that the shift key is attached to
|
const int SHIFTPin = 21; // the pin that the shift key is attached to
|
||||||
const int CTRLPin = 5; // the pin that the control key is attached to
|
const int CTRLPin = 5; // the pin that the control key is attached to
|
||||||
const int APPLEPin1 = 8; // the pin that the open-apple key is attached to
|
const int APPLEPin1 = 8; // the pin that the open-apple key is attached to
|
||||||
const int APPLEPin2 = 9; // the pin that the closed-apple key is attached to
|
const int APPLEPin2 = 9; // the pin that the closed-apple key is attached to
|
||||||
// these pins are special in that they are dis/connected to ground, instead of to a row/col
|
|
||||||
const int CAPSPin = 7;
|
const int CAPSPin = 7;
|
||||||
|
|
||||||
|
#define LED 6
|
||||||
|
|
||||||
|
uint16_t modifierKeys[4];
|
||||||
|
|
||||||
|
|
||||||
char modifierKeys[4];
|
#define KEY_CAPS_UNLOCK 0
|
||||||
|
|
||||||
|
boolean resetCapsLock = false; // Allows one caps unlock signal.
|
||||||
|
unsigned long dTime = 0;
|
||||||
|
boolean CAPSLock = false; // Initialize this to a reasonable value.
|
||||||
|
|
||||||
|
boolean FKEYS = false; // used to set numbers to F-Key equivalent. currently tied to caps lock
|
||||||
|
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
#define KEY_CAPS_UNLOCK 0
|
pinMode(SHIFTPin, INPUT_PULLUP);
|
||||||
|
|
||||||
boolean resetCapsLock = false; // Allows one caps unlock signal.
|
|
||||||
unsigned long dTime = 0;
|
|
||||||
char CAPSState; // Initialize this to a reasonable value.
|
|
||||||
|
|
||||||
boolean FKEYS = false; // used to set numbers to F-Key equivalent. currently tied to caps lock
|
|
||||||
|
|
||||||
|
|
||||||
void setup(){
|
|
||||||
|
|
||||||
pinMode(SHIFTPin, INPUT);
|
|
||||||
pinMode(CTRLPin, INPUT);
|
|
||||||
pinMode(APPLEPin1, INPUT);
|
|
||||||
pinMode(APPLEPin2, INPUT);
|
|
||||||
|
|
||||||
digitalWrite(APPLEPin1, LOW);
|
|
||||||
digitalWrite(APPLEPin2, LOW);
|
|
||||||
|
|
||||||
digitalWrite(SHIFTPin, HIGH);
|
digitalWrite(SHIFTPin, HIGH);
|
||||||
|
|
||||||
|
pinMode(CTRLPin, INPUT_PULLUP);
|
||||||
digitalWrite(CTRLPin, HIGH);
|
digitalWrite(CTRLPin, HIGH);
|
||||||
|
|
||||||
pinMode(CAPSPin, INPUT);
|
pinMode(APPLEPin1, INPUT);
|
||||||
|
digitalWrite(APPLEPin1, LOW);
|
||||||
|
|
||||||
|
pinMode(APPLEPin2, INPUT);
|
||||||
|
digitalWrite(APPLEPin2, LOW);
|
||||||
|
|
||||||
|
pinMode(CAPSPin, INPUT_PULLUP);
|
||||||
digitalWrite(CAPSPin, HIGH);
|
digitalWrite(CAPSPin, HIGH);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// DEBUG
|
// DEBUG
|
||||||
|
// Serial.begin(115200);
|
||||||
|
pinMode(LED, OUTPUT);
|
||||||
|
|
||||||
//Serial.begin(115200);
|
// This gives time for the keyboard to hook up to the PC.
|
||||||
//Serial.println(CAPSState);
|
// Otherwise the caps lock state may be incorrect.
|
||||||
|
delay(1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
//probably should be on an interrupt, to catch high->low transition
|
//probably should be on an interrupt, to catch high->low transition
|
||||||
|
|
||||||
// Only do something if the pin is different from previous state.
|
// Only do something if the pin is different from previous state.
|
||||||
if ( (CAPSState!=digitalRead(CAPSPin)) && !resetCapsLock) {
|
boolean newCaps = digitalRead(CAPSPin) ? false : true;
|
||||||
CAPSState = digitalRead(CAPSPin); // Remember new CAPSState.
|
|
||||||
Keyboard.set_key6(KEY_CAPS_LOCK); // Send KEY_CAPS_LOCK.
|
if ( (CAPSLock != newCaps) && !resetCapsLock)
|
||||||
|
{
|
||||||
|
CAPSLock = newCaps; // Remember new CAPSLock.
|
||||||
|
Keyboard.set_key6((uint8_t) KEY_CAPS_LOCK); // Send KEY_CAPS_LOCK.
|
||||||
dTime = millis(); // Reset delay timer.
|
dTime = millis(); // Reset delay timer.
|
||||||
resetCapsLock = true;
|
resetCapsLock = true;
|
||||||
|
|
||||||
Serial.print("Caps = ");
|
// Serial.print("Caps = ");
|
||||||
Serial.println(CAPSState);
|
// Serial.println(CAPSLock);
|
||||||
|
|
||||||
|
// Turn on the LED for caps lock.
|
||||||
|
digitalWrite(LED, CAPSLock ? HIGH : LOW);
|
||||||
|
|
||||||
}
|
}
|
||||||
if ( resetCapsLock && (millis()-dTime) > 10) {
|
|
||||||
|
if ( resetCapsLock && (millis()-dTime) > 10)
|
||||||
|
{
|
||||||
Keyboard.set_key6(KEY_CAPS_UNLOCK);
|
Keyboard.set_key6(KEY_CAPS_UNLOCK);
|
||||||
resetCapsLock = false;
|
resetCapsLock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FKEYS = !CAPSState;
|
// If caps lock is set, then turn number keys into function keys.
|
||||||
|
FKEYS = CAPSLock;
|
||||||
|
|
||||||
|
/*char CAPSLock = digitalRead(CAPSPin);
|
||||||
/*char CAPSState = digitalRead(CAPSPin);
|
if (CAPSLock == LOW) {
|
||||||
if (CAPSState == LOW) {
|
|
||||||
Keyboard.set_key6(KEY_CAPS_LOCK);
|
Keyboard.set_key6(KEY_CAPS_LOCK);
|
||||||
} else {
|
} else {
|
||||||
Keyboard.set_key6(0);89
|
Keyboard.set_key6(0);89
|
||||||
@ -201,9 +212,7 @@ FKEYS = !CAPSState;
|
|||||||
|
|
||||||
if (SHIFTState == LOW) {
|
if (SHIFTState == LOW) {
|
||||||
modifierKeys[0] = MODIFIERKEY_SHIFT;
|
modifierKeys[0] = MODIFIERKEY_SHIFT;
|
||||||
digitalWrite(SHIFTPin, HIGH);
|
|
||||||
} else {
|
} else {
|
||||||
digitalWrite(SHIFTPin, HIGH);
|
|
||||||
modifierKeys[0] = 0;
|
modifierKeys[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,10 +220,8 @@ FKEYS = !CAPSState;
|
|||||||
|
|
||||||
if (CTRLState == LOW) {
|
if (CTRLState == LOW) {
|
||||||
modifierKeys[1] = MODIFIERKEY_CTRL;
|
modifierKeys[1] = MODIFIERKEY_CTRL;
|
||||||
digitalWrite(CTRLPin, HIGH);
|
|
||||||
} else {
|
} else {
|
||||||
modifierKeys[1] = 0;
|
modifierKeys[1] = 0;
|
||||||
digitalWrite(CTRLPin, HIGH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char OAPPLEState = digitalRead(APPLEPin1);
|
char OAPPLEState = digitalRead(APPLEPin1);
|
||||||
@ -232,28 +239,20 @@ FKEYS = !CAPSState;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// *** NOW USING CLOSED APPLE AS ALT/OPTION
|
// *** NOW USING CLOSED APPLE AS ALT/OPTION
|
||||||
if (OAPPLEState == HIGH) {
|
if (OAPPLEState == HIGH) {
|
||||||
modifierKeys[2] = MODIFIERKEY_GUI;
|
modifierKeys[2] = MODIFIERKEY_GUI;
|
||||||
digitalWrite(APPLEPin1, LOW);
|
|
||||||
} else {
|
} else {
|
||||||
modifierKeys[2] = 0;
|
modifierKeys[2] = 0;
|
||||||
digitalWrite(APPLEPin1, LOW);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CAPPLEState == HIGH) {
|
if (CAPPLEState == HIGH) {
|
||||||
modifierKeys[3] = MODIFIERKEY_ALT;
|
modifierKeys[3] = MODIFIERKEY_ALT;
|
||||||
digitalWrite(APPLEPin2, LOW);
|
|
||||||
} else {
|
} else {
|
||||||
modifierKeys[3] = 0;
|
modifierKeys[3] = 0;
|
||||||
digitalWrite(APPLEPin2, LOW);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// to use the TILDE key as ALT/OPTION
|
// to use the TILDE key as ALT/OPTION
|
||||||
/* modifierKeys[3] = 0;
|
/* modifierKeys[3] = 0;
|
||||||
if( KPD.isPressed(KEY_TILDE) ) {
|
if( KPD.isPressed(KEY_TILDE) ) {
|
||||||
@ -263,14 +262,10 @@ FKEYS = !CAPSState;
|
|||||||
|
|
||||||
// *** NOW USING CLOSED APPLE AS ALT/OPTION
|
// *** NOW USING CLOSED APPLE AS ALT/OPTION
|
||||||
|
|
||||||
Keyboard.set_modifier( modifierKeys[0] | modifierKeys[1] | modifierKeys[2] | modifierKeys[3] );
|
Keyboard.set_modifier( modifierKeys[0] | modifierKeys[1] | modifierKeys[2] | modifierKeys[3] );
|
||||||
|
|
||||||
KPD.getKeys(); // Scan for all pressed keys. 6 Max, + 4 modifiers. Should be plenty, but can be extended to 10+
|
KPD.getKeys(); // Scan for all pressed keys. 6 Max, + 4 modifiers. Should be plenty, but can be extended to 10+
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Set keyboard keys to default values.
|
// Set keyboard keys to default values.
|
||||||
Keyboard.set_key1(0);
|
Keyboard.set_key1(0);
|
||||||
Keyboard.set_key2(0);
|
Keyboard.set_key2(0);
|
||||||
@ -280,41 +275,36 @@ FKEYS = !CAPSState;
|
|||||||
//Keyboard.set_key6(0);
|
//Keyboard.set_key6(0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* based on suggestion from Craig Brooks <s.craig.brooks@gmail.com>
|
/* based on suggestion from Craig Brooks <s.craig.brooks@gmail.com>
|
||||||
uses CAPS LOCK to turn number keys into F-Key equivalent.
|
uses CAPS LOCK to turn number keys into F-Key equivalent.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Update keyboard keys to active values.
|
// Update keyboard keys to active values.
|
||||||
if( KPD.key[0].kchar && ( KPD.key[0].kstate==PRESSED || KPD.key[0].kstate==HOLD )) {
|
if ( KPD.key[0].kchar && ( KPD.key[0].kstate==PRESSED || KPD.key[0].kstate==HOLD ))
|
||||||
|
{
|
||||||
//Serial.println(FKEYS);
|
//Serial.println(FKEYS);
|
||||||
|
|
||||||
|
if (FKEYS)
|
||||||
if (FKEYS) {
|
{
|
||||||
// number keys 1 through 0 for f1 - f10
|
// number keys 1 through 0 for f1 - f10
|
||||||
if((KPD.key[0].kchar >= 0x1E) && (KPD.key[0].kchar <= 0x27)){
|
if ((KPD.key[0].kchar >= 0x1E) && (KPD.key[0].kchar <= 0x27))
|
||||||
|
{
|
||||||
KPD.key[0].kchar += 0x1C;
|
KPD.key[0].kchar += 0x1C;
|
||||||
|
// Serial.println( KPD.key[0].kchar, HEX );
|
||||||
// Serial.println( KPD.key[0].kchar, HEX );
|
}
|
||||||
|
else if ( KPD.key[0].kchar == 0x2D || KPD.key[0].kchar == 0x2E )
|
||||||
// - and = for f11 and f12
|
{
|
||||||
} else if( KPD.key[0].kchar == 0x2D || KPD.key[0].kchar == 0x2E ) {
|
// - and = for f11 and f12
|
||||||
KPD.key[0].kchar += 0x17;
|
KPD.key[0].kchar += 0x17;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Keyboard.set_key1( KPD.key[0].kchar );
|
Keyboard.set_key1( KPD.key[0].kchar );
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( KPD.key[1].kchar && ( KPD.key[1].kstate==PRESSED || KPD.key[1].kstate==HOLD ))
|
|
||||||
|
if ( KPD.key[1].kchar && ( KPD.key[1].kstate==PRESSED || KPD.key[1].kstate==HOLD ))
|
||||||
Keyboard.set_key2( KPD.key[1].kchar );
|
Keyboard.set_key2( KPD.key[1].kchar );
|
||||||
|
|
||||||
if( KPD.key[2].kchar && ( KPD.key[2].kstate==PRESSED || KPD.key[2].kstate==HOLD ))
|
if( KPD.key[2].kchar && ( KPD.key[2].kstate==PRESSED || KPD.key[2].kstate==HOLD ))
|
||||||
|
191
M0100 USB/M0100_USB_Trinket/M0100_USB_Trinket.ino
Normal file
191
M0100 USB/M0100_USB_Trinket/M0100_USB_Trinket.ino
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CANT HAVE ANYTHING HOOKED UP TO PINS 3 OR 4 AND DO USB. FFFFUUUUUU
|
||||||
|
|
||||||
|
|
||||||
|
M0100 pins:
|
||||||
|
|
||||||
|
|
||||||
|
if LPIN & RPIN are HIGH or LPIN & RPIN are LOW
|
||||||
|
|
||||||
|
if LPIN goes HIGH to LOW or LPIN goes LOW to HIGH
|
||||||
|
|
||||||
|
moving right, X++
|
||||||
|
|
||||||
|
if RPIN goes HIGH to LOW or RPIN goes LOW to HIGH
|
||||||
|
|
||||||
|
moving left, X--
|
||||||
|
|
||||||
|
/
|
||||||
|
/
|
||||||
|
|
||||||
|
Mouse.move(X, Y), where X and Y range from -127 to +127. Positive X moves to the right. Positive Y moves downwards.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// mouse is essentially two rotary encoders. one for L/R one for U/D
|
||||||
|
|
||||||
|
int LPIN = 0;
|
||||||
|
int RPIN = 4;
|
||||||
|
int led = 1; // blink 'digital' pin 1 - AKA the built in red LED
|
||||||
|
|
||||||
|
static uint8_t X_prev_pos = 0;
|
||||||
|
static uint8_t X_flags = 0;
|
||||||
|
|
||||||
|
|
||||||
|
int DPIN = 2;
|
||||||
|
int UPIN = 3;
|
||||||
|
|
||||||
|
static uint8_t Y_prev_pos = 0;
|
||||||
|
static uint8_t Y_flags = 0;
|
||||||
|
|
||||||
|
// using comparison to previous read to check direction instead of interrupts.
|
||||||
|
|
||||||
|
volatile int DeltaX = 0;
|
||||||
|
volatile int DeltaY = 0;
|
||||||
|
|
||||||
|
int MouseButtonPin = 1;
|
||||||
|
|
||||||
|
boolean MouseButton = 0;
|
||||||
|
|
||||||
|
int MouseCalibration = 4; // how fast does the movement translate (3 - 6 seems okay, 10 is too fast)
|
||||||
|
|
||||||
|
#include <TrinketMouse.h>
|
||||||
|
//#include <Bounce.h>
|
||||||
|
|
||||||
|
//Bounce button4 = Bounce(4, 10);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
pinMode(MouseButtonPin, INPUT_PULLUP);
|
||||||
|
pinMode(led, OUTPUT);
|
||||||
|
|
||||||
|
pinMode(LPIN, INPUT);
|
||||||
|
// pinMode(RPIN, INPUT);
|
||||||
|
// pinMode(UPIN, INPUT);
|
||||||
|
// pinMode(DPIN, INPUT);
|
||||||
|
|
||||||
|
digitalWrite(LPIN, HIGH);
|
||||||
|
// digitalWrite(RPIN, HIGH);
|
||||||
|
// digitalWrite(UPIN, HIGH);
|
||||||
|
// digitalWrite(DPIN, HIGH);
|
||||||
|
|
||||||
|
|
||||||
|
TrinketMouse.begin();
|
||||||
|
|
||||||
|
// get an initial reading on the encoder pins
|
||||||
|
/* if (digitalRead(LPIN) == LOW) {
|
||||||
|
X_prev_pos |= (1 << 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (digitalRead(RPIN) == LOW) {
|
||||||
|
X_prev_pos |= (1 << 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (digitalRead(UPIN) == LOW) {
|
||||||
|
Y_prev_pos |= (1 << 0);
|
||||||
|
}
|
||||||
|
if (digitalRead(DPIN) == LOW) {
|
||||||
|
Y_prev_pos |= (1 << 1);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
int8_t X_action = 0; // 1 or -1 if moved, sign is direction
|
||||||
|
|
||||||
|
uint8_t X_cur_pos = 0;
|
||||||
|
// read in the encoder state first
|
||||||
|
|
||||||
|
|
||||||
|
if ( digitalRead(LPIN) ) {
|
||||||
|
X_cur_pos |= (1 << 0);
|
||||||
|
}
|
||||||
|
if ( digitalRead(RPIN) ) {
|
||||||
|
X_cur_pos |= (1 << 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if any rotation at all
|
||||||
|
if (X_cur_pos != X_prev_pos)
|
||||||
|
{
|
||||||
|
if (X_prev_pos == 0x00)
|
||||||
|
{
|
||||||
|
// this is the first edge
|
||||||
|
if (X_cur_pos == 0x01) {
|
||||||
|
X_flags |= (1 << 0);
|
||||||
|
}
|
||||||
|
else if (X_cur_pos == 0x02) {
|
||||||
|
X_flags |= (1 << 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (X_cur_pos == 0x03)
|
||||||
|
{
|
||||||
|
// this is when the Xoder is in the middle of a "step"
|
||||||
|
X_flags |= (1 << 4);
|
||||||
|
}
|
||||||
|
else if (X_cur_pos == 0x00)
|
||||||
|
{
|
||||||
|
// this is the final edge
|
||||||
|
if (X_prev_pos == 0x02) {
|
||||||
|
X_flags |= (1 << 2);
|
||||||
|
}
|
||||||
|
else if (X_prev_pos == 0x01) {
|
||||||
|
X_flags |= (1 << 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
// check the first and last edge
|
||||||
|
// or maybe one edge is missing, if missing then require the middle state
|
||||||
|
// this will reject bounces and false movements
|
||||||
|
if (bit_is_set(X_flags, 0) && (bit_is_set(X_flags, 2) || bit_is_set(X_flags, 4))) {
|
||||||
|
X_action = 1;
|
||||||
|
}
|
||||||
|
else if (bit_is_set(X_flags, 2) && (bit_is_set(X_flags, 0) || bit_is_set(X_flags, 4))) {
|
||||||
|
X_action = 1;
|
||||||
|
}
|
||||||
|
else if (bit_is_set(X_flags, 1) && (bit_is_set(X_flags, 3) || bit_is_set(X_flags, 4))) {
|
||||||
|
X_action = -1;
|
||||||
|
}
|
||||||
|
else if (bit_is_set(X_flags, 3) && (bit_is_set(X_flags, 1) || bit_is_set(X_flags, 4))) {
|
||||||
|
X_action = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
X_flags = 0; // reset for next time
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
X_prev_pos = X_cur_pos;
|
||||||
|
|
||||||
|
|
||||||
|
DeltaX = X_action;
|
||||||
|
|
||||||
|
|
||||||
|
// now do Y...
|
||||||
|
|
||||||
|
|
||||||
|
if( (DeltaX != 0) || (DeltaY != 0) ) {
|
||||||
|
TrinketMouse.move(DeltaX * MouseCalibration, DeltaY * MouseCalibration, 0, MouseButton);
|
||||||
|
DeltaX = 0;
|
||||||
|
DeltaY = 0;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
digitalWrite(led, digitalRead(LPIN));
|
||||||
|
TrinketMouse.move(1,0,0,0);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
BIN
M0110 to USB/M0110 adapter.fzz
Normal file
BIN
M0110 to USB/M0110 adapter.fzz
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user