Skip to content

Instantly share code, notes, and snippets.

@projectgus
projectgus / gist:6016251
Created July 16, 2013 23:37
Simple mashup of the Arduino Ethernet WebServer example and the SD DumpFile example
/*
Web Server
A simple web server that sends the contents of "hello.txt" on the SD card
to any web client that connects.
Modified from the "Ethernet -> WebServer" & "SD -> DumpFile" Arduino examples
by Angus Gratton <[email protected]>
*/
@projectgus
projectgus / zombie_pv.py
Created November 8, 2012 22:13
Demonstration of callbacks coming from otherwise stale PV object
import epics, time
pvname = "c1v0:UPTIME"
def my_callback(value, **kw):
print value
def setup_callback():
pv = epics.PV(pvname)
pv.add_callback(my_callback)
@projectgus
projectgus / 1_pv_leak.py
Created November 8, 2012 22:04
Demonstration of pv reference leak
import epics,gc
name1 = "c1v0:UPTIME"
name2 = "c2v0:UPTIME"
name3 = "c3v0:UPTIME"
def report_usage():
epics.ca.show_cache()
# use the gc's debugging features to look for leaked PV objects
gc.collect()
@projectgus
projectgus / serial_mux.py
Created September 4, 2012 02:28
Quick serial port to tcp socket muxer
#!/usr/bin/env python
import argparse, serial, socket, select
parser = argparse.ArgumentParser(description='Connect to a serial port and allow multiple TCP clients to talk to it (simultaneous output shared between all TCP clients, any client can write to port.)')
parser.add_argument('--baud', help="Baud rate", default=115200, type=int)
parser.add_argument('port', help="Port to listen on.", type=int)
parser.add_argument('serial', help="Serial port to share.")
def main():
args = parser.parse_args()
@projectgus
projectgus / gist:1807319
Created February 12, 2012 08:31
openwrt-zipit 3.2 libertas problem
scripted as;
sleep 15
ifconfig wlan0 up &
sleep 10
dmesg > after.log
/sbin/poweroff
ie 'ifconfig wlan0 up' is run @ 82
// Big block of macros to access EEPROM data
#include <avr/eeprom.h>
#define eeprom_read_to(dst_p, eeprom_field, dst_size) eeprom_read_block(dst_p, (void *)offsetof(__eeprom_data, eeprom_field), MIN(dst_size, sizeof((__eeprom_data*)0)->eeprom_field))
#define eeprom_read(dst, eeprom_field) eeprom_read_to(&dst, eeprom_field, sizeof(dst))
#define eeprom_write_from(src_p, eeprom_field, src_size) eeprom_write_block(src_p, (void *)offsetof(__eeprom_data, eeprom_field), MIN(src_size, sizeof((__eeprom_data*)0)->eeprom_field))
#define eeprom_write(src, eeprom_field) { typeof(src) x = src; eeprom_write_from(&x, eeprom_field, sizeof(x)); }
#define MIN(x,y) ( x > y ? y : x )
#define KEYPAD_SIZE 5
@projectgus
projectgus / VAN_Monitor_Interrupts sketch
Created February 17, 2010 21:51
Arduino sketch to monitor a 125 kbps VAN automotive bus (similar to CAN bus)
#include <avr/interrupt.h>
const int pin_rx = 3; // Pin hooked to the output of the CAN transceiver
enum message_state { vacant, loading, ready };
const int ticksPerTs = 132; // 16Mhz clock / 125Kbps / 8 = 128 ticks/bit
const int timerLoadValue = 257 - ticksPerTs;
const int oneHalfTimerLoadValue = 257 - (ticksPerTs * 1.25); // Add an extra 1/4TS when we know we're at start of a bit