Skip to content

Instantly share code, notes, and snippets.

View nmwilk's full-sized avatar

Neil Wilkinson nmwilk

View GitHub Profile
#include <BleGamepad.h> // https://github.com/lemmingDev/ESP32-BLE-Gamepad
#include <Encoder.h> // Encoder - by Paul Stoffregen
BleGamepad bleGamepad("SimWheel");
#define TIME unsigned int
#define ENCODER_PULSES_PER_STEP 2
#define numOfRotaryButtons 10 // 5 rotaries x 2 (rotate left and right)
#define numOfhc165 3
#define dataWidth numOfhc165 * 8
#define BUF_SIZE 64
char simHubMessageBuf[BUF_SIZE];
RGBDigit rgbDigit(1, <your-pin-here>);
char gear = '-';
void setup() {
Serial.begin(115200);
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
#define BUF_SIZE 64
char simHubMessageBuf[BUF_SIZE];
BluetoothSerial btSerial;
#define BytesValT unsigned int
#define numOfRotaryButtons 10
#define numOfhc165 3
#define dataWidth numOfhc165 * 8
#define pulseWidthUSec 5
byte previousButtonStates[dataWidth];
byte currentButtonStates[dataWidth];
@nmwilk
nmwilk / bt_leds_simhub.ino
Created February 21, 2021 14:27
Example of shows WS2812 leds using ESP32 over Bluetooth with SimHub.
#include "BluetoothSerial.h"
#include <FastLED.h>
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
#define BUF_SIZE 64
#define REV_LIGHTS_COUNT 8
#include <FastLED.h>
#define LED_COUNT 10
CRGB leds[LED_COUNT];
int lastPot = -100;
float col[3];
void setup() {
@nmwilk
nmwilk / map.dart
Created June 2, 2020 09:20
Easy sorting of maps by value
/// Usage
/// foos.sortedBy((it) => it.bar);
extension MapExt<T, U> on Map<T, U> {
Map<T, U> sortedBy(Comparable value(U u)) {
final entries = this.entries.toList();
entries.sort((a, b) => value(a.value).compareTo(value(b.value)));
return Map<T, U>.fromEntries(entries);
}
}
@nmwilk
nmwilk / TestTools.kt
Created January 19, 2018 13:46
Use in Espresso tests to wait for the idle state.
import android.support.test.InstrumentationRegistry
import java.util.concurrent.CountDownLatch
fun waitForIdle(errorMessage: String) {
val countDownLatch = CountDownLatch(1)
InstrumentationRegistry.getInstrumentation().waitForIdle { countDownLatch.countDown() }
try {
countDownLatch.await()
} catch (e: InterruptedException) {
@nmwilk
nmwilk / IntentExtensions.kt
Created January 30, 2017 08:37
Example of using Kotlin extension functions to reduce boilerplate when dealing with Android Intents.
package com.carte_app.carte.util
import android.content.Intent
fun Intent.addLocation(location: Location): Intent {
putExtra(IntentExtensions.INTENT_PARAM_LOCATION_LAT, location.lat)
putExtra(IntentExtensions.INTENT_PARAM_LOCATION_LNG, location.lng)
return this
}
@nmwilk
nmwilk / observeOnMainSubscribeOnIO.kt
Last active January 25, 2017 11:50
Encapsulation of typical subscribeOn() observeOn() for composition - Android RxJava
/**
* Allows reuse of typical subscribeOn & observeOn scheduling.
*/
fun <T> applyIOMainSchedulers(): Observable.Transformer<T, T> {
return Observable.Transformer { observable ->
observable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
}
}