Demo example on FRDM-64F https://ide.mbed.com/compiler/#nav:/rzr-example-mbed;

Dependencies:   FXOS8700Q

Files at this revision

API Documentation at this revision

Comitter:
rzrfreefr
Date:
Wed Mar 16 14:41:31 2022 +0000
Parent:
2:15bfd52937dc
Commit message:
Publish

Changed in this revision

Utils.cpp Show annotated file Show diff for this revision Revisions of this file
Utils.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 15bfd52937dc -r 807a69c34b8b Utils.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils.cpp	Wed Mar 16 14:41:31 2022 +0000
@@ -0,0 +1,44 @@
+/// SPDX-License-Indentifier: Apache-2.0
+/// Copyright: 2020+ Philippe Coval <https://purl.org/rzr/>
+/// URL: https://os.mbed.com/users/rzrfreefr/code/rzr-example-mbed/
+
+#include "Utils.h"
+
+//https://github.com/ARMmbed/mbed-os/blob/c6094f7b36dc0e90a6a7271870333fbba475286c/drivers/usb/source/USBKeyboard.cpp
+#define REPORT_ID_KEYBOARD 1
+
+bool Utils::keyboard_key_code(USBKeyboard& usb,
+                              unsigned char const key,
+                              unsigned char const modifier,
+                              unsigned int delay)
+{
+    HID_REPORT report;
+
+    report.data[0] = REPORT_ID_KEYBOARD;
+    report.data[1] = modifier;
+    report.data[2] = 0;
+    //report.data[3] = usb.keymap[key].usage;
+    report.data[3] = key;
+
+    report.data[4] = 0;
+    report.data[5] = 0;
+    report.data[6] = 0;
+    report.data[7] = 0;
+    report.data[8] = 0;
+
+    report.length = 9;
+
+    if (!usb.send(&report)) {
+        return false;
+    }
+    if (delay) { 
+      ThisThread::sleep_for(delay);
+    }
+    report.data[1] = 0;
+    report.data[3] = 0;
+
+    if (!usb.send(&report)) {
+        return false;
+    }
+    return true;
+}
diff -r 15bfd52937dc -r 807a69c34b8b Utils.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils.h	Wed Mar 16 14:41:31 2022 +0000
@@ -0,0 +1,16 @@
+/// SPDX-License-Indentifier: Apache-2
+/// Copyright: 2020+ Philippe Coval <https://purl.org/rzr/>
+/// URL: https://os.mbed.com/users/rzrfreefr/code/rzr-example-mbed/
+
+#pragma once
+#include "mbed.h"
+#include "USBKeyboard.h"
+
+class Utils
+{
+public:
+    static bool keyboard_key_code(USBKeyboard& usb,
+                              unsigned char const key,
+                              unsigned char const modifier=0,
+                              unsigned int delay=30); //< delay until release
+};
\ No newline at end of file
diff -r 15bfd52937dc -r 807a69c34b8b main.cpp
--- a/main.cpp	Thu Nov 19 23:07:40 2020 +0000
+++ b/main.cpp	Wed Mar 16 14:41:31 2022 +0000
@@ -1,14 +1,15 @@
 /// SPDX-License-Indentifier: ISC
-/// Copyright: 2020+ Philippe Coval <https://purl.org/rzr>
+/// Copyright: 2020+ Philippe Coval <https://purl.org/rzr/>
 /// URL: https://os.mbed.com/users/rzrfreefr/code/rzr-example-mbed/
 
 #include "mbed.h"
 
-#include "EthernetInterface.h"
-#include "USBKeyboard.h"
-#include "FXOS8700Q.h"
+#include <EthernetInterface.h>
+#include <USBKeyboard.h>
+#include <FXOS8700Q.h>
+#include "Utils.h"
 
-#define CONFIG_LOG 1
+//#define CONFIG_LOG 1
 //#define CONFIG_NET 1
 #define CONFIG_USB 1
 
@@ -26,8 +27,6 @@
     DigitalOut led(LED1);
     led = false; //on
 
-    const float delay = 1000.f / 25;
-
     I2C i2c(PTE25, PTE24);
     motion_data_units_t acc_data;
     motion_data_counts_t acc_raw;
@@ -41,21 +40,30 @@
     float vmin[] = {0, 0, 0};
     float vmax[] = {0, 0, 0};
 
-    float threshold = 1./3.;
+    // cis: 10 < 12 < 13Log < 15 < 20N < 25<  35N < 40 < ~50 < 60 < !75
+    // pin: 12? < 50
+    float threshold = 1./25;
     float vthreshold[] = {threshold, threshold, threshold};
+    const float delay = 1000.f / 25 / len;
 
-#if 1
+#if 0
     int keymap[3][2] = {
-        { LEFT_ARROW, RIGHT_ARROW },
+        { RIGHT_ARROW, LEFT_ARROW },
         { DOWN_ARROW, UP_ARROW },
         { KEY_PAGE_DOWN, KEY_PAGE_UP }
     };
-#else
+#elif 1
     int keymap[3][2] = {
-        { KEY_CTRL, KEY_RCTRL },
+        { KEY_RCTRL, KEY_CTRL },
         { DOWN_ARROW, UP_ARROW },
         { KEY_PAGE_DOWN, KEY_PAGE_UP }
     };
+#elif 0 // https://github.com/ARMmbed/mbed-os/blob/c6094f7b36dc0e90a6a7271870333fbba475286c/drivers/usb/source/USBKeyboard.cpp
+    int keymap[3][2] = {
+        { 0x4f, 0x50 },
+        { 0x51, 0x52 },
+        { 0x4b, 0x4e }
+    };
 #endif
 
 
@@ -108,10 +116,17 @@
             if (key != 0) {
                 led = false; //on
                 logf("# key: %0X\n", key);
+#if 0
+                Thread thread;
+                thread.start(idle);
+#endif
+
                 if (!true) {
                     usb.key_code(key, key);
+                } else if (false) {
+                    usb.key_code(key);
                 } else {
-                    usb.key_code(key);
+                    Utils::keyboard_key_code(usb, key, key);
                 }
             }
             iter=0;
diff -r 15bfd52937dc -r 807a69c34b8b mbed-os.lib
--- a/mbed-os.lib	Thu Nov 19 23:07:40 2020 +0000
+++ b/mbed-os.lib	Wed Mar 16 14:41:31 2022 +0000
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#aa70f680bb5755e8fea3f93fc6e04d9b3de235bb
+https://github.com/ARMmbed/mbed-os/#c6d65fe5082aeef6bf0d7043b4cbf0a9cc9a9d5e