Skip to content

Instantly share code, notes, and snippets.

@idt12312
idt12312 / rename_leading_number_selected.py
Last active August 8, 2021 16:50
This script is for KiCad. This renames leading reference number of selected components.
import pcbnew
import re
def _get_selected_modules():
modules = pcbnew.GetBoard().GetModules()
return filter(lambda m: m.IsSelected(), modules)
def _replace_leading_number(target, new):
match = re.search(r'[0-9]', target)
idx = match.start()
@idt12312
idt12312 / load_screen.py
Last active December 26, 2022 16:42
Save screen image of RIGOL MSO5000 series oscilloscope
import visa
import argparse
from PIL import Image
import io
argparser = argparse.ArgumentParser()
argparser.add_argument('-a', '--address', required=True, help='VISA address like "TCPIP::{ipaddress}::INSTR"')
argparser.add_argument('-o', '--output', help='Output file name (default: "screen.png")', default='screen.png')
args = argparser.parse_args()
@idt12312
idt12312 / save_as_csv.py
Last active October 19, 2023 16:18
Load waveform and save it as csv file for RIGOL MSO5000 series oscilloscope
import visa
import argparse
import csv
def load_waveform(chidx, points_request):
inst.write(f':WAV:SOUR CHAN{chidx}')
inst.write(':WAV:MODE RAW')
inst.write(f':WAV:POIN {points_request}')
inst.write(':WAV:FORM BYTE')
@idt12312
idt12312 / PIDController.h
Last active September 7, 2018 14:26
This is C++ implementation of MATLAB's 2DOF discrete time PID controller
#ifndef PIDCONTROLLER_H_
#define PIDCONTROLLER_H_
class PIDController
{
public:
struct Param
{
float P;
float I;
import kicad_tools
#抵抗とLEDを正規表現を使って検索し、リストにする
rList = kicad_tools.findModulesByRe("R\d+")
ledList = kicad_tools.findModulesByRe("D\d+")
#LEDを(100mm,100mm)を始点に(10mm,0)間隔で直線上に並べる
kicad_tools.arrangeInLine(ledList, (100,100), (10,0))
#抵抗を(100mm,150mm)を始点に3x4行列のように並べる
#R1を90度回転する
r1.SetOrientation(90*10)
#R1を(100mm, 100mm)に移動する
r1.SetPosition(pcbnew.wxPointMM(100,100))
#R1を現在位置から(50mm, 0mm)だけ移動する
r1.Move(pcbnew.wxPointMM(50,0))
import pcbnew
#pcbnewで開いている基板(BORAD)への参照を取得する
board = pcbnew.GetBoard()
#基板上の"R1"というリファレンスを持つ部品(MODULE)への参照を取得する
r1 = board.FindModuleByReference("R1")
#r1(MODULE)のもつリファレンスを文字列として取得する
print r1.GetReference()
@idt12312
idt12312 / TaskBase.h
Created February 1, 2017 04:49
FreeRTOSのタスクを楽に扱うクラス
#ifndef TASK_TASKBASE_H_
#define TASK_TASKBASE_H_
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
class TaskBase {
@idt12312
idt12312 / led_blink_systick.s
Last active December 25, 2016 07:41
アセンブリでSystickを使ってLチカをする : Nucleo STM32F103
@idt12312
idt12312 / led_blink.s
Last active December 25, 2016 06:51
アセンブリでLチカをする : Nucleo STM32F103