Skip to content

Instantly share code, notes, and snippets.

View cnlohr's full-sized avatar

CNLohr cnlohr

View GitHub Profile
@cnlohr
cnlohr / tensigral_lamp touch.c
Last active March 13, 2020 18:47
Example of using software-defined touch buttons on the STM32F042.
#include "touch.h"
#include "systems.h"
uint8_t touch_calib[3];
uint8_t done_startup;
//DO_PD means we use the internal pull-down resistors to measure the capacitance
//if we define this to be 0, then it will use the internal pull-up resistors.
//I am still experimenting with both options to see which is better overall and
//in a lot of situations.
@cnlohr
cnlohr / forgot_to_check_out_with_recurse_submodules.md
Last active April 22, 2024 12:13
Git forgot to clone recursively (forgot to check out with recurse submodules)
@cnlohr
cnlohr / .txt
Created October 19, 2020 06:29
How to dynamically test hdmi_timings with Raspberry Pi
Having a hard time getting the timings you want working? Try this.
config.txt:
Then execute this command (or put it in rc.local)
vcgencmd hdmi_timings 2880 0 55 10 55 1600 0 30 6 570 0 0 0 90 0 593000000 3 && tvservice -e "DMT 87" && tvservice -s
@cnlohr
cnlohr / gist:1979b6d1b52d3724ef64d6e706420b8a
Last active November 13, 2020 16:22
Issue with rendering order in HTML
@cnlohr
cnlohr / hlsl
Last active December 11, 2020 14:50
Really fast HLSL perlin-like noise (but it does repeat)
// QuickNoise -> Extremely fast noise that does repeat, but "feels" like
// perlin noise. Rewritten to avoid license issues.
//
// The original version of this noise is restrictively licensed. Code was
// re-written for HLSL 2020 <>< CNLohr, code henseforth may be liberally
// licensed under MIT-X11, NewBSD or Any Creative Commons License including
// CC0.
//
// There was also a bug in the version by stubbe which caused a migration in
// x/y/z when there was an applied w value. The matrix undoes the migration
@cnlohr
cnlohr / battery_monitor_overlay.c
Last active November 19, 2023 00:10
How to make a monitor overlay in OpenVR in C
// Battery Watcher for OpenVR (make an overlay with the battery left for all connected devices on your left hand)
//
// Compile with:
// tcc battery_monitor_overlay.c -o bmo.exe -luser32 -lgdi32 -lkernel32 -lopengl32 C:\windows\system32\msvcrt.dll openvr_api.dll
// System headers for any extra stuff we need.
#include <stdbool.h>
// Include CNFG (rawdraw) for generating a window and/or OpenGL context.
#define CNFG_IMPLEMENTATION
@cnlohr
cnlohr / CNLohr's Guide for Windows C Apps in 2021.md
Last active November 14, 2022 04:48
How to Set Up a Windows Computer to Write C applications in 2021

Building C apps on Windows in 2021

This document was written on April 3, 2021. The procedure may change over time. This is a companion gist to the youtube video here, where I go through every step of both options

Youtube Version Of This Document

@cnlohr
cnlohr / usingtimer14onstm32f042.md
Last active April 7, 2021 03:36
Using Timer 14 on the STM32F042
	void Setup()
	{
		RCC->APB1ENR |= RCC_APB1ENR_TIM14EN;
		TIM14->PSC = 48-1; //Counts up in microseconds
		TIM14->ARR = 65535;
		TIM14->CNT = 0;
		TIM14->CR1 = 1;
		TIM14->DIER = TIM_DIER_CC2IE | TIM_DIER_UIE;
 
@cnlohr
cnlohr / perfeater.shader
Last active May 22, 2021 22:10
perfeater - to keep your GPU busy in unity so you can do timing measurements in renderdoc or nsight.
Shader "Unlit/PerfEat"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
@cnlohr
cnlohr / raw_packet_read_write.c
Last active March 19, 2024 20:35
Read/write raw packets in C in Linux
//Based on https://github.com/cnlohr/lamenet/blob/master/librawp.c
#include <stdio.h>
#include <arpa/inet.h>
#include <string.h>
#include <linux/if_packet.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/ether.h>