Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java language stack overflow #2091

Closed
W6BJK opened this issue May 23, 2014 · 8 comments
Closed

java language stack overflow #2091

W6BJK opened this issue May 23, 2014 · 8 comments
Assignees
Labels
Component: Preprocessor The Arduino sketch preprocessor converts .ino files into C++ code before compilation Type: Bug
Milestone

Comments

@W6BJK
Copy link

W6BJK commented May 23, 2014

I get the message:
Exception in thread "Thread-583" java.lang.StackOverflowError
followed by a long list of other messages while trying to
compile an Arduino sketch. The problem appears to be
my attempt to define a 4 by n table.

const byte Set2a[][4] = {
  {0   ,0   ,0   ,UNUSED},        // 00 unused
.......
  {0xF7,0   ,0   ,FUNKEY}         // 83 Function key F7
}; 

Attempting to interface a PS/2 keyboard to an adduino.

@ffissore
Copy link
Contributor

Which version of the IDE are you using? 1.5.x series has a couple of fixes related to this problem. Can you share the entire sketch code?

@W6BJK
Copy link
Author

W6BJK commented May 24, 2014

I was using IDE version 1.0.5. This morning I downloaded and installed version 1.5.6-r2 and the problem still occurs.
Error message:
Exception in thread "Thread-354" java.lang.StackOverflowError
at java.util.regex.Pattern$GroupHead.match(Unknown Source)
........... (long list of similar massages)
Below is the entire sketch.
The problem appears to be the size of the table I am defining.
If I move the start of the comment block one line up (reducing the table size by one row)
the sketch compiles without error.
A table driven approach to decoding the PS/2 keyboard scan codes seemed like the
easiest and I was just starting to construct the table when the problem appeared.

/*
         Interface a PS/2 type keyboard from Parallax
*/

