You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/07/28 13:54:34 UTC

[GitHub] [incubator-nuttx-apps] acassis opened a new pull request, #1238: apps/games: Add shift game

acassis opened a new pull request, #1238:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1238

   ## Summary
   Add shift game
   ## Impact
   Users could use this game with any board with LCD framebuffer
   ## Testing
   https://www.youtube.com/shorts/dsUN4EQ0_JI
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] acassis commented on a diff in pull request #1238: apps/games: Add shift game

Posted by GitBox <gi...@apache.org>.
acassis commented on code in PR #1238:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1238#discussion_r933491474


##########
games/shift/shift_input_console.h:
##########
@@ -0,0 +1,133 @@
+/****************************************************************************
+ * apps/games/shift/shift_input_console.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <termios.h>
+
+#include "shift_inputs.h"
+
+/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+/* Termios functions to have getch on Linux/NuttX */
+
+static struct termios g_old;
+static struct termios g_new;
+
+/* Initialize g_new terminal I/O settings */
+
+void init_termios(int echo)
+{
+  tcgetattr(0, &g_old);                 /* grab old terminal i/o settings */
+  g_new = g_old;                        /* use old settings as starting */
+  g_new.c_lflag &= ~ICANON;             /* disable buffered I/O */
+  g_new.c_lflag &= ~ECHO;               /* disable ECHO bit */
+  g_new.c_lflag |= echo ? ECHO : 0;     /* set echo mode if requested */
+  tcsetattr(0, TCSANOW, &g_new);        /* apply terminal I/O settings */
+}
+
+/* Restore g_old terminal i/o settings */
+
+void reset_termios(void)
+{
+  tcsetattr(0, TCSANOW, &g_old);
+}
+
+/* Read 1 character - echo defines echo mode */
+
+char getch_(int echo)
+{
+  char ch;
+
+  init_termios(echo);
+  ch = getchar();
+  reset_termios();
+
+  return ch;
+}
+
+/* Read 1 character without echo getch() function definition. */
+
+char getch(void)
+{
+  return getch_(0);
+}
+
+/****************************************************************************
+ * dev_input_init
+ ****************************************************************************/
+
+int dev_input_init(FAR struct input_state_s *dev)
+{
+  init_termios(0);
+
+  return OK;
+}
+
+/****************************************************************************
+ * dev_read_input
+ ****************************************************************************/
+
+int dev_read_input(FAR struct input_state_s *dev)
+{
+  char ch;
+
+  /* Arrows keys return three bytes: 27 91 [65-68] */
+
+  if ((ch = getch()) == 27)
+    {
+      if ((ch = getch()) == 91)
+        {
+          ch = getch();
+          if (ch == 65)
+            {
+              dev->dir = DIR_UP;
+            }
+          else if (ch == 66)
+                {
+                   dev->dir = DIR_DOWN;
+                }
+               else if (ch == 67)
+                      {
+                        dev->dir = DIR_RIGHT;
+                      }
+                    else if (ch == 68)
+                          {
+                             dev->dir = DIR_LEFT;
+                          }

Review Comment:
   @pkarashchenko when I put the braces just below the space below the space between "if" and "(" the automatic test fails because it is not in an odd column. What do you suggest? Just keep the braces below letter "f" and move "dev->dir" one position to left?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] acassis commented on a diff in pull request #1238: apps/games: Add shift game

Posted by GitBox <gi...@apache.org>.
acassis commented on code in PR #1238:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1238#discussion_r933501939


##########
games/shift/shift_input_console.h:
##########
@@ -0,0 +1,133 @@
+/****************************************************************************
+ * apps/games/shift/shift_input_console.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <termios.h>
+
+#include "shift_inputs.h"
+
+/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+/* Termios functions to have getch on Linux/NuttX */
+
+static struct termios g_old;
+static struct termios g_new;
+
+/* Initialize g_new terminal I/O settings */
+
+void init_termios(int echo)
+{
+  tcgetattr(0, &g_old);                 /* grab old terminal i/o settings */
+  g_new = g_old;                        /* use old settings as starting */
+  g_new.c_lflag &= ~ICANON;             /* disable buffered I/O */
+  g_new.c_lflag &= ~ECHO;               /* disable ECHO bit */
+  g_new.c_lflag |= echo ? ECHO : 0;     /* set echo mode if requested */
+  tcsetattr(0, TCSANOW, &g_new);        /* apply terminal I/O settings */
+}
+
+/* Restore g_old terminal i/o settings */
+
+void reset_termios(void)
+{
+  tcsetattr(0, TCSANOW, &g_old);
+}
+
+/* Read 1 character - echo defines echo mode */
+
+char getch_(int echo)
+{
+  char ch;
+
+  init_termios(echo);
+  ch = getchar();
+  reset_termios();
+
+  return ch;
+}
+
+/* Read 1 character without echo getch() function definition. */
+
+char getch(void)
+{
+  return getch_(0);
+}
+
+/****************************************************************************
+ * dev_input_init
+ ****************************************************************************/
+
+int dev_input_init(FAR struct input_state_s *dev)
+{
+  init_termios(0);
+
+  return OK;
+}
+
+/****************************************************************************
+ * dev_read_input
+ ****************************************************************************/
+
+int dev_read_input(FAR struct input_state_s *dev)
+{
+  char ch;
+
+  /* Arrows keys return three bytes: 27 91 [65-68] */
+
+  if ((ch = getch()) == 27)
+    {
+      if ((ch = getch()) == 91)
+        {
+          ch = getch();
+          if (ch == 65)
+            {
+              dev->dir = DIR_UP;
+            }
+          else if (ch == 66)
+                {
+                   dev->dir = DIR_DOWN;
+                }
+               else if (ch == 67)
+                      {
+                        dev->dir = DIR_RIGHT;
+                      }
+                    else if (ch == 68)
+                          {
+                             dev->dir = DIR_LEFT;
+                          }

Review Comment:
   Ok, I found a good example at apps/examples/audio_rttl/audio_rttl.cxx



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] pkarashchenko commented on a diff in pull request #1238: apps/games: Add shift game

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #1238:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1238#discussion_r933434382


##########
games/shift/shift_input_console.h:
##########
@@ -0,0 +1,133 @@
+/****************************************************************************
+ * apps/games/shift/shift_input_console.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <termios.h>
+
+#include "shift_inputs.h"
+
+/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+/* Termios functions to have getch on Linux/NuttX */
+
+static struct termios g_old;
+static struct termios g_new;
+
+/* Initialize g_new terminal I/O settings */
+
+void init_termios(int echo)
+{
+  tcgetattr(0, &g_old);                 /* grab old terminal i/o settings */
+  g_new = g_old;                        /* use old settings as starting */
+  g_new.c_lflag &= ~ICANON;             /* disable buffered I/O */
+  g_new.c_lflag &= ~ECHO;               /* disable ECHO bit */
+  g_new.c_lflag |= echo ? ECHO : 0;     /* set echo mode if requested */
+  tcsetattr(0, TCSANOW, &g_new);        /* apply terminal I/O settings */
+}
+
+/* Restore g_old terminal i/o settings */
+
+void reset_termios(void)
+{
+  tcsetattr(0, TCSANOW, &g_old);
+}
+
+/* Read 1 character - echo defines echo mode */
+
+char getch_(int echo)
+{
+  char ch;
+
+  init_termios(echo);
+  ch = getchar();
+  reset_termios();
+
+  return ch;
+}
+
+/* Read 1 character without echo getch() function definition. */
+
+char getch(void)
+{
+  return getch_(0);
+}
+
+/****************************************************************************
+ * dev_input_init
+ ****************************************************************************/
+
+int dev_input_init(FAR struct input_state_s *dev)
+{
+  init_termios(0);
+
+  return OK;
+}
+
+/****************************************************************************
+ * dev_read_input
+ ****************************************************************************/
+
+int dev_read_input(FAR struct input_state_s *dev)
+{
+  char ch;
+
+  /* Arrows keys return three bytes: 27 91 [65-68] */
+
+  if ((ch = getch()) == 27)
+    {
+      if ((ch = getch()) == 91)
+        {
+          ch = getch();
+          if (ch == 65)
+            {
+              dev->dir = DIR_UP;
+            }
+          else if (ch == 66)
+                {
+                   dev->dir = DIR_DOWN;
+                }
+               else if (ch == 67)
+                      {
+                        dev->dir = DIR_RIGHT;
+                      }
+                    else if (ch == 68)
+                          {
+                             dev->dir = DIR_LEFT;
+                          }

Review Comment:
   please fix formatting here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] acassis commented on a diff in pull request #1238: apps/games: Add shift game

Posted by GitBox <gi...@apache.org>.
acassis commented on code in PR #1238:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1238#discussion_r933192461


##########
games/shift/shift_input_console.h:
##########
@@ -0,0 +1,133 @@
+/****************************************************************************
+ * apps/games/shift/shift_input_console.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <termios.h>
+
+#include "shift_inputs.h"
+
+/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+/* Termios functions to have getch on Linux/NuttX */
+
+static struct termios g_old;
+static struct termios g_new;
+
+/* Initialize g_new terminal I/O settings */
+
+void init_termios(int echo)
+{
+  tcgetattr(0, &g_old);                 /* grab old terminal i/o settings */
+  g_new = g_old;                        /* use old settings as starting */
+  g_new.c_lflag &= ~ICANON;             /* disable buffered I/O */
+  g_new.c_lflag &= echo ? ECHO : ~ECHO; /* set echo mode */

Review Comment:
   you are right, it only works to disable the echo, it needs to be broken in two parts:
   ```
   g_new.c_lflag &= ~ECHO; /* clear ECHO bit */
   g_new.c_lflag |= echo ? ECHO : 0;  /* enable echo if requested */
   ```



##########
games/shift/shift_input_console.h:
##########
@@ -0,0 +1,133 @@
+/****************************************************************************
+ * apps/games/shift/shift_input_console.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <termios.h>
+
+#include "shift_inputs.h"
+
+/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+/* Termios functions to have getch on Linux/NuttX */
+
+static struct termios g_old;
+static struct termios g_new;
+
+/* Initialize g_new terminal I/O settings */
+
+void init_termios(int echo)
+{
+  tcgetattr(0, &g_old);                 /* grab old terminal i/o settings */
+  g_new = g_old;                        /* use old settings as starting */
+  g_new.c_lflag &= ~ICANON;             /* disable buffered I/O */
+  g_new.c_lflag &= echo ? ECHO : ~ECHO; /* set echo mode */
+  tcsetattr(0, TCSANOW, &g_new);        /* apply terminal I/O settings */
+}
+
+/* Restore g_old terminal i/o settings */
+
+void reset_termios(void)
+{
+  tcsetattr(0, TCSANOW, &g_old);
+}
+
+/* Read 1 character - echo defines echo mode */
+
+char getch_(int echo)
+{
+    char ch;
+    init_termios(echo);
+    ch = getchar();
+    reset_termios();
+    return ch;

Review Comment:
   Thanks



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] acassis commented on a diff in pull request #1238: apps/games: Add shift game

Posted by GitBox <gi...@apache.org>.
acassis commented on code in PR #1238:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1238#discussion_r933491474


##########
games/shift/shift_input_console.h:
##########
@@ -0,0 +1,133 @@
+/****************************************************************************
+ * apps/games/shift/shift_input_console.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <termios.h>
+
+#include "shift_inputs.h"
+
+/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+/* Termios functions to have getch on Linux/NuttX */
+
+static struct termios g_old;
+static struct termios g_new;
+
+/* Initialize g_new terminal I/O settings */
+
+void init_termios(int echo)
+{
+  tcgetattr(0, &g_old);                 /* grab old terminal i/o settings */
+  g_new = g_old;                        /* use old settings as starting */
+  g_new.c_lflag &= ~ICANON;             /* disable buffered I/O */
+  g_new.c_lflag &= ~ECHO;               /* disable ECHO bit */
+  g_new.c_lflag |= echo ? ECHO : 0;     /* set echo mode if requested */
+  tcsetattr(0, TCSANOW, &g_new);        /* apply terminal I/O settings */
+}
+
+/* Restore g_old terminal i/o settings */
+
+void reset_termios(void)
+{
+  tcsetattr(0, TCSANOW, &g_old);
+}
+
+/* Read 1 character - echo defines echo mode */
+
+char getch_(int echo)
+{
+  char ch;
+
+  init_termios(echo);
+  ch = getchar();
+  reset_termios();
+
+  return ch;
+}
+
+/* Read 1 character without echo getch() function definition. */
+
+char getch(void)
+{
+  return getch_(0);
+}
+
+/****************************************************************************
+ * dev_input_init
+ ****************************************************************************/
+
+int dev_input_init(FAR struct input_state_s *dev)
+{
+  init_termios(0);
+
+  return OK;
+}
+
+/****************************************************************************
+ * dev_read_input
+ ****************************************************************************/
+
+int dev_read_input(FAR struct input_state_s *dev)
+{
+  char ch;
+
+  /* Arrows keys return three bytes: 27 91 [65-68] */
+
+  if ((ch = getch()) == 27)
+    {
+      if ((ch = getch()) == 91)
+        {
+          ch = getch();
+          if (ch == 65)
+            {
+              dev->dir = DIR_UP;
+            }
+          else if (ch == 66)
+                {
+                   dev->dir = DIR_DOWN;
+                }
+               else if (ch == 67)
+                      {
+                        dev->dir = DIR_RIGHT;
+                      }
+                    else if (ch == 68)
+                          {
+                             dev->dir = DIR_LEFT;
+                          }

Review Comment:
   @pkarashchenko when I put the braces just below the space below between "if" and "(" the automatic test fails because it is not in an odd column. What do you suggest? Just keep the braces below letter "f" and move "dev->dir" one position to left?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] acassis commented on a diff in pull request #1238: apps/games: Add shift game

Posted by GitBox <gi...@apache.org>.
acassis commented on code in PR #1238:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1238#discussion_r933193591


##########
games/shift/shift_input_console.h:
##########
@@ -0,0 +1,133 @@
+/****************************************************************************
+ * apps/games/shift/shift_input_console.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <termios.h>
+
+#include "shift_inputs.h"
+
+/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+/* Termios functions to have getch on Linux/NuttX */
+
+static struct termios g_old;
+static struct termios g_new;
+
+/* Initialize g_new terminal I/O settings */
+
+void init_termios(int echo)
+{
+  tcgetattr(0, &g_old);                 /* grab old terminal i/o settings */
+  g_new = g_old;                        /* use old settings as starting */
+  g_new.c_lflag &= ~ICANON;             /* disable buffered I/O */
+  g_new.c_lflag &= echo ? ECHO : ~ECHO; /* set echo mode */
+  tcsetattr(0, TCSANOW, &g_new);        /* apply terminal I/O settings */
+}
+
+/* Restore g_old terminal i/o settings */
+
+void reset_termios(void)

Review Comment:
   I want to avoid creating many .c and .h files. So it I prefer to keep it only in these .h files



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] pkarashchenko merged pull request #1238: apps/games: Add shift game

Posted by GitBox <gi...@apache.org>.
pkarashchenko merged PR #1238:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1238


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] pkarashchenko commented on a diff in pull request #1238: apps/games: Add shift game

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #1238:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1238#discussion_r932504505


##########
games/shift/shift_input_console.h:
##########
@@ -0,0 +1,133 @@
+/****************************************************************************
+ * apps/games/shift/shift_input_console.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <termios.h>
+
+#include "shift_inputs.h"
+
+/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+/* Termios functions to have getch on Linux/NuttX */
+
+static struct termios g_old;
+static struct termios g_new;
+
+/* Initialize g_new terminal I/O settings */
+
+void init_termios(int echo)
+{
+  tcgetattr(0, &g_old);                 /* grab old terminal i/o settings */
+  g_new = g_old;                        /* use old settings as starting */
+  g_new.c_lflag &= ~ICANON;             /* disable buffered I/O */
+  g_new.c_lflag &= echo ? ECHO : ~ECHO; /* set echo mode */

Review Comment:
   is this correct? usually set/unset are done like
   ```
   if (set)
     {
       a |= BIT;
     }
   else
     {
       a &= ~BIT;
     }
   ```



##########
games/shift/shift_input_console.h:
##########
@@ -0,0 +1,133 @@
+/****************************************************************************
+ * apps/games/shift/shift_input_console.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <termios.h>
+
+#include "shift_inputs.h"
+
+/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+/* Termios functions to have getch on Linux/NuttX */
+
+static struct termios g_old;
+static struct termios g_new;
+
+/* Initialize g_new terminal I/O settings */
+
+void init_termios(int echo)
+{
+  tcgetattr(0, &g_old);                 /* grab old terminal i/o settings */
+  g_new = g_old;                        /* use old settings as starting */
+  g_new.c_lflag &= ~ICANON;             /* disable buffered I/O */
+  g_new.c_lflag &= echo ? ECHO : ~ECHO; /* set echo mode */
+  tcsetattr(0, TCSANOW, &g_new);        /* apply terminal I/O settings */
+}
+
+/* Restore g_old terminal i/o settings */
+
+void reset_termios(void)

Review Comment:
   why all this API implementation is in header file and not in C-file?



##########
games/shift/shift_input_console.h:
##########
@@ -0,0 +1,133 @@
+/****************************************************************************
+ * apps/games/shift/shift_input_console.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <termios.h>
+
+#include "shift_inputs.h"
+
+/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+/* Termios functions to have getch on Linux/NuttX */
+
+static struct termios g_old;
+static struct termios g_new;
+
+/* Initialize g_new terminal I/O settings */
+
+void init_termios(int echo)
+{
+  tcgetattr(0, &g_old);                 /* grab old terminal i/o settings */
+  g_new = g_old;                        /* use old settings as starting */
+  g_new.c_lflag &= ~ICANON;             /* disable buffered I/O */
+  g_new.c_lflag &= echo ? ECHO : ~ECHO; /* set echo mode */
+  tcsetattr(0, TCSANOW, &g_new);        /* apply terminal I/O settings */
+}
+
+/* Restore g_old terminal i/o settings */
+
+void reset_termios(void)
+{
+  tcsetattr(0, TCSANOW, &g_old);
+}
+
+/* Read 1 character - echo defines echo mode */
+
+char getch_(int echo)
+{
+    char ch;
+    init_termios(echo);
+    ch = getchar();
+    reset_termios();
+    return ch;

Review Comment:
   2 spaces



##########
games/shift/shift_main.c:
##########
@@ -0,0 +1,927 @@
+/****************************************************************************
+ * apps/games/shift/shift_main.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <math.h>
+
+#include <nuttx/video/fb.h>
+#include <nuttx/video/rgbcolors.h>
+
+#ifdef CONFIG_GAMES_SHIFT_USE_CONSOLEKEY
+#include "shift_input_console.h"
+#endif
+
+#ifdef CONFIG_GAMES_SHIFT_USE_DJOYSTICK
+#include "shift_input_joystick.h"
+#endif
+
+#ifdef CONFIG_GAMES_SHIFT_USE_GESTURE
+#include "shift_input_gesture.h"
+#endif
+
+/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+#define BOARDX_SIZE 6
+#define BOARDY_SIZE 6
+
+#define ROW         8
+#define COL         8
+
+/* Difficult mode:  4, 5, 6 */
+
+#define GAMEMODE    6
+
+#define NCOLORS     GAMEMODE
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct screen_state_s
+{
+  int fd_fb;
+  struct fb_videoinfo_s vinfo;
+  struct fb_planeinfo_s pinfo;
+#ifdef CONFIG_FB_OVERLAY
+  struct fb_overlayinfo_s oinfo;
+#endif
+  FAR void *fbmem;
+};
+
+struct game_screen_s
+{
+  int xres;     /* X display resolution */
+  int yres;     /* Y display resolution */
+  int xoff;     /* X offset to start drawing */
+  int yoff;     /* Y offset to start drawing */
+  int ncolors;  /* Supported number of colors */
+  int blklen;   /* Size of side of the blocks */
+  int steps;    /* Steps to slide a block for a now position */
+  int stepinc;  /* Step increment during the sliding */
+  int dir;      /* Direction to move the blocks */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const char g_default_fbdev[] = "/dev/fb0";
+
+/* The edge of the board is invisible to user */
+
+int board[ROW][COL] =
+                            {
+                              {1, 1, 1, 1, 1, 1, 1, 1},
+                              {1, 0, 0, 0, 0, 0, 0, 1},
+                              {1, 0, 0, 0, 0, 0, 0, 1},
+                              {1, 0, 0, 0, 0, 0, 0, 1},
+                              {1, 0, 0, 0, 0, 0, 0, 1},
+                              {1, 0, 0, 0, 0, 0, 0, 1},
+                              {1, 0, 0, 0, 0, 0, 0, 1},
+                              {1, 1, 1, 1, 1, 1, 1, 1}
+                            };

Review Comment:
   please remove extra spaces



##########
games/shift/shift_input_joystick.h:
##########
@@ -0,0 +1,166 @@
+/****************************************************************************
+ * apps/games/shift/shift_input_joystick.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <nuttx/input/djoystick.h>
+
+#include "shift_inputs.h"
+
+/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+#define DJOYSTICK_DEVNAME "/dev/djoy0"
+#define DJOYSTICK_SIGNO 13
+
+/* The set of supported joystick discretes */
+
+static djoy_buttonset_t g_djoysupported;
+
+/* Last sampled discrete set */
+
+static djoy_buttonset_t g_djoylast;
+
+struct djoy_notify_s notify;
+
+/****************************************************************************
+ * dev_input_init
+ ****************************************************************************/
+
+int dev_input_init(FAR struct input_state_s *dev)
+{
+  int tmp;
+  int ret;
+
+  /* Open the djoystick device */
+
+  dev->fd_joy = open(DJOYSTICK_DEVNAME, O_RDONLY);
+  if (dev->fd_joy < 0)
+    {
+      fprintf(stderr, "ERROR: Failed to open %s: %d\n",
+              DJOYSTICK_DEVNAME, errno);
+      return -ENODEV;
+    }
+
+  /* Get the set of supported discretes */
+
+  ret = ioctl(dev->fd_joy, DJOYIOC_SUPPORTED,
+              (unsigned long)((uintptr_t)&tmp));
+  if (ret < 0)
+    {
+      fprintf(stderr, "ERROR: ioctl(DJOYIOC_SUPPORTED) failed: %d\n", errno);
+      goto errout_with_fd;
+    }
+
+  g_djoysupported = (djoy_buttonset_t)tmp;
+
+  /* Register to receive a signal on any change in the joystick discretes. */
+
+  notify.dn_press   = g_djoysupported;
+  notify.dn_release = g_djoysupported;
+
+  notify.dn_event.sigev_notify = SIGEV_SIGNAL;
+  notify.dn_event.sigev_signo  = DJOYSTICK_SIGNO;
+
+  ret = ioctl(dev->fd_joy, DJOYIOC_REGISTER,
+              (unsigned long)((uintptr_t)&notify));
+  if (ret < 0)
+    {
+      fprintf(stderr, "ERROR: ioctl(DJOYIOC_REGISTER) failed: %d\n", errno);
+      goto errout_with_fd;
+    }
+
+  /* Ignore the default signal action */
+
+  signal(DJOYSTICK_SIGNO, SIG_IGN);
+
+  return OK;
+
+errout_with_fd:
+  close(dev->fd_joy);
+  return -ENODEV;
+}
+
+/****************************************************************************
+ * dev_read_input
+ ****************************************************************************/
+
+int dev_read_input(FAR struct input_state_s *dev)
+{
+  struct siginfo value;
+  sigset_t set;
+  djoy_buttonset_t newset;
+  ssize_t nread;
+  int ret;
+
+  /* Wait for a signal */
+
+  sigemptyset(&set);
+  sigaddset(&set, DJOYSTICK_SIGNO);
+  ret = sigwaitinfo(&set, &value);
+  if (ret < 0)
+    {
+      fprintf(stderr, "ERROR: sigwaitinfo() failed: %d\n", errno);
+    }
+
+  newset = (djoy_buttonset_t)value.si_value.sival_int;
+
+  g_djoylast = newset;
+
+  /* Read the signal set and compare */
+
+  nread = read(dev->fd_joy, &newset, sizeof(djoy_buttonset_t));
+  if (nread < 0)
+    {
+      fprintf(stderr, "ERROR: read() failed: %d\n", errno);
+    }
+  else if (nread != sizeof(djoy_buttonset_t))
+    {
+      fprintf(stderr, "ERROR: read() unexpected size: %ld vs %d\n",
+              (long)nread, sizeof(djoy_buttonset_t));
+    }
+
+  g_djoylast = newset;
+
+  switch (newset)
+    {
+      case DJOY_UP_BIT:
+          dev->dir = DIR_UP;
+          break;

Review Comment:
   remove 2 spaces here and other case items



##########
games/shift/shift_input_console.h:
##########
@@ -0,0 +1,133 @@
+/****************************************************************************
+ * apps/games/shift/shift_input_console.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <termios.h>
+
+#include "shift_inputs.h"
+
+/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+/* Termios functions to have getch on Linux/NuttX */
+
+static struct termios g_old;
+static struct termios g_new;
+
+/* Initialize g_new terminal I/O settings */
+
+void init_termios(int echo)
+{
+  tcgetattr(0, &g_old);                 /* grab old terminal i/o settings */
+  g_new = g_old;                        /* use old settings as starting */
+  g_new.c_lflag &= ~ICANON;             /* disable buffered I/O */
+  g_new.c_lflag &= echo ? ECHO : ~ECHO; /* set echo mode */
+  tcsetattr(0, TCSANOW, &g_new);        /* apply terminal I/O settings */
+}
+
+/* Restore g_old terminal i/o settings */
+
+void reset_termios(void)
+{
+  tcsetattr(0, TCSANOW, &g_old);
+}
+
+/* Read 1 character - echo defines echo mode */
+
+char getch_(int echo)
+{
+    char ch;
+    init_termios(echo);
+    ch = getchar();
+    reset_termios();
+    return ch;
+}
+
+/* Read 1 character without echo getch() function definition. */
+
+char getch(void)
+{
+  return getch_(0);
+}
+
+/****************************************************************************
+ * dev_input_init
+ ****************************************************************************/
+
+int dev_input_init(FAR struct input_state_s *dev)
+{
+  init_termios(0);
+
+  return OK;
+}
+
+/****************************************************************************
+ * dev_read_input
+ ****************************************************************************/
+
+int dev_read_input(FAR struct input_state_s *dev)
+{
+  char ch;
+
+  /* Arrows keys return three bytes: 27 91 [65-68] */
+
+  if ((ch = getch()) == 27)
+    {
+      if ((ch = getch()) == 91)
+        {
+          ch = getch();
+          if (ch == 65)
+            {
+              dev->dir = DIR_UP;
+            }
+          else
+          if (ch == 66)

Review Comment:
   ```suggestion
             else if (ch == 66)
   ```
   here and other places



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] acassis commented on a diff in pull request #1238: apps/games: Add shift game

Posted by GitBox <gi...@apache.org>.
acassis commented on code in PR #1238:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1238#discussion_r933194184


##########
games/shift/shift_input_console.h:
##########
@@ -0,0 +1,133 @@
+/****************************************************************************
+ * apps/games/shift/shift_input_console.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <termios.h>
+
+#include "shift_inputs.h"
+
+/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+/* Termios functions to have getch on Linux/NuttX */
+
+static struct termios g_old;
+static struct termios g_new;
+
+/* Initialize g_new terminal I/O settings */
+
+void init_termios(int echo)
+{
+  tcgetattr(0, &g_old);                 /* grab old terminal i/o settings */
+  g_new = g_old;                        /* use old settings as starting */
+  g_new.c_lflag &= ~ICANON;             /* disable buffered I/O */
+  g_new.c_lflag &= echo ? ECHO : ~ECHO; /* set echo mode */
+  tcsetattr(0, TCSANOW, &g_new);        /* apply terminal I/O settings */
+}
+
+/* Restore g_old terminal i/o settings */
+
+void reset_termios(void)
+{
+  tcsetattr(0, TCSANOW, &g_old);
+}
+
+/* Read 1 character - echo defines echo mode */
+
+char getch_(int echo)
+{
+    char ch;
+    init_termios(echo);
+    ch = getchar();
+    reset_termios();
+    return ch;
+}
+
+/* Read 1 character without echo getch() function definition. */
+
+char getch(void)
+{
+  return getch_(0);
+}
+
+/****************************************************************************
+ * dev_input_init
+ ****************************************************************************/
+
+int dev_input_init(FAR struct input_state_s *dev)
+{
+  init_termios(0);
+
+  return OK;
+}
+
+/****************************************************************************
+ * dev_read_input
+ ****************************************************************************/
+
+int dev_read_input(FAR struct input_state_s *dev)
+{
+  char ch;
+
+  /* Arrows keys return three bytes: 27 91 [65-68] */
+
+  if ((ch = getch()) == 27)
+    {
+      if ((ch = getch()) == 91)
+        {
+          ch = getch();
+          if (ch == 65)
+            {
+              dev->dir = DIR_UP;
+            }
+          else
+          if (ch == 66)

Review Comment:
   Ok, I will modify to use "else if" in a single line



##########
games/shift/shift_input_joystick.h:
##########
@@ -0,0 +1,166 @@
+/****************************************************************************
+ * apps/games/shift/shift_input_joystick.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <nuttx/input/djoystick.h>
+
+#include "shift_inputs.h"
+
+/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+#define DJOYSTICK_DEVNAME "/dev/djoy0"
+#define DJOYSTICK_SIGNO 13
+
+/* The set of supported joystick discretes */
+
+static djoy_buttonset_t g_djoysupported;
+
+/* Last sampled discrete set */
+
+static djoy_buttonset_t g_djoylast;
+
+struct djoy_notify_s notify;
+
+/****************************************************************************
+ * dev_input_init
+ ****************************************************************************/
+
+int dev_input_init(FAR struct input_state_s *dev)
+{
+  int tmp;
+  int ret;
+
+  /* Open the djoystick device */
+
+  dev->fd_joy = open(DJOYSTICK_DEVNAME, O_RDONLY);
+  if (dev->fd_joy < 0)
+    {
+      fprintf(stderr, "ERROR: Failed to open %s: %d\n",
+              DJOYSTICK_DEVNAME, errno);
+      return -ENODEV;
+    }
+
+  /* Get the set of supported discretes */
+
+  ret = ioctl(dev->fd_joy, DJOYIOC_SUPPORTED,
+              (unsigned long)((uintptr_t)&tmp));
+  if (ret < 0)
+    {
+      fprintf(stderr, "ERROR: ioctl(DJOYIOC_SUPPORTED) failed: %d\n", errno);
+      goto errout_with_fd;
+    }
+
+  g_djoysupported = (djoy_buttonset_t)tmp;
+
+  /* Register to receive a signal on any change in the joystick discretes. */
+
+  notify.dn_press   = g_djoysupported;
+  notify.dn_release = g_djoysupported;
+
+  notify.dn_event.sigev_notify = SIGEV_SIGNAL;
+  notify.dn_event.sigev_signo  = DJOYSTICK_SIGNO;
+
+  ret = ioctl(dev->fd_joy, DJOYIOC_REGISTER,
+              (unsigned long)((uintptr_t)&notify));
+  if (ret < 0)
+    {
+      fprintf(stderr, "ERROR: ioctl(DJOYIOC_REGISTER) failed: %d\n", errno);
+      goto errout_with_fd;
+    }
+
+  /* Ignore the default signal action */
+
+  signal(DJOYSTICK_SIGNO, SIG_IGN);
+
+  return OK;
+
+errout_with_fd:
+  close(dev->fd_joy);
+  return -ENODEV;
+}
+
+/****************************************************************************
+ * dev_read_input
+ ****************************************************************************/
+
+int dev_read_input(FAR struct input_state_s *dev)
+{
+  struct siginfo value;
+  sigset_t set;
+  djoy_buttonset_t newset;
+  ssize_t nread;
+  int ret;
+
+  /* Wait for a signal */
+
+  sigemptyset(&set);
+  sigaddset(&set, DJOYSTICK_SIGNO);
+  ret = sigwaitinfo(&set, &value);
+  if (ret < 0)
+    {
+      fprintf(stderr, "ERROR: sigwaitinfo() failed: %d\n", errno);
+    }
+
+  newset = (djoy_buttonset_t)value.si_value.sival_int;
+
+  g_djoylast = newset;
+
+  /* Read the signal set and compare */
+
+  nread = read(dev->fd_joy, &newset, sizeof(djoy_buttonset_t));
+  if (nread < 0)
+    {
+      fprintf(stderr, "ERROR: read() failed: %d\n", errno);
+    }
+  else if (nread != sizeof(djoy_buttonset_t))
+    {
+      fprintf(stderr, "ERROR: read() unexpected size: %ld vs %d\n",
+              (long)nread, sizeof(djoy_buttonset_t));
+    }
+
+  g_djoylast = newset;
+
+  switch (newset)
+    {
+      case DJOY_UP_BIT:
+          dev->dir = DIR_UP;
+          break;

Review Comment:
   Ok



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] acassis commented on a diff in pull request #1238: apps/games: Add shift game

Posted by GitBox <gi...@apache.org>.
acassis commented on code in PR #1238:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1238#discussion_r933195084


##########
games/shift/shift_main.c:
##########
@@ -0,0 +1,927 @@
+/****************************************************************************
+ * apps/games/shift/shift_main.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <math.h>
+
+#include <nuttx/video/fb.h>
+#include <nuttx/video/rgbcolors.h>
+
+#ifdef CONFIG_GAMES_SHIFT_USE_CONSOLEKEY
+#include "shift_input_console.h"
+#endif
+
+#ifdef CONFIG_GAMES_SHIFT_USE_DJOYSTICK
+#include "shift_input_joystick.h"
+#endif
+
+#ifdef CONFIG_GAMES_SHIFT_USE_GESTURE
+#include "shift_input_gesture.h"
+#endif
+
+/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+#define BOARDX_SIZE 6
+#define BOARDY_SIZE 6
+
+#define ROW         8
+#define COL         8
+
+/* Difficult mode:  4, 5, 6 */
+
+#define GAMEMODE    6
+
+#define NCOLORS     GAMEMODE
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct screen_state_s
+{
+  int fd_fb;
+  struct fb_videoinfo_s vinfo;
+  struct fb_planeinfo_s pinfo;
+#ifdef CONFIG_FB_OVERLAY
+  struct fb_overlayinfo_s oinfo;
+#endif
+  FAR void *fbmem;
+};
+
+struct game_screen_s
+{
+  int xres;     /* X display resolution */
+  int yres;     /* Y display resolution */
+  int xoff;     /* X offset to start drawing */
+  int yoff;     /* Y offset to start drawing */
+  int ncolors;  /* Supported number of colors */
+  int blklen;   /* Size of side of the blocks */
+  int steps;    /* Steps to slide a block for a now position */
+  int stepinc;  /* Step increment during the sliding */
+  int dir;      /* Direction to move the blocks */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const char g_default_fbdev[] = "/dev/fb0";
+
+/* The edge of the board is invisible to user */
+
+int board[ROW][COL] =
+                            {
+                              {1, 1, 1, 1, 1, 1, 1, 1},
+                              {1, 0, 0, 0, 0, 0, 0, 1},
+                              {1, 0, 0, 0, 0, 0, 0, 1},
+                              {1, 0, 0, 0, 0, 0, 0, 1},
+                              {1, 0, 0, 0, 0, 0, 0, 1},
+                              {1, 0, 0, 0, 0, 0, 0, 1},
+                              {1, 0, 0, 0, 0, 0, 0, 1},
+                              {1, 1, 1, 1, 1, 1, 1, 1}
+                            };

Review Comment:
   Ok, my plan was to keep it aligned with the end of previous line, but I will move it to the left



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] acassis commented on a diff in pull request #1238: apps/games: Add shift game

Posted by GitBox <gi...@apache.org>.
acassis commented on code in PR #1238:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1238#discussion_r933504741


##########
games/shift/shift_input_console.h:
##########
@@ -0,0 +1,133 @@
+/****************************************************************************
+ * apps/games/shift/shift_input_console.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <termios.h>
+
+#include "shift_inputs.h"
+
+/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+/* Termios functions to have getch on Linux/NuttX */
+
+static struct termios g_old;
+static struct termios g_new;
+
+/* Initialize g_new terminal I/O settings */
+
+void init_termios(int echo)
+{
+  tcgetattr(0, &g_old);                 /* grab old terminal i/o settings */
+  g_new = g_old;                        /* use old settings as starting */
+  g_new.c_lflag &= ~ICANON;             /* disable buffered I/O */
+  g_new.c_lflag &= ~ECHO;               /* disable ECHO bit */
+  g_new.c_lflag |= echo ? ECHO : 0;     /* set echo mode if requested */
+  tcsetattr(0, TCSANOW, &g_new);        /* apply terminal I/O settings */
+}
+
+/* Restore g_old terminal i/o settings */
+
+void reset_termios(void)
+{
+  tcsetattr(0, TCSANOW, &g_old);
+}
+
+/* Read 1 character - echo defines echo mode */
+
+char getch_(int echo)
+{
+  char ch;
+
+  init_termios(echo);
+  ch = getchar();
+  reset_termios();
+
+  return ch;
+}
+
+/* Read 1 character without echo getch() function definition. */
+
+char getch(void)
+{
+  return getch_(0);
+}
+
+/****************************************************************************
+ * dev_input_init
+ ****************************************************************************/
+
+int dev_input_init(FAR struct input_state_s *dev)
+{
+  init_termios(0);
+
+  return OK;
+}
+
+/****************************************************************************
+ * dev_read_input
+ ****************************************************************************/
+
+int dev_read_input(FAR struct input_state_s *dev)
+{
+  char ch;
+
+  /* Arrows keys return three bytes: 27 91 [65-68] */
+
+  if ((ch = getch()) == 27)
+    {
+      if ((ch = getch()) == 91)
+        {
+          ch = getch();
+          if (ch == 65)
+            {
+              dev->dir = DIR_UP;
+            }
+          else if (ch == 66)
+                {
+                   dev->dir = DIR_DOWN;
+                }
+               else if (ch == 67)
+                      {
+                        dev->dir = DIR_RIGHT;
+                      }
+                    else if (ch == 68)
+                          {
+                             dev->dir = DIR_LEFT;
+                          }

Review Comment:
   I think the nxstyle.c needs to be fixed to this case where we move the braces to just below the external (right most) "if (". Also need to be fixed to catch "case" with more than 2 spaces in the next line.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] pkarashchenko commented on a diff in pull request #1238: apps/games: Add shift game

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #1238:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1238#discussion_r933501088


##########
games/shift/shift_input_console.h:
##########
@@ -0,0 +1,133 @@
+/****************************************************************************
+ * apps/games/shift/shift_input_console.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <termios.h>
+
+#include "shift_inputs.h"
+
+/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+/* Termios functions to have getch on Linux/NuttX */
+
+static struct termios g_old;
+static struct termios g_new;
+
+/* Initialize g_new terminal I/O settings */
+
+void init_termios(int echo)
+{
+  tcgetattr(0, &g_old);                 /* grab old terminal i/o settings */
+  g_new = g_old;                        /* use old settings as starting */
+  g_new.c_lflag &= ~ICANON;             /* disable buffered I/O */
+  g_new.c_lflag &= ~ECHO;               /* disable ECHO bit */
+  g_new.c_lflag |= echo ? ECHO : 0;     /* set echo mode if requested */
+  tcsetattr(0, TCSANOW, &g_new);        /* apply terminal I/O settings */
+}
+
+/* Restore g_old terminal i/o settings */
+
+void reset_termios(void)
+{
+  tcsetattr(0, TCSANOW, &g_old);
+}
+
+/* Read 1 character - echo defines echo mode */
+
+char getch_(int echo)
+{
+  char ch;
+
+  init_termios(echo);
+  ch = getchar();
+  reset_termios();
+
+  return ch;
+}
+
+/* Read 1 character without echo getch() function definition. */
+
+char getch(void)
+{
+  return getch_(0);
+}
+
+/****************************************************************************
+ * dev_input_init
+ ****************************************************************************/
+
+int dev_input_init(FAR struct input_state_s *dev)
+{
+  init_termios(0);
+
+  return OK;
+}
+
+/****************************************************************************
+ * dev_read_input
+ ****************************************************************************/
+
+int dev_read_input(FAR struct input_state_s *dev)
+{
+  char ch;
+
+  /* Arrows keys return three bytes: 27 91 [65-68] */
+
+  if ((ch = getch()) == 27)
+    {
+      if ((ch = getch()) == 91)
+        {
+          ch = getch();
+          if (ch == 65)
+            {
+              dev->dir = DIR_UP;
+            }
+          else if (ch == 66)
+                {
+                   dev->dir = DIR_DOWN;
+                }
+               else if (ch == 67)
+                      {
+                        dev->dir = DIR_RIGHT;
+                      }
+                    else if (ch == 68)
+                          {
+                             dev->dir = DIR_LEFT;
+                          }

Review Comment:
   Very strange. I do not think this is the only place in the project where `else if` + `{}` is used.  Let me check why this might happen



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org