orangepi
root
or root
orangepi
password sudo apt-get update && sudo apt-get upgrade –y
sudo apt-get install motion -y
sudo nano /etc/default/motion
start_motion_daemon
set 'yes'. Save changes Ctrl + x, y, Enter. sudo nano /etc/motion/motion.conf
daemon on
width 800 height 600
framerate 25
output_normal off
webcam_quality 100
webcam_maxrate 25
webcam_localhost off
sudo apt-get install build-essential -y
sudo apt-get install ncurses -y
sudo chown orangepi /dev/ttyS2
sudo nano /etc/modules
gpio-sunxi
. With this action we activate gpio, more precisely, the module for working with it, why I’ll tell you later. sudo nano /etc/rc.local
exit
line the following chown -R orangepi /sys/devices/platform/*
. This command will make the orangepi user own the virtual files that are responsible for interacting with the GPIO port. sudo reboot
cd ~ mkdir PROG cd PROG
HIDKeyboard.h
and LRHIDKeyboard.cpp
: touch HIDKeyboard.h touch LRHIDKeyboard.cpp
nano HIDKeyboard.h
#ifndef HIDKeyboard_h #define HIDKeyboard_h //#include "Arduino.h" /**************************************************************************** * SPECIAL CHARACTER DEFINES * * These are the HID values for keys that do not output characters * ****************************************************************************/ // HID Values of Function Keys #define F1 0x3a #define F2 0x3b #define F3 0x3c #define F4 0x3d #define F5 0x3e #define F6 0x3f #define F7 0x40 #define F8 0x41 #define F9 0x42 #define F10 0x43 #define F11 0x44 #define F12 0x45 // HID Values of Special Keys #define ENTER 0x28 #define ESCAPE 0x29 #define BACKSPACE 0x2a #define TAB 0x2b #define SPACEBAR 0x2c #define CAPSLOCK 0x39 #define PRINTSCREEN 0x46 #define SCROLLLOCK 0x47 #define PAUSE 0x48 #define INSERT 0x49 #define HOME 0x4a #define PAGEUP 0x4b #define DELETE 0x4c #define END 0x4d #define PAGEDOWN 0x4e #define RIGHTARROW 0x4f #define LEFTARROW 0x50 #define DOWNARROW 0x51 #define UPARROW 0x52 // HID Values of Keypad Keys #define NUMLOCK 0x53 #define KEYPADSLASH 0x54 #define KEYPADSTAR 0x55 #define KEYPADMINUS 0x56 #define KEYPADPLUS 0x57 #define KEYPADENTER 0x58 #define KEYPAD1 0x59 #define KEYPAD2 0x5a #define KEYPAD3 0x5b #define KEYPAD4 0x5c #define KEYPAD5 0x5d #define KEYPAD6 0x5e #define KEYPAD7 0x5f #define KEYPAD8 0x60 #define KEYPAD9 0x61 #define KEYPAD0 0x62 #define KEYPADPERIOD 0x63 // HID Values of System Keys #define KEYBOARDAPPLICATION 0x65 #define KEYBOARDPOWER 0x66 #define VOLUMEMUTE 0x7f #define VOLUMEUP 0x80 #define VOLUMEDOWN 0x81 // Common-use modifiers #define LCTRL 0x01 #define SHIFT 0x02 #define ALT 0x04 #define GUI 0x08 /**************************************************************************** * * ASCII->HID LOOKUP TABLE * * Taken from the HID Table definition at * http://www.usb.org/developers/devclass_docs/Hut1_11.pdf * * This array maps the ASCII value of a type-able character to its * corresponding HID value. * * Example: * 'a' = ASCII value 97 = HID value 0x04 * HIDTable['a'] = HIDTable[97] = 0x04 * * NOTE: * "Shift Modified" HID values are the same as the non Shift-Modified values * for any given character, eg the HID value for '2' is equal to the * HID value for '@'. The Shift-Modified value is sent by setting the * modifier value (buf[0]) to the corresponding modifier value in the * modifier table. * ****************************************************************************/ const static uint8_t HIDTable[] = { 0x00, // 0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2A, 0x2b, 0x28, // 10 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 20 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, // 30 0x00, 0x2c, 0x1e, 0x34, 0x20, 0x21, 0x22, 0x24, 0x34, 0x26, // 40 0x27, 0x25, 0x2e, 0x36, 0x2d, 0x37, 0x38, 0x27, 0x1e, 0x1f, // 50 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x33, 0x33, 0x36, // 60 0x2e, 0x37, 0x38, 0x1f, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, // 70 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, // 80 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, // 90 0x2f, 0x31, 0x30, 0x23, 0x2d, 0x35, 0x04, 0x05, 0x06, 0x07, // 100 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, // 110 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, // 120 0x1c, 0x1d, 0x2f, 0x31, 0x30, 0x35, 0x4c, 0x00, 0x00, 0x00, // 130 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 140 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 150 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 160 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 170 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 190 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 200 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 240 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x51, 0x52, 0x50, // 260 0x4f, 0x4a, 0x2a, 0x00, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, // 270 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x00, 0x00, 0x00, 0x00, // 280 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 310 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 320 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, // 330 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4e, 0x4b, 0x00, // 340 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 350 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d, // 360 }; /**************************************************************************** * * ASCII->MODIFIER LOOKUP TABLE * * Looks up whether or not the HID report should use the SHIFT modifier. * * Example: * The character '2' and the character '@' have different ASCII values but * the same HID value. This table uses the ASCII value to determine if * we should hold shift while sending the key. eg: * * HIDTable['2'] = 0x1f and modifierTable['2'] = 0 * HIDTable['@'] = 0x1f and modifierTable['@'] = SHIFT * * There's probaly a better way to do this, but it's functional. * ****************************************************************************/ const static uint8_t modifierTable[] = { 0x00, // 0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 10 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 20 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 30 0x00, 0x00, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, 0x00, SHIFT, // 40 SHIFT, SHIFT, SHIFT, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 50 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, SHIFT, 0x00, SHIFT, // 60 0x00, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, // 70 SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, // 80 SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, SHIFT, // 90 0x00, 0x00, 0x00, SHIFT, SHIFT, 0x00, 0x00, 0x00, 0x00, 0x00, // 100 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 110 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 120 0x00, 0x00, SHIFT, SHIFT, SHIFT, SHIFT, 0x00 // 127 }; class HIDKeyboard { public: // Constructor HIDKeyboard(); // Public functions void begin(); // Starts the required serial communication (9600 baud) void pressKey(uint8_t modifier, uint8_t key); // Looks up key in HIDTable and sends with a modifier void pressKey(uint8_t key); // Sends key report without modifier (modifier = 0) void pressSpecialKey(uint8_t modifier, uint8_t specialKey); // Sends specialKey with a modifier void pressSpecialKey(uint8_t specialKey); // Sends specialKey without modifier void releaseKey(); // Releases keys (clears key and modifier) void print(char* sequence); // Prints string <sequence> void println(char* sequence); // Prints string <sequence> followed by a carriage return private: // HID report buffer uint8_t buf[8]; // In report, buf[0] = modifier and buf[2] = key HID value }; #endif
nano LRHIDKeyboard.cpp
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include <termios.h> #include <time.h> #include <ncurses.h> #include "HIDKeyboard.h" char myport[] = "/dev/ttyS2"; // serial port // char nul[] = ""; char menu[] = "/sys/class/gpio_sw/PA14/data"; // char zoom[] = "/sys/class/gpio_sw/PD14/data"; // char kup[] = "/sys/class/gpio_sw/PC4/data"; // char kdn[] = "/sys/class/gpio_sw/PC7/data"; // char klf[] = "/sys/class/gpio_sw/PG8/data"; // char krt[] = "/sys/class/gpio_sw/PA21/data"; // uint8_t buf[8] = { 0 }; /* Keyboard report buffer */ int open_port(char *devname) // serial port { int fd; fd = open(devname, O_RDWR | O_NOCTTY | O_NDELAY); if(fd == -1) // { printw("Port is not open! %s" , devname); return -1; } else { fcntl(fd, F_SETFL, 0); printw("Open port %s", devname); } // struct termios port_settings; cfsetispeed(&port_settings, B9600); cfsetospeed(&port_settings, B9600); port_settings.c_cflag &= ~PARENB; port_settings.c_cflag &= ~CSTOPB; port_settings.c_cflag &= ~CSIZE; port_settings.c_cflag |= CS8; tcsetattr(fd, TCSANOW, &port_settings); return(fd); } int alt_check(int check) // ALT, ALT, "0" { if(check == 27) { nodelay(stdscr,TRUE); check = getch(); if (check == -1) return ESCAPE; // Esc nodelay(stdscr,FALSE); return check; } //else return 0; return 0; } int hot_key(int fd, int alt, int vchar) // { if(alt != 0) { if (alt == 330) // "Alt" + "Delete" Ctrl + Alt + Delete { vchar = 0; buf[0] = 0x04|0x01; buf[2] = HIDTable[alt]; write(fd, buf, 8); return 0; } if (alt == 114) // "Alt" + "r" Win + r { vchar = 0; buf[0] = 0x08; buf[2] = HIDTable[alt]; write(fd, buf, 8); return 0; } if (alt == 52) // "Alt" + "4" Alt + F4 { vchar = 0; buf[0] = 0x04; buf[2] = 0x3d; write(fd, buf, 8); return 0; } if (alt == 116) // "Alt" + "t" Alt + Tab { vchar = 0; buf[0] = 0x04; buf[2] = 0x2b; write(fd, buf, 8); return 0; } if (alt == 44) // "Alt" + "," Alt + Shift { vchar = 0; buf[0] = 0x04|0x02; write(fd, buf, 8); return 0; } if (alt == 46) // "Alt" + "." Ctrl + Shift { vchar = 0; buf[0] = 0x01|0x02; write(fd, buf, 8); return 0; } } else { if (vchar == 17) // "Ctrl" + "q" { endwin(); exit(0); } // *nul = '\0'; if (vchar == 28) strcpy(nul, menu); // "Ctrl" + "\" if (vchar == 31) strcpy(nul, zoom); // "Ctrl" + "/" if (vchar == 566) strcpy(nul, kup); // "Ctrl" + "up" if (vchar == 525) strcpy(nul, kdn); // "Ctrl" + "down" if (vchar == 545) strcpy(nul, klf); // "Ctrl" + "left" if (vchar == 560) strcpy(nul, krt); // "Ctrl" + "right" FILE *f = fopen(nul, "w"); // if (f != '\0') { fwrite("1", 1, 1, f); int wrt = fclose(f); // usleep(70000); if (wrt == 0) { FILE *f = fopen(nul, "w"); fwrite("0", 1, 1, f); fclose(f); } else printf("error write file: %s", nul); return 0; } return vchar; } } int send_key(int fd, int altkey, int getkey) // { if (altkey == ESCAPE) { buf[0] = 0x00; buf[2] = 0x29; write(fd, buf, 8); return 1; } if (altkey != 0) { buf[0] = 0x04; buf[2] = HIDTable[altkey]; write(fd, buf, 8); return 1; } else { if (getkey == 0) return 0; //printf("KEY NAME : %s - %d\n", keyname(getkey),getkey); // buf[0] = modifierTable[getkey]; buf[2] = HIDTable[getkey]; write(fd, buf, 8); return 1; } return(-1); } int release_key(int fd) // { buf[0] = 0; buf[2] = 0; write(fd, buf, 8); } int main(void) { initscr(); keypad(stdscr,TRUE); // raw(); // int fd = open_port(myport); printw("\nHOT KEYS: Alt + Delete = Ctrl + Alt + Delete Alt + r = Win + r Alt + 4 = Alt + F4 Alt + t = Alt + Tab Alt + , = Alt + Shift Alt + . = Ctrl + Shift"); printw("\nGPIO: MENU = Ctrl + \\ ZOOM = Ctrl + / UP = Ctrl + up DOWN = Ctrl + down LEFT = Ctrl + left RIGHT = Ctrl + right"); printw("\n Exit = Ctrl + q"); move(10,1); refresh(); while (fd != -1) { int pkey = getch(); int alt = alt_check(pkey); int hot = hot_key(fd, alt, pkey); send_key(fd, alt, hot); release_key(fd); } endwin(); }
g++ LRHIDKeyboard.cpp -o rkeysend -lncurses
orangepi:8081
. Well, that's all, all the necessary information for repeating the experience is stated, the mission is completed.Source: https://habr.com/ru/post/326112/
All Articles