#include <stdio.h>
/*
         Define PS/2 keyboard input-output pins
*/
#define CLOCK 11     // keyboard clock pin
#define DATA 10      // keyboard data pin
/*
         PS/2 Keyboard Scan Codes, Set 2

         Column 1 (Set2[n][0])    Unshifted ascii char or special function index
         Column 2 (Set2[n][1])    Shifted ascii char
         Column 3 (Set2[n][2])    index for 0xE0 prefix function kays
         Column 4 (Set2[n][3])    scancode decoding type

         Notes: Function keys F1 thru F12 return values 0xF1 thru 0xFC for now. Let applications handle.
                TAB key returns a tab code (0x09) shifted or unshifted, some keyboards show a backward tab,
                    don't know how to handle that yet.  Make shifted a global boolean so applications can
                    respond as they wish to shifted TAB key.
                Split table 4 x n table inti two 2 x n tables because of stack overflow in compiler.
*/
#define UNUSED 0
#define ASCII 1                   // Keys that respond to CAPS LOCK
#define FUNKEY 2
#define CONTRL 3
#define KEYPAD 4
#define TOPROW 5                  // Keys that do not respond to CAPS LOCK
const byte Set2[][4] = {
  {0   ,0   ,0   ,UNUSED},        // 00 unused
  {0xF9,0   ,0   ,FUNKEY},        // 01 Function key F9
  {0   ,0   ,0   ,UNUSED},        // 02 unused
  {0xF5,0   ,0   ,FUNKEY},        // 03 Function key F5
  {0xF3,0   ,0   ,FUNKEY},        // 04 Function kay F3
  {0xF1,0   ,0   ,FUNKEY},        // 05 Function key F1
  {0xF2,0   ,0   ,FUNKEY},        // 06 Function key F2
  {0xFC,0   ,0   ,FUNKEY},        // 07 Function key F12
  {0   ,0   ,0   ,UNUSED},        // 08 unused
  {0xFA,0   ,0   ,FUNKEY},        // 09 Function key F10
  {0xF8,0   ,0   ,FUNKEY},        // 0A Function key F8
  {0xF6,0   ,0   ,FUNKEY},        // 0B Function key F6
  {0xF4,0   ,0   ,FUNKEY},        // 0C Function key F4
  {'\t','\t',0   ,ASCII },        // 0D Tab key
  {'`' ,'~' ,0   ,TOPROW},        // 0E apostrophe/tilde
  {0   ,0   ,0   ,UNUSED},        // 0F unused
  {0   ,0   ,0   ,UNUSED},        // 10 unused
  {1   ,0   ,0   ,CONTRL},        // 11 Left ALT key
  {2   ,0   ,0   ,CONTRL},        // 12 Left SHFT key
  {0   ,0   ,0   ,UNUSED},        // 13 unused
  {3   ,0   ,0   ,CONTRL},        // 14 Left CTRL key
  {'q' ,'Q' ,0   ,ASCII },        // 15 Letter Q
  {'1' ,'!' ,0   ,TOPROW},        // 16 Digit 1 / Exclamation mark
  {0   ,0   ,0   ,UNUSED},        // 17 unused
  {0   ,0   ,0   ,UNUSED},        // 18 unused
  {0   ,0   ,0   ,UNUSED},        // 19 unused
  {'z' ,'Z' ,0   ,ASCII },        // 1A Letter Z
  {'s' ,'S' ,0   ,ASCII },        // 1B Letter S
  {'a' ,'A' ,0   ,ASCII },        // 1C Letter A
  {'w' ,'W' ,0   ,ASCII },        // 1D Letter W
  {'2' ,'@' ,0   ,TOPROW},        // 1E Digit 2 / At symbol
  {0   ,0   ,0   ,UNUSED},        // 1F unused
  {0   ,0   ,0   ,UNUSED},        // 20 unused
  {'c' ,'C' ,0   ,ASCII },        // 21 Letter C
  {'x' ,'X' ,0   ,ASCII },        // 22 Letter X
  {'d' ,'D' ,0   ,ASCII },        // 23 Letter D
  {'e' ,'E' ,0   ,ASCII },        // 24 Letter E
  {'4' ,'$' ,0   ,TOPROW},        // 25 Digit 4 / Dollar sign
  {'3' ,'#' ,0   ,TOPROW},        // 26 Digit 3 / Tic tac toe
  {0   ,0   ,0   ,UNUSED},        // 27 unused
  {0   ,0   ,0   ,UNUSED},        // 28 unused
  {' ' ,' ' ,0   ,ASCII },        // 29 Space bar
  {'v' ,'V' ,0   ,ASCII },        // 2A Letter V
  {'f' ,'F' ,0   ,ASCII },        // 2B Letter F
  {'t' ,'T' ,0   ,ASCII },        // 2C Letter T
  {'r' ,'R' ,0   ,ASCII },        // 2D Letter R
  {'5' ,'%' ,0   ,TOPROW},        // 2E Digit 5 / Percent symbol
  {0   ,0   ,0   ,UNUSED},        // 2F unused
  {0   ,0   ,0   ,UNUSED},        // 30 unused
  {'n' ,'N' ,0   ,ASCII },        // 31 Letter N
  {'b' ,'B' ,0   ,ASCII },        // 32 Letter B
  {'h' ,'H' ,0   ,ASCII },        // 33 Letter H
  {'g' ,'G' ,0   ,ASCII },        // 34 Letter G
  {'y' ,'Y' ,0   ,ASCII },        // 35 Letter Y
  {'6' ,'^' ,0   ,TOPROW},        // 36 Digit 6 / Caret
  {0   ,0   ,0   ,UNUSED},        // 37 unused
  {0   ,0   ,0   ,UNUSED},        // 38 unused
  {0   ,0   ,0   ,UNUSED},        // 39 unused
  {'m' ,'M' ,0   ,ASCII },        // 3A Letter M
  {'j' ,'J' ,0   ,ASCII },        // 3B Letter J
  {'u' ,'U' ,0   ,ASCII },        // 3C Letter U
  {'7' ,'&' ,0   ,TOPROW},        // 3D Digit 7 / Ampersand
  {'8' ,'*' ,0   ,TOPROW},        // 3E Digit 8 / Asterisk
  {0   ,0   ,0   ,UNUSED},        // 3F unused
  {0   ,0   ,0   ,UNUSED},        // 40 unused
  {',' ,'<' ,0   ,TOPROW},        // 41 Comma / Left caret
  {'k' ,'K' ,0   ,ASCII },        // 42 Letter K
  {'i' ,'I' ,0   ,ASCII },        // 43 Letter I
  {'o' ,'O' ,0   ,ASCII },        // 44 Letter O
  {'0' ,')' ,0   ,TOPROW},        // 45 Digit zero / Right bracket
  {'9' ,'(' ,0   ,TOPROW},        // 46 Digit 9 / Left bracket
  {0   ,0   ,0   ,UNUSED},        // 47 unused
  {0   ,0   ,0   ,UNUSED},        // 48 unused
  {'.' ,'>' ,0   ,TOPROW},        // 49 Period / Right caret
  {'/' ,'\?',0   ,TOPROW},        // 4A Forward Slash / Question mark
  {'l' ,'L' ,0   ,ASCII },        // 4B Letter L
  {';' ,':' ,0   ,TOPROW},        // 4C Semicolon / Colon
  {'p' ,'P' ,0   ,ASCII },        // 4D Letter P
  {'-' ,'_' ,0   ,TOPROW},        // 4E Dash (Minus sign) / Underscore
  {0   ,0   ,0   ,UNUSED},        // 4F unused
  {0   ,0   ,0   ,UNUSED},        // 50 unused
  {0   ,0   ,0   ,UNUSED},        // 51 unused
  {'\'','\"',0   ,TOPROW},        // 52 Single quote / Double quote
/*  {0   ,0   ,0   ,UNUSED},        // 53 unused
  {'[' ,'{' ,0   ,TOPROW},        // 54 Left square Bracket / Left brace
  {'=' ,'+' ,0   ,TOPROW},        // 55 Equal sign / Plus sign
  {0   ,0   ,0   ,UNUSED},        // 56 unused
  {0   ,0   ,0   ,UNUSED},        // 57 unused
  {4   ,0   ,0   ,CONTRL},        // 58 Caps Lock
  {5   ,0   ,0   ,CONTRL},        // 59 Right SHFT key
  {'\r','\r',0   ,TOPROW},        // 5A ENTER (Return) key
  {']' ,'}' ,0   ,TOPROW},        // 5B Right square Bracket / Right brace
  {0   ,0   ,0   ,UNUSED},        // 5C unused
  {'\\',0   ,0   ,ASCII },        // 5D Back Slash
  {0   ,0   ,0   ,UNUSED},        // 5E unused
  {0   ,0   ,0   ,UNUSED},        // 5F unused
  {0   ,0   ,0   ,UNUSED},        // 60 unused
  {0   ,0   ,0   ,UNUSED},        // 61 unused
  {0   ,0   ,0   ,UNUSED},        // 62 unused
  {0   ,0   ,0   ,UNUSED},        // 63 unused
  {0   ,0   ,0   ,UNUSED},        // 64 unused
  {0   ,0   ,0   ,UNUSED},        // 65 unused
  {6   ,0   ,0   ,CONTRL},        // 66 Backspace
  {0   ,0   ,0   ,UNUSED},        // 67 unused
  {0   ,0   ,0   ,UNUSED},        // 68 unused
  {'1' ,0   ,0   ,KEYPAD},        // 69 KP Digit 1
  {0   ,0   ,0   ,UNUSED},        // 6A unused
  {'4' ,0   ,0   ,KEYPAD},        // 6B KP Digit 4
  {'7' ,0   ,0   ,KEYPAD},        // 6C KP Digit 7
  {0   ,0   ,0   ,UNUSED},        // 6D unused
  {0   ,0   ,0   ,UNUSED},        // 6E unused
  {0   ,0   ,0   ,UNUSED},        // 6F unused
  {'0' ,0   ,0   ,KEYPAD},        // 70 KP Digit Zero
  {'.' ,0   ,0   ,KEYPAD},        // 71 KP Period
  {'2' ,0   ,0   ,KEYPAD},        // 72 KP Digit 2
  {'5' ,0   ,0   ,KEYPAD},        // 73 KP Digit 5
  {'6' ,0   ,0   ,KEYPAD},        // 74 KP Digit 6
  {'8' ,0   ,0   ,KEYPAD},        // 75 KP Digit 8
  {6   ,0   ,0   ,CONTRL},        // 76 ESC key
  {7   ,0   ,0   ,CONTRL},        // 77 NUM Lock key
  {0xFB,0   ,0   ,FUNKEY},        // 78 Function key F11
  {'+' ,0   ,0   ,KEYPAD},        // 79 KP + key
  {'3' ,0   ,0   ,KEYPAD},        // 7A KP Digit 3
  {'-' ,0   ,0   ,KEYPAD},        // 7B KP Dash (Minus) key
  {'*' ,0   ,0   ,KEYPAD},        // 7C KP * key
  {'9' ,0   ,0   ,KEYPAD},        // 7D KP Digit 9
  {8   ,0   ,0   ,CONTRL},        // 7E SCROLL LOCK key
  {0   ,0   ,0   ,UNUSED},        // 7F unused
  {0   ,0   ,0   ,UNUSED},        // 80 unused
  {0   ,0   ,0   ,UNUSED},        // 81 unused
  {0   ,0   ,0   ,UNUSED},        // 82 unused
*/  {0xF7,0   ,0   ,FUNKEY}         // 83 Function key F7
}; 
int i, j;
byte parityError, framingError;
void setup() {
  Serial.begin(9600);
  pinMode(CLOCK, INPUT);
  pinMode(DATA, INPUT);
//  delay(1000);       // wait 1 second for keyboard to reset
}
void loop() {
  Serial.println(KBRead(), HEX);
}
/*
        routine to read a byte from keyboard
*/
byte KBRead(void) {
  int i;
  byte clockState, dataState;
  byte startBit, data, parity, parityBit, stopBit;
  parityError = false;
  framingError = false;
  pinMode(CLOCK, INPUT);
  pinMode(DATA, INPUT);
  do clockState = digitalRead(CLOCK);  while (clockState == HIGH); // wait for falling edge
  delayMicroseconds(5);
  startBit = digitalRead(DATA);
  if (startBit == HIGH) framingError = true;
  do clockState = digitalRead(CLOCK);  while (clockState == LOW); // wait for rising edge
  delayMicroseconds(5);
  data = 0;
  parity = 0;
  for (i = 0; i < 8; i++) {
    do clockState = digitalRead(CLOCK);  while (clockState == HIGH); // wait for falling edge
    delayMicroseconds(5);
    dataState = digitalRead(DATA);
    data = data >> 1;
    if (dataState == HIGH) {
      data = data | 0x80;
      parity = parity ^ 1;
    }
    do clockState = digitalRead(CLOCK);  while (clockState == LOW); // wait for rising edge
    delayMicroseconds(5);
  }
  do clockState = digitalRead(CLOCK);  while (clockState == HIGH); // wait for falling edge
  delayMicroseconds(5);
  parityBit = digitalRead(DATA);
  if ((parityBit == HIGH) && (parity == 1)) parityError = true;
  if ((parityBit == LOW) && (parity == 0)) parityError = true;
  do clockState = digitalRead(CLOCK);  while (clockState == LOW); // wait for rising edge
  delayMicroseconds(5);
  do clockState = digitalRead(CLOCK);  while (clockState == HIGH); // wait for falling edge
  delayMicroseconds(5);
  stopBit = digitalRead(DATA);
  if (stopBit == LOW) framingError = true;
  do clockState = digitalRead(CLOCK);  while (clockState == LOW); // wait for rising edge
  delayMicroseconds(5);
  return(data);
}

