linguini1 commented on code in PR #19812:
URL: https://github.com/apache/nuttx/pull/19812#discussion_r3768975069


##########
Documentation/platforms/sim/sim_input.rst:
##########
@@ -0,0 +1,38 @@
+====================
+Sim Input Interfaces
+====================
+
+Overview
+========
+
+The Sim can emulate buttons, keyboard, touchscreen-mouse based, mouse with 3 
buttons and analog-mouse based joystick.
+
+These drivers are particularly useful for graphical applications emulared over 
X11.
+
+Buttons
+=======
+
+This driver emulates a button using the user Mouse button. You can enable it 
using
+``CONFIG_SIM_BUTTONS``.
+
+Joystick
+========
+
+This driver simulates an Analog Joystick using the user mouse.
+
+Keyboard
+========
+
+There are two types of keyboards: is native one used by default on NuttX SIM, 
since it is used to access the NuttShell interface and the 
``CONFIG_SIM_KEYBOARD`` used with graphical applications.
+
+Mouse
+=====
+
+The driver emulates a Mouse with 3 buttons support. It can be enabled using the
+symbol: ``CONFIG_SIM_MOUSE``. This driver is useful with used with more 
advanced interfaces like Microwindow/Nano-X that require at least left and 
right click buttons events.

Review Comment:
   Is there a doc page to link to for nano x yet or no? If there is it would be 
good to backlink



##########
Documentation/platforms/sim/sim_input.rst:
##########
@@ -0,0 +1,38 @@
+====================
+Sim Input Interfaces
+====================
+
+Overview
+========
+
+The Sim can emulate buttons, keyboard, touchscreen-mouse based, mouse with 3 
buttons and analog-mouse based joystick.
+
+These drivers are particularly useful for graphical applications emulared over 
X11.
+
+Buttons
+=======
+
+This driver emulates a button using the user Mouse button. You can enable it 
using
+``CONFIG_SIM_BUTTONS``.
+
+Joystick
+========
+
+This driver simulates an Analog Joystick using the user mouse.
+
+Keyboard
+========
+
+There are two types of keyboards: is native one used by default on NuttX SIM, 
since it is used to access the NuttShell interface and the 
``CONFIG_SIM_KEYBOARD`` used with graphical applications.

Review Comment:
   *the native one



