This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ui.h> // include protothread library | |
#define LEDPIN 13 // LEDPIN is a constant | |
uint16_t sub_time = 0; // subtracts time from LED periods | |
void toggleLED() { | |
boolean ledstate = digitalRead(LEDPIN); // get LED state | |
ledstate ^= 1; // toggle LED state using xor | |
digitalWrite(LEDPIN, ledstate); // write inversed state back |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum MYTHREADS{ | |
LED1, | |
LED2 | |
}; | |
enum MYFUNCS{ | |
REINIT | |
}; | |
enum MYVARS{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This function can be called form the command line as "reinit" | |
// It resets all the settings. | |
uint8_t reinit(pthread *pt){ | |
thread *th; | |
// First we try to kill the threads. | |
// Note: TRY simply silences any error outputs. You still have to clear errors | |
// afterwards (if you don't clear errors, it can effect the next funciton call) | |
// Note: this also destroys all thread data. | |
TRY(set_thread_innactive(get_thread(LED1))); | |
clrerr(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Expose the things we want to access. | |
// Threads always need to be exposed if you want to schedule them | |
// Note: the order is important! | |
expose_threads(TH_T(blinky_thread), TH_T(blinky_thread)); // wrap threads in TH_T | |
expose_functions(UI_F(reinit)); // Wrap functions in UI_F | |
UI_V(v1, sub_time); // Variables have to be declared specially. Declare variable names first with UI_V | |
//UI_V(v2, othervar) -- if you had more variables, continue in this way | |
expose_variables(UI_VA(v1)); // Then wrap the variable names in UI_VA. Alot of things have to be done to take up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From b5b44812c8928de1e7d1e3e2e1a31239b26f49b3 Mon Sep 17 00:00:00 2001 | |
From: Garrett Berg <gberg@neutral.io> | |
Date: Fri, 15 Aug 2014 11:55:20 -0600 | |
Subject: [PATCH] Arduino.mk | |
--- | |
Arduino.mk | 5 +++++ | |
1 file changed, 5 insertions(+) | |
diff --git a/Arduino.mk b/Arduino.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Better strncpy | |
* Example code: | |
* char buf[100]; | |
* uint16_t len = 100; | |
* char *place = buf; | |
* len = bstrncpy(&place, "hello\n", len); | |
* len = bstrncpy(&place, "another hi\n", len); | |
* input: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_timer(timer, duration = 1): | |
timer.enable() | |
time.sleep(1) | |
timer.disable() | |
print(timer.get_elapsed()) | |
timer = Timer() | |
test_timer(timer) | |
class Timer(object): | |
def __init__(self, time=time.time): | |
self.time = time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from enum import Enum | |
def enum(name, attrs=None): | |
'''enum generator function | |
Creates an Enum type. attrs can be: set, list, tuples or a dictionary. | |
The behavior is as follows: | |
- dictionaries and lists/tuples of the form [(name, key), (name2, key2), ...] will behave | |
as expected. (dictionaries will have their items() method called | |
- sets will be converted to zip(sorted(attrs), range(len(attrs))) | |
- lists/tuples without embeded tuples will do the same without sorting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python 3 | |
import os | |
import platform | |
import ctypes | |
import re | |
import subprocess | |
import psutil | |
def processor(): | |
'''Get type of processor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import imp | |
module = imp.find_module('path/to/module') | |
module = imp.load_module('module_name', *module) |
OlderNewer