Skip to content

Instantly share code, notes, and snippets.

View Arachnid's full-sized avatar

Nick Johnson Arachnid

View GitHub Profile
from datetime import datetime, timedelta
import time
def check_sleep(func, amt):
start = datetime.now()
func(amt)
end = datetime.now()
delta = end-start
return abs(delta.seconds + delta.microseconds/1000000.0 - amt)
typedef void (*command_handler)(char*);
struct command_t {
char *command;
command_handler handler;
} commands[] = {
{"command1", func1},
{"command2", func2},
{NULL, NULL}
};
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import codecs
import csv
import itertools
import sys
country_codes = {
"AF": "AFGHANISTAN",
@Arachnid
Arachnid / parse.py
Last active December 29, 2015 07:49
class MessageHeader(object):
def __init__(self, priority, protocol):
self.priority = priority
self.protocol = protocol
self.sender = None
def decode(bits):
priority = bits.read('uint:2')
broadcast = bits.read('bool')
import bitstring
class StructValueError(Exception): pass
class Member(object):
creation_counter = 0
abstract = False
/*
* uCAN.h
*
* Created on: Dec 1, 2013
* Author: nick
*/
#ifndef UCAN_H_
#define UCAN_H_
uint8_t row_counts[4];
for(int row = 0; row < NUM_ROWS; row++)
for(int col = 0; col < NUM_COLUMNS; col++)
row_counts[row] += (scan[col] >> row) & 1;
for(int col = 0; col < NUM_COLUMNS; col++) {
uint8_t column_count = set_bits[scan[col]];
for(int row = 0; row < NUM_ROWS; row++) {
if(row_counts[row] > 1 && column_count > 1)
@Arachnid
Arachnid / main.c
Created December 21, 2013 13:08
Everything you need to bootload with an SCB UART in PSoC 4
void CyBtldrCommStart(void) {
UART_Start();
}
void CyBtldrCommStop (void) {
UART_Stop();
}
void CyBtldrCommReset(void) {
UART_SpiUartClearRxBuffer();
@Arachnid
Arachnid / main.c
Created December 21, 2013 13:12
Recovery mode bootloader
void main()
{
int i;
if(Bootloader_GET_RUN_TYPE == Bootloader_START_BTLDR)
Bootloader_Start();
for(i = 0; i < 2000; i++) {
uint8 status = Button_Read();
if(status)
// Maps current state (index) to next state for a forward transition.
const int8 quadrature_states[] = {0x1, 0x3, 0x0, 0x2};
CY_ISR(quadrature_event_isr) {
static int8 last_levels = 3;
static int8 count = 0;
int levels = Quadrature_Read();
Quadrature_ClearInterrupt();