@W6BJK W6BJK closed this as completed May 24, 2014
@ffissore ffissore reopened this May 24, 2014
@ffissore
Copy link
Contributor

I know it's strange, but (with IDE 1.5.x) if you format the code (tools -> autoformat), it will successfully compile, even if you remove the comment, thus having a 131 items in the table
/cc @cmaglie

@W6BJK
Copy link
Author

W6BJK commented May 24, 2014

Wow, that's weird. That worked. Thank you for the help.

@W6BJK W6BJK closed this as completed May 24, 2014
@ffissore
Copy link
Contributor

I'll keep the issue open, since it needs to fixed anyway

@ffissore ffissore reopened this May 25, 2014
@ffissore ffissore self-assigned this Jan 28, 2015
@ffissore
Copy link
Contributor

Please give a try to the IDEs linked at the bottom of this email on the dev list
https://groups.google.com/a/arduino.cc/forum/#!msg/developers/4X2T3rCxXWM/YNJl6PZuDucJ
We're testing a new preprocessor and it compiles your sketch just fine.

@ffissore
Copy link
Contributor

New preprocessor tracked at #2636. Builds for testing it are available

@ffissore
Copy link
Contributor

Fixed by #3779

@ffissore ffissore added this to the Release 1.6.6 milestone Sep 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Preprocessor The Arduino sketch preprocessor converts .ino files into C++ code before compilation Type: Bug
Projects
None yet
Development

No branches or pull requests

2 participants