Skip to content

Instantly share code, notes, and snippets.

@mcorrigan
mcorrigan / main.py
Created October 4, 2024 14:58
Advanced User Input Method
import sys
import tty
import termios
def user_input(prompt, default = None, sensitive = False, ret_type = str, required = True):
prompt_default = default
# if they provided a default, the input cannot be required
if default is not None:
required = False
@mcorrigan
mcorrigan / Microsoft.PowerShell_profile.ps1
Created June 3, 2024 14:41
vi and nano in Powershell (using WSL under)
function vi ($File){
$File = $File -replace "\\", "/" -replace " ", "\ "
bash -c "vi $File"
}
function nano ($File){
$File = $File -replace "\\", "/" -replace " ", "\ "
bash -c "nano $File"
}
@mcorrigan
mcorrigan / main.cpp
Last active November 28, 2023 22:40
Test Optidrive E3 Modbus RTU
#include <Arduino.h>
#include <ModbusMaster.h>
#define MAX485_DE_RE 4
ModbusMaster node;
void preTransmission()
{
digitalWrite(MAX485_DE_RE, HIGH);
@mcorrigan
mcorrigan / main.cpp
Last active November 10, 2023 20:14
Arduino Invertek Optidrive E3 VFD ModbusMaster Test
#include <Arduino.h>
#include <ModbusMaster.h>
#define MAX485_DE_RE 4
#define OUTPUT_MOTOR_FREQ 0x0007
#define DRIVE_STATUS 0x0006
#define DRIVE_TEMP 0x0018
ModbusMaster node;
@mcorrigan
mcorrigan / lolin_c3_pico.json
Last active November 19, 2024 02:50
Lolin ESP32-C3 PlatformIO Board
{
"build": {
"arduino": {
"ldscript": "esp32c3_out.ld"
},
"core": "esp32",
"extra_flags": [
"-DARDUINO_LOLIN_C3_PICO",
"-DARDUINO_USB_MODE=1",
"-DARDUINO_USB_CDC_ON_BOOT=1"
@mcorrigan
mcorrigan / Animator.cpp
Last active November 15, 2022 23:30
(Non-blocking) Sequence Animator for OLED "0.96 - SSD1306
#include <Arduino.h>
#include "Animator.h"
Animator::Animator(){
// nothing for now
}
void Animator::begin(Adafruit_SSD1306 *display, unsigned int width, unsigned int height, HardwareSerial* serial){
_display = display;
_stream = serial;
@mcorrigan
mcorrigan / campi_ascii.py
Last active November 20, 2023 19:09
Preview Raspberry Pi Camera via Color ASCII Preview [for headless Pi]
from picamera import PiCamera
from picamera.array import PiRGBArray
import sys, curses, time, cv2
import numpy as np
import warnings
import collections
# TODO: resolve these at some point
warnings.filterwarnings(action='ignore', message='Mean of empty slice')
warnings.filterwarnings(action='ignore', message='invalid value encountered in double_scalars')
@mcorrigan
mcorrigan / pos_text.h
Last active September 13, 2023 03:45
Position text oled SSD1306 Arduino
void displayPositionedText(char* buf, int textSize, Position vpos, Position hpos) {
display.setTextSize(textSize);
int16_t x1, y1;
uint16_t w, h;
display.getTextBounds(buf, 0, 0, &x1, &y1, &w, &h);
int _vpos = 0, _hpos = 0;
switch (vpos) {
case CENTER:
@mcorrigan
mcorrigan / chutes_and_ladders.html
Last active July 27, 2022 03:04
A Quick Fully Computerized Game of Chutes and Ladders (Since its totally random)
<!-- this was just a rapid development program for fun -->
<html>
<body>
<h1>Chutes and Ladders!</h1>
<button onclick="beginGame()">Play Game</button>
<img src="https://thumbs.dreamstime.com/z/s-board-games-chutes-ladders-woodbridge-new-jersey-october-circa-game-shown-128701391.jpg" />
<script>
// general configs
var spin_min = 1, spin_max = 6;
var exact_space_win = true;
@mcorrigan
mcorrigan / toggle_headless.py
Last active July 14, 2022 02:15
SteamVR Headless Mode Toggle Python Script
#!python
# coding: utf-8
# This is a simple script to quickly switch between HMD mode and headless mode with Vive in SteamVR
# It uses symlinks to ensure that SteamVR will continue to run and always preserves the original files,
# This should be able to be rerun following updates (assuming the configs haven't structurally changes
# along with anything else) -- symlinks require running with elevated priviledges
import sys, os, ctypes, time, json, shutil
from winreg import QueryValueEx, HKEY_CURRENT_USER, OpenKey