Skip to content

Instantly share code, notes, and snippets.

View xiongyihui's full-sized avatar

Yihui Xiong xiongyihui

View GitHub Profile
@xiongyihui
xiongyihui / usb-composite.sh
Last active January 14, 2023 14:46
Linux USB Gadget - UAC & HID
#!/bin/bash
modprobe libcomposite
mkdir -p /sys/kernel/config/usb_gadget/g
echo 0x1d6b > /sys/kernel/config/usb_gadget/g/idVendor # Linux Foundation
echo 0x0104 > /sys/kernel/config/usb_gadget/g/idProduct # Multifunction Composite Gadget
echo 0x0100 > /sys/kernel/config/usb_gadget/g/bcdDevice # v1.0.0
echo 0x0200 > /sys/kernel/config/usb_gadget/g/bcdUSB # USB 2.0
echo 0xef > /sys/kernel/config/usb_gadget/g/bDeviceClass # USB 2.0
echo 0x02 > /sys/kernel/config/usb_gadget/g/bDeviceSubClass # USB 2.0
@xiongyihui
xiongyihui / CMakeLists.txt
Created December 24, 2018 08:42
paho.mqtt.cpp example
find_package(PahoMqttCpp REQUIRED)
add_executable(data_publish data_publish.cpp)
# target_link_libraries(data_publish paho-mqtt3a paho-mqttpp3)
target_link_libraries(data_publish PahoMqttCpp::paho-mqttpp3)
@xiongyihui
xiongyihui / gif2c.py
Created February 2, 2018 07:47
convert image (ICO, GIF, PNG, JPG and etc) to C array
import sys
from PIL import Image
if len(sys.argv) != 3:
print('Usage: python {} image.gif array.c'.format(sys.argv[0]))
sys.exit(1)
im = Image.open(sys.argv[1])
@xiongyihui
xiongyihui / ubuntu-cli-install-android-sdk.sh
Created September 9, 2017 03:12 — forked from zhy0/ubuntu-cli-install-android-sdk.sh
Install Android SDK on headless Ubuntu linux machine via command line, so that you can compile open source Android apps.
#!/bin/bash
# Thanks to https://gist.github.com/wenzhixin/43cf3ce909c24948c6e7
# Execute this script in your home directory. Lines 17 and 21 will prompt you for a y/n
# Install Oracle JDK 8
add-apt-repository ppa:webupd8team/java
apt-get update
apt-get install -y oracle-java8-installer
apt-get install -y unzip make # NDK stuff
@xiongyihui
xiongyihui / CMakeLists.txt
Created February 10, 2017 09:44
Using WebRTC Audio Processing Module
cmake_minimum_required(VERSION 2.8)
project(webrtc-audio-processing)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
add_definitions("-DWEBRTC_LINUX -DWEBRTC_POSIX -DWEBRTC_NS_FLOAT")
#-DWEBRTC_UNTRUSTED_DELAY
include_directories(
@xiongyihui
xiongyihui / detect_linux_drive_change.py
Last active May 25, 2016 02:39
drive detection on linux and windows
#!/usr/bin/python2
# Using dbus to detect new drive on linux
# Install dependences: sudo apt-get install python-dbus python-gobject
import dbus
import glib
from dbus.mainloop.glib import DBusGMainLoop
def handle_new_drive(sender, mount_id, data):
mounted_path = data[5][7:]
@xiongyihui
xiongyihui / fix_checksum.sh
Created December 10, 2015 10:01
fix vector checksum value for NXP LPC1xxx Microcontroller
#!/bin/bash
#
# fix vector checksum value for NXP LPc1xxx
#
if [ $# != 1 ]; then
echo "Usage: $0 firmware.bin"
exit 1
fi
@xiongyihui
xiongyihui / beaglebone_green_test.py
Created March 31, 2015 06:53
To test BeagleBone Green
'''
BeagleBone Green Test
apt-get install build-essential python-dev python-setuptools python-pip python-smbus -y
pip install Adafruit_BBIO
'''
import Adafruit_BBIO.GPIO as GPIO
@xiongyihui
xiongyihui / k_type_tc_table.c
Created March 3, 2015 07:11
K type thermocouple conversion table - Celsius
// K type thermocouple conversion table - Celsius
// from -270 to 1372
const float k_type_tc_table[] = {
/* ˚C -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 ˚C */
/* -260 */ -6.458, -6.457, -6.456, -6.455, -6.453, -6.452, -6.45, -6.448, -6.446, -6.444,
/* -250 */ -6.441, -6.438, -6.435, -6.432, -6.429, -6.425, -6.421, -6.417, -6.413, -6.408,
/* -240 */ -6.404, -6.399, -6.393, -6.388, -6.382, -6.377, -6.37, -6.364, -6.358, -6.351,
/* -230 */ -6.344, -6.337, -6.329, -6.322, -6.314, -6.306, -6.297, -6.289, -6.28, -6.271,
/* -220 */ -6.262, -6.252, -6.243, -6.233, -6.223, -6.213, -6.202, -6.192, -6.181, -6.17,
/* -210 */ -6.158, -6.147, -6.135, -6.123, -6.111, -6.099, -6.087, -6.074, -6.061, -6.048,
#!/usr/bin/env python
import sys, serial
import numpy as np
from collections import deque
from matplotlib import pyplot as plt
# class that holds data for N samples
class DataPoll:
# constr