From 53c51f1d16b40fdd3e68a6afc5844917d3d58640 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Sun, 28 Apr 2019 09:42:16 +1000 Subject: A better new_project.sh (#5191) * A better new_project.sh * Fix docstrings * Use single quotes for anything not shown to user * Missed this docstring * Simplify get_git_username() Thanks @vomindoraan * chmod +x * Add docstring for print_error() * Break up git username call into multiple lines * Use with statement here * Conform to PEP 8 even more * Turn it back into a shell script * chmod +x again * Update docs to reflect new keyboard generator usage * Tweak wording slightly * Trim trailing whitespace * Don't actually need to escape the newlines here * As I suspected, you can pass shift a number * Prepend ./ to match the other code block * Minor syntax tweaks * The username token has changed * Replace name in the readme too * Make some reasonable assumptions about the presence of Git --- util/new_keyboard.sh | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++ util/new_project.sh | 70 ----------------------- 2 files changed, 159 insertions(+), 70 deletions(-) create mode 100755 util/new_keyboard.sh delete mode 100755 util/new_project.sh (limited to 'util') diff --git a/util/new_keyboard.sh b/util/new_keyboard.sh new file mode 100755 index 0000000000..e9ce309784 --- /dev/null +++ b/util/new_keyboard.sh @@ -0,0 +1,159 @@ +#!/bin/bash + +# This script generates a new keyboard directory under keyboards/, +# and copies the template files from quantum/template/ into it. + +# Print an error message with the word "ERROR" in red. +echo_error() { + echo -e "[\033[0;91mERROR\033[m]: $1" +} + +# Print a message in bold. +echo_bold() { + echo -e "\033[1m$1\033[m" +} + +# Prompt the user for information, showing the default value in brackets. +prompt() { + local message="$1" + local default="$2" + + [ -n "$default" ] && message+=" [$default]" + message+=": " + + read -rp "$message" prompt_return + [ -z "$prompt_return" ] && prompt_return="$default" +} + +# Grab a username from Git config. +set_git_username() { + git_username="$(git config --get user.name)" +} + +# Copy the template files to the new keyboard directory. +copy_templates() { + echo -n "Copying base template files..." + cp -r "quantum/template/base" "${keyboard_dir}" + echo " done" + + echo -n "Copying $keyboard_type template files..." + cp -r "quantum/template/${keyboard_type}/." "${keyboard_dir}" + echo " done" + + echo -n "Renaming keyboard files..." + mv "${keyboard_dir}/template.c" "${keyboard_dir}/${keyboard_name}.c" + mv "${keyboard_dir}/template.h" "${keyboard_dir}/${keyboard_name}.h" + echo " done" +} + +# Set the inplace editing parameter for sed. +# macOS/BSD sed expects a file extension immediately following -i. +set_sed_i() { + sed_i=(-i) + + case $(uname -a) in + *Darwin*) sed_i=(-i "") + esac +} + +# Replace a token with a value in the given list of files. +replace_placeholders() { + local replace_token="$1" + local replace_value="$2" + shift 2 + local replace_filenames=("$@") + + echo -n "Replacing $replace_token with $replace_value..." + for replace_filename in "${replace_filenames[@]}"; do + sed "${sed_i[@]}" -e "s/${replace_token}/${replace_value}/g" "$replace_filename" + done + echo " done" +} + +# Replace %KEYBOARD% with the keyboard name. +replace_keyboard_placeholders() { + local replace_keyboard_filenames=( + "${keyboard_dir}/config.h" + "${keyboard_dir}/readme.md" + "${keyboard_dir}/${keyboard_name}.c" + "${keyboard_dir}/keymaps/default/readme.md" + ) + replace_placeholders "%KEYBOARD%" "$keyboard_name" "${replace_keyboard_filenames[@]}" +} + +# Replace %YOUR_NAME% with the username. +replace_name_placeholders() { + local replace_name_filenames=( + "${keyboard_dir}/config.h" + "${keyboard_dir}/readme.md" + "${keyboard_dir}/${keyboard_name}.c" + "${keyboard_dir}/${keyboard_name}.h" + "${keyboard_dir}/keymaps/default/config.h" + "${keyboard_dir}/keymaps/default/keymap.c" + ) + replace_placeholders "%YOUR_NAME%" "$username" "${replace_name_filenames[@]}" +} + +# Check if an array contains an element. +array_contains() { + local e match="$1" + shift + for e; do + [[ "$e" == "$match" ]] && return 0; + done + + return 1 +} + +# If we've been started from util/, we want to be in qmk_firmware/ +[[ "$PWD" == *util ]] && cd .. + +# The root qmk_firmware/ directory should have a subdirectory called quantum/ +if [ ! -d "quantum" ]; then + echo_error "Could not detect the QMK firmware directory!" + echo_error "Are you sure you're in the right place?" + exit 1 +fi + +echo_bold "Generating a new QMK keyboard directory" +echo + +# Keyboard name is required, so keep prompting until we get one +while [ -z "$keyboard_name" ]; do + prompt "Keyboard Name" "" + keyboard_name=$prompt_return +done + +keyboard_dir="keyboards/$keyboard_name" + +if [ -d "$keyboard_dir" ]; then + echo_error "Keyboard $keyboard_name already exists!" + exit 1 +fi + +KEYBOARD_TYPES=("avr" "ps2avrgb") + +prompt "Keyboard Type" "avr" +keyboard_type=$prompt_return + +if ! array_contains "$keyboard_type" "${KEYBOARD_TYPES[@]}"; then + echo_error "Keyboard type must be one of: ${KEYBOARD_TYPES[*]}" + exit 1 +fi + +set_git_username +prompt "Your Name" "$git_username" +username=$prompt_return + +echo + +copy_templates +set_sed_i +replace_keyboard_placeholders +[ -n "$username" ] && replace_name_placeholders + +echo +echo_bold "Created a new keyboard called $keyboard_name." +echo +echo_bold "To start working on things, cd into keyboards/$keyboard_name," +echo_bold "or open the directory in your favourite text editor." diff --git a/util/new_project.sh b/util/new_project.sh deleted file mode 100755 index 9dec714b02..0000000000 --- a/util/new_project.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/sh -# Script to make a new quantum project -# Jack Humbert 2015 - -KEYBOARD=$1 -KEYBOARD_TYPE=$2 - -if [ -z "$KEYBOARD" ]; then - echo "Usage: $0 " - echo "Example: $0 gh60 avr" - echo "Example: $0 bfake ps2avrgb" - exit 1 -elif [ -z "$KEYBOARD_TYPE" ]; then - KEYBOARD_TYPE=avr -fi - -if [ "$KEYBOARD_TYPE" != "avr" ] && [ "$KEYBOARD_TYPE" != "ps2avrgb" ]; then - echo "Invalid keyboard type target" - exit 1 -fi - -if [ -e "keyboards/$1" ]; then - echo "Error! keyboards/$1 already exists!" - exit 1 -fi - -cd "$(dirname "$0")/.." || exit - -KEYBOARD_NAME=$(basename "$1") -KEYBOARD_NAME_UPPERCASE=$(echo "$KEYBOARD_NAME" | awk '{print toupper($0)}') -NEW_KBD=keyboards/${KEYBOARD} - - -cp -r quantum/template/base "$NEW_KBD" -cp -r "quantum/template/$KEYBOARD_TYPE/." "$NEW_KBD" - -mv "${NEW_KBD}/template.c" "${NEW_KBD}/${KEYBOARD_NAME}.c" -mv "${NEW_KBD}/template.h" "${NEW_KBD}/${KEYBOARD_NAME}.h" -find "${NEW_KBD}" -type f -exec sed -i '' -e "s;%KEYBOARD%;${KEYBOARD_NAME};g" {} \; -find "${NEW_KBD}" -type f -exec sed -i '' -e "s;%KEYBOARD_UPPERCASE%;${KEYBOARD_NAME_UPPERCASE};g" {} \; - -GIT=$(whereis git) -if [ "$GIT" != "" ]; then - IS_GIT_REPO=$($GIT log >>/dev/null 2>&1; echo $?) - if [ "$IS_GIT_REPO" -eq 0 ]; then - ID="$($GIT config --get user.name)" - read -rp "What is your name? [$ID] " YOUR_NAME - if [ -n "$YOUR_NAME" ]; then - ID=$YOUR_NAME - fi - echo "Using $ID as user name" - - for i in "$NEW_KBD/config.h" \ - "$NEW_KBD/$KEYBOARD_NAME.c" \ - "$NEW_KBD/$KEYBOARD_NAME.h" \ - "$NEW_KBD/keymaps/default/config.h" \ - "$NEW_KBD/keymaps/default/keymap.c" - do - awk -v id="$ID" '{sub(/%YOUR_NAME%/,id); print}' < "$i" > "$i.$$" - mv "$i.$$" "$i" - done - fi -fi - -cat <<-EOF -###################################################### -# $NEW_KBD project created. To start -# working on things, cd into $NEW_KBD -###################################################### -EOF -- cgit v1.2.3 From 3da8d46a07167fc862e90b6bb232812d5cb64651 Mon Sep 17 00:00:00 2001 From: Takeshi ISHII <2170248+mtei@users.noreply.github.com> Date: Thu, 2 May 2019 23:59:29 +0900 Subject: If RGBLIGHT_EFFECT_BREATHE_CENTER is undefined, use fixed breathe table instead of exp() and sin() (#5484) * If RGBLIGHT_EFFECT_BREATHE_CENTER is undefined, use fixed breathe table instead of exp() and sin() * Change rgblight breathing table size to be easily selectable. add RGBLIGHT_BREATHE_TABLE_SIZE macro for customize breathing effect. --- util/rgblight_breathing_table_calc.c | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 util/rgblight_breathing_table_calc.c (limited to 'util') diff --git a/util/rgblight_breathing_table_calc.c b/util/rgblight_breathing_table_calc.c new file mode 100644 index 0000000000..fc4d49ea58 --- /dev/null +++ b/util/rgblight_breathing_table_calc.c @@ -0,0 +1,49 @@ +// +// calculate rgblight_effect_breathe_table[] values +// +// this is host program for quantum/rgblight.c:void rgblight_effect_breathing(); +// +// example: +// $ edit util/rgblight_breathing_table_calc.c +// $ cc -o util/rgblight_breathing_table_calc util/rgblight_breathing_table_calc.c +// $ ./util/rgblight_breathing_table_calc > keyboards/KEYBOARD_NAME/keymaps/KEYMAP_NAME/rgblight_breathe_table.h +// +#include +#include +#include + +/// customize breeathing effect part /////////////////////////// +#define RGBLIGHT_EFFECT_BREATHE_CENTER 1.85 // 1 to 2.7 +#define RGBLIGHT_EFFECT_BREATHE_MAX 255 // 0 to 255 +//////////////////////////////////////////////////////////////// + +int main(void) { + int pos, step; + int table[256]; + for (pos = 0; pos < 256; pos ++ ) { + table[pos] = (uint8_t)( + (exp(sin((pos/255.0)*M_PI))- RGBLIGHT_EFFECT_BREATHE_CENTER/M_E) + * (RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E)) + ); + } + printf("#ifndef RGBLIGHT_EFFECT_BREATHE_TABLE\n"); + printf("#define RGBLIGHT_EFFECT_BREATHE_TABLE\n\n"); + printf("const uint8_t rgblight_effect_breathe_table[] PROGMEM = {\n"); + printf(" /* #define RGBLIGHT_EFFECT_BREATHE_CENTER %.2f */\n", RGBLIGHT_EFFECT_BREATHE_CENTER); + printf(" /* #define RGBLIGHT_EFFECT_BREATHE_MAX %d */\n", RGBLIGHT_EFFECT_BREATHE_MAX); + + for (int s = 0, step = (1<=256?"":"," ); + if ((pos+step) % 8 == 0) + printf("\n"); + } + printf(" #endif /* %d bytes table */\n", s == 0 ? 256:(s== 1 ? 128: 64)); + } + printf("};\n"); + printf("\nstatic const int table_scale = 256/sizeof(rgblight_effect_breathe_table);\n"); + printf("\n#endif /* RGBLIGHT_EFFECT_BREATHE_TABLE */\n"); + return 0; +} -- cgit v1.2.3 From e73587cfd08b2bd73987e7f762194079875df93a Mon Sep 17 00:00:00 2001 From: Robin Hallabro-Kokko <44033026+hallabro@users.noreply.github.com> Date: Sat, 4 May 2019 00:41:39 +0000 Subject: docker_build.sh: Docker requires access to hosts devices (#5063) * docker_build.sh: Docker requires access to hosts devices This also runs the container interactively which allows the user to interupt the build with Ctrl-C. * docker_build.sh: Mount /dev via $usb_args instead --- util/docker_build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util') diff --git a/util/docker_build.sh b/util/docker_build.sh index e7aeac8f3e..c573ebcae2 100755 --- a/util/docker_build.sh +++ b/util/docker_build.sh @@ -35,7 +35,7 @@ else fi if [ -n "$target" ]; then if [ "$(uname)" = "Linux" ] || docker-machine active >/dev/null 2>&1; then - usb_args="--privileged -v /dev/bus/usb:/dev/bus/usb" + usb_args="--privileged -v /dev:/dev" else echo "Error: target requires docker-machine to work on your platform" >&2 echo "See http://gw.tnode.com/docker/docker-machine-with-usb-support-on-windows-macos" >&2 -- cgit v1.2.3 From 99500243e10c12c0a5005da49aa1986947b27153 Mon Sep 17 00:00:00 2001 From: skullydazed Date: Mon, 6 May 2019 10:56:34 -0700 Subject: Make python a required build dependency (#5784) * Make python a required build dependency * Add missing color * fixup sabayon linux per @BlitzKraft --- util/freebsd_install.sh | 3 ++- util/linux_install.sh | 9 ++++++++- util/macos_install.sh | 2 +- util/msys2_install.sh | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) (limited to 'util') diff --git a/util/freebsd_install.sh b/util/freebsd_install.sh index 25ea80a7fc..c8696e8cc7 100755 --- a/util/freebsd_install.sh +++ b/util/freebsd_install.sh @@ -15,4 +15,5 @@ pkg install -y \ arm-none-eabi-gcc \ arm-none-eabi-binutils \ arm-none-eabi-newlib \ - diffutils + diffutils \ + python3 diff --git a/util/linux_install.sh b/util/linux_install.sh index 608975a915..5e2afe9998 100755 --- a/util/linux_install.sh +++ b/util/linux_install.sh @@ -25,6 +25,7 @@ if grep ID /etc/os-release | grep -qE "fedora"; then kernel-headers \ make \ perl \ + python3 \ unzip \ wget \ zip @@ -47,6 +48,7 @@ elif grep ID /etc/os-release | grep -qE 'debian|ubuntu'; then gcc-avr \ git \ libnewlib-arm-none-eabi \ + python3 \ unzip \ wget \ zip @@ -66,6 +68,7 @@ elif grep ID /etc/os-release | grep -q 'arch\|manjaro'; then diffutils \ gcc \ git \ + python \ unzip \ wget \ zip @@ -87,6 +90,7 @@ elif grep ID /etc/os-release | grep -q gentoo; then app-arch/zip \ app-mobilephone/dfu-util \ dev-embedded/avrdude \ + dev-lang/python:3.5 \ net-misc/wget \ sys-devel/gcc \ sys-devel/crossdev @@ -102,6 +106,7 @@ elif grep ID /etc/os-release | grep -q sabayon; then app-arch/zip \ app-mobilephone/dfu-util \ dev-embedded/avrdude \ + dev-lang/python \ net-misc/wget \ sys-devel/gcc \ sys-devel/crossdev @@ -125,6 +130,7 @@ elif grep ID /etc/os-release | grep -qE "opensuse|tumbleweed"; then dfu-tool \ dfu-programmer \ gcc \ + python3 \ unzip \ wget \ zip @@ -143,7 +149,8 @@ elif grep ID /etc/os-release | grep -q slackware; then dfu-util \ arm-binutils \ arm-gcc \ - newlib + newlib \ + python3 echo "Done!" else echo "Quitting..." diff --git a/util/macos_install.sh b/util/macos_install.sh index d2629a8cb4..93f3ed0b96 100755 --- a/util/macos_install.sh +++ b/util/macos_install.sh @@ -22,5 +22,5 @@ fi brew tap osx-cross/avr brew tap PX4/homebrew-px4 brew update -brew install avr-gcc@7 gcc-arm-none-eabi dfu-programmer avrdude dfu-util +brew install avr-gcc@7 gcc-arm-none-eabi dfu-programmer avrdude dfu-util python3 brew link --force avr-gcc@7 diff --git a/util/msys2_install.sh b/util/msys2_install.sh index fcb4882494..bcb628ab21 100755 --- a/util/msys2_install.sh +++ b/util/msys2_install.sh @@ -7,7 +7,7 @@ armtools=gcc-arm-none-eabi installflip=false echo "Installing dependencies needed for the installation (quazip)" -pacman --needed -S msys/unzip msys/p7zip base-devel msys/git mingw-w64-x86_64-toolchain +pacman --needed -S base-devel mingw-w64-x86_64-toolchain msys/git msys/p7zip msys/python3 msys/unzip source "$dir/win_shared_install.sh" -- cgit v1.2.3