Skip to content

Instantly share code, notes, and snippets.

View blinkinglight's full-sized avatar
🏠
Working from home

M blinkinglight

🏠
Working from home
View GitHub Profile

This document describes the work-in-progress C API for writing custom chips for the Wokwi simulator.

Using the API

First, make sure to include wokwi-api.h. Every external method you declare should be wrapped with the EXPORT macro (e.g. void EXPORT(my_method_name) (uint32_t arg) { ... }). The chip should declare a chip_init method. This method will be called for every new instance of the chip. If the chip has some internal state, chip_init should allocate memory for the internal state and return a pointer to this memory. This pointer will be passed in the first argument for any listener that you declare (e.g. chip_pin_change). For chip without any internal state, simply return NULL.

Here's an example of a minimal chip file:

<?php
/**
* Lietuviškų vardų linksniai.
*
* @author Maug Lee <mauglee@gmail.com>
* @copyright Copyleft (ↄ) 2011, Maug Lee
* @version 0.3
* @package Vardai
*/
package main
import (
"log"
"runtime"
"time"
"github.com/nats-io/nats.go"
"github.com/nats-io/stan.go"
)
@blinkinglight
blinkinglight / start_docker_registry.bash
Created October 30, 2020 07:51 — forked from u1i/start_docker_registry.bash
Start docker registry with letsencrypt certificates and Basic Auth
#!/usr/bin/env bash
# install docker
# https://docs.docker.com/engine/installation/linux/ubuntulinux/
# install docker-compose
# https://docs.docker.com/compose/install/
# install letsencrypt
# https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04
/*
Copyright 2011 Martin Hawksey
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@blinkinglight
blinkinglight / example.sh
Last active September 26, 2020 16:13
git fetch branch and reset its contents
worker.bash /var/www/html/project1 devel
@blinkinglight
blinkinglight / MidpointLruCache.py
Created August 1, 2020 20:34 — forked from midom/MidpointLruCache.py
LRU with midpoint insertion (LRU2Q) cache decorator for Python
class MidpointLruCache:
def __init__(self, size, oldpercentage):
self.size = size
self.oldsize = size * oldpercentage / 100
self.youngsize = size * (100 - oldpercentage) / 100
self.youngitems = collections.OrderedDict()
self.olditems = collections.OrderedDict()
def __call__(self, func):
// only 1 sensor to test
const int led = 8;
const int echo = 3;
const int trig = 2;
const long wait = 1000; //cooldown time for the sensor
unsigned long last = 0;
@blinkinglight
blinkinglight / I2C_LCD_driver.py
Created April 5, 2020 12:59 — forked from IdrisCytron/I2C_LCD_driver.py
Raspberry Pi I2C LCD driver.
# -*- coding: utf-8 -*-
# i2c bus (0 -- original Pi, 1 -- Rev 2 Pi)
I2CBUS = 1
# LCD Address
ADDRESS = 0x27
import smbus
from time import sleep
@blinkinglight
blinkinglight / serve.go
Created February 23, 2020 14:38 — forked from pheuter/serve.go
go http streaming
package main
import (
"fmt"
"io"
"io/ioutil"
"strings"
"exec"
"http"
)