##########
arch/sim/src/sim/sim_mouse.c:
##########
@@ -0,0 +1,206 @@
+/****************************************************************************
+ * arch/sim/src/sim/sim_mouse.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/* A full X11 mouse emulation for the sim architecture, registering
+ * /dev/mouseN via the standard mouse_lowerhalf_s interface (see
+ * include/nuttx/input/mouse.h). Modeled closely on sim_touchscreen.c
+ * (same registration shape, same X11-button-event source via
+ * sim_x11eventloop.c), but reports which physical button changed
+ * instead of folding every button into one "pen down" contact --
+ * sim_touchscreen.c exists to emulate real touchscreen hardware, which
+ * has no second or third button to report in the first place. Any
+ * consumer that needs to tell a right-click from a left-click (e.g. a
+ * GUI toolkit's context-menu handling) needs this driver, not the
+ * touchscreen one.
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <nuttx/debug.h>
+
+#include <nuttx/input/mouse.h>
+
+#include "sim_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define DEV_FORMAT   "/dev/mouse%d"
+#define DEV_NAMELEN  16
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* This structure describes the state of one simulated mouse driver
+ * instance.
+ */
+
+struct sim_dev_s
+{
+  int eventloop;
+  uint8_t minor;                     /* Minor device number */
+  struct mouse_lowerhalf_s lower;    /* Mouse lowerhalf */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Only one simulated mouse is supported so the driver state structure
+ * may as well be pre-allocated.
+ */
+
+static struct sim_dev_s g_simmouse;
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sim_mouse_initialize
+ *
+ * Description:
+ *   Configure the simulated mouse.  This will register the driver as
+ *   /dev/mouseN where N is the minor device number
+ *
+ * Input Parameters:
+ *   minor   - The input device minor number
+ *
+ * Returned Value:
+ *   Zero is returned on success.  Otherwise, a negated errno value is
+ *   returned to indicate the nature of the failure.
+ *
+ ****************************************************************************/
+
+int sim_mouse_initialize(int minor)
+{
+  struct sim_dev_s *priv = (struct sim_dev_s *)&g_simmouse;
+  char devname[DEV_NAMELEN];
+  int ret;
+
+  iinfo("minor: %d\n", minor);
+
+  /* Debug-only sanity checks */
+
+  DEBUGASSERT(minor >= 0 && minor < 100);
+
+  /* Initialize the mouse device driver instance */
+
+  memset(priv, 0, sizeof(struct sim_dev_s));
+
+  priv->minor = minor;
+
+  /* Register the device as an input device */
+
+  snprintf(devname, sizeof(devname), DEV_FORMAT, minor);
+  iinfo("Registering %s\n", devname);
+
+  ret = mouse_register(&priv->lower, devname, 1);
+  if (ret < 0)
+    {
+      ierr("ERROR: mouse_register() failed: %d\n", ret);
+      return ret;
+    }
+
+  /* Enable X11 event processing from the IDLE loop */
+
+  priv->eventloop = 1;
+
+  /* And return success */
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: sim_mouse_uninitialize
+ *
+ * Description:
+ *   Uninitialized the simulated mouse
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   Return OK if success or negative value of the error.
+ *
+ ****************************************************************************/
+
+int sim_mouse_uninitialize(void)
+{
+  struct sim_dev_s *priv = (struct sim_dev_s *)&g_simmouse;
+  char devname[DEV_NAMELEN];
+
+  /* Stop the event loop (Hmm.. the caller must be sure that there are no

Review Comment:
   Maybe we can state this assumption in the function comment? I've seen other 
NuttX functions use the "Assumptions" field.



##########
arch/sim/src/sim/posix/sim_x11eventloop.c:
##########
@@ -91,6 +91,64 @@ static int sim_buttonmap(int state, int button)
 }
 #endif
 
+/****************************************************************************
+ * Name: sim_mousebuttonmap
+ *
+ * Description:
+ *   Same idea as sim_buttonmap() above, but producing a bitmap in
+ *   struct mouse_report_s's MOUSE_BUTTON_1/2/3 numbering (see
+ *   include/nuttx/input/mouse.h) instead of touch_sample_s's single
+ *   undifferentiated "pen down" bit -- the whole point of
+ *   CONFIG_SIM_MOUSE over CONFIG_SIM_TOUCHSCREEN is to keep which
+ *   physical button was pressed. Not including that header here since
+ *   it's the only thing that would pull NuttX input headers into this
+ *   host-compiled (HOSTSRCS) file; the three bit values are hand-rolled
+ *   instead, matching MOUSE_BUTTON_1=1, MOUSE_BUTTON_2=2, MOUSE_BUTTON_3=4.

Review Comment:
   I think everything after "pen down bit" is extra info that doesn't really 
describe the function. It's quite "AI sounding".



##########
arch/sim/src/sim/sim_mouse.c:
##########
@@ -0,0 +1,206 @@
+/****************************************************************************
+ * arch/sim/src/sim/sim_mouse.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/* A full X11 mouse emulation for the sim architecture, registering
+ * /dev/mouseN via the standard mouse_lowerhalf_s interface (see
+ * include/nuttx/input/mouse.h). Modeled closely on sim_touchscreen.c
+ * (same registration shape, same X11-button-event source via
+ * sim_x11eventloop.c), but reports which physical button changed
+ * instead of folding every button into one "pen down" contact --
+ * sim_touchscreen.c exists to emulate real touchscreen hardware, which
+ * has no second or third button to report in the first place. Any
+ * consumer that needs to tell a right-click from a left-click (e.g. a
+ * GUI toolkit's context-menu handling) needs this driver, not the
+ * touchscreen one.
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <nuttx/debug.h>
+
+#include <nuttx/input/mouse.h>
+
+#include "sim_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define DEV_FORMAT   "/dev/mouse%d"
+#define DEV_NAMELEN  16
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* This structure describes the state of one simulated mouse driver
+ * instance.
+ */
+
+struct sim_dev_s
+{
+  int eventloop;
+  uint8_t minor;                     /* Minor device number */
+  struct mouse_lowerhalf_s lower;    /* Mouse lowerhalf */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Only one simulated mouse is supported so the driver state structure
+ * may as well be pre-allocated.
+ */
+
+static struct sim_dev_s g_simmouse;
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sim_mouse_initialize
+ *
+ * Description:
+ *   Configure the simulated mouse.  This will register the driver as
+ *   /dev/mouseN where N is the minor device number
+ *
+ * Input Parameters:
+ *   minor   - The input device minor number
+ *
+ * Returned Value:
+ *   Zero is returned on success.  Otherwise, a negated errno value is
+ *   returned to indicate the nature of the failure.
+ *
+ ****************************************************************************/
+
+int sim_mouse_initialize(int minor)
+{
+  struct sim_dev_s *priv = (struct sim_dev_s *)&g_simmouse;
+  char devname[DEV_NAMELEN];
+  int ret;
+
+  iinfo("minor: %d\n", minor);
+
+  /* Debug-only sanity checks */
+
+  DEBUGASSERT(minor >= 0 && minor < 100);
+
+  /* Initialize the mouse device driver instance */
+
+  memset(priv, 0, sizeof(struct sim_dev_s));
+
+  priv->minor = minor;
+
+  /* Register the device as an input device */
+
+  snprintf(devname, sizeof(devname), DEV_FORMAT, minor);
+  iinfo("Registering %s\n", devname);
+
+  ret = mouse_register(&priv->lower, devname, 1);
+  if (ret < 0)
+    {
+      ierr("ERROR: mouse_register() failed: %d\n", ret);
+      return ret;
+    }
+
+  /* Enable X11 event processing from the IDLE loop */
+
+  priv->eventloop = 1;
+
+  /* And return success */

Review Comment:
   Remove



##########
Documentation/platforms/sim/sim_input.rst:
##########
@@ -0,0 +1,38 @@
+====================
+Sim Input Interfaces
+====================
+
+Overview
+========
+
+The Sim can emulate buttons, keyboard, touchscreen-mouse based, mouse with 3 
buttons and analog-mouse based joystick.
+
+These drivers are particularly useful for graphical applications emulared over 
X11.

Review Comment:
   *emulated



##########
Documentation/platforms/sim/sim_input.rst:
##########
@@ -0,0 +1,38 @@
+====================
+Sim Input Interfaces
+====================
+
+Overview
+========
+
+The Sim can emulate buttons, keyboard, touchscreen-mouse based, mouse with 3 
buttons and analog-mouse based joystick.
+
+These drivers are particularly useful for graphical applications emulared over 
X11.
+
+Buttons
+=======
+
+This driver emulates a button using the user Mouse button. You can enable it 
using
+``CONFIG_SIM_BUTTONS``.
+
+Joystick
+========
+
+This driver simulates an Analog Joystick using the user mouse.
+
+Keyboard
+========
+
+There are two types of keyboards: is native one used by default on NuttX SIM, 
since it is used to access the NuttShell interface and the 
``CONFIG_SIM_KEYBOARD`` used with graphical applications.
+
+Mouse
+=====
+
+The driver emulates a Mouse with 3 buttons support. It can be enabled using the
+symbol: ``CONFIG_SIM_MOUSE``. This driver is useful with used with more 
advanced interfaces like Microwindow/Nano-X that require at least left and 
right click buttons events.
+
+Touchscreen
+===========
+
+The difference between this driver and the Mouse is because this only 
generates a pen-down event when the user click in the interface. It is useful 
to use with LVGL graphic interface.

Review Comment:
   *is that this only generates
   
   *when the user clicks
   
   *with the LVGL



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to