Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@brentpicasso
brentpicasso / RaceCapture_simple_Lua_CAN_bus_analyzer.lua
Last active April 22, 2022 21:24
Simple CAN bus analyzer for RaceCapture using Lua scripting
-- Simple CAN bus analyzer
-- This script is useful for reverse engineering CAN bus data
-- and detecting patterns.
--
-- Up to 100 individual 8 bit channels can be created. Additional channels will not be tracked.
-- CAN bus data will appear in the data stream with the channel name: <CAN ID>_<OFFSET>
-- Once script is running, you can monitor the data under Dashboard / Raw Channels View.
----------------------------------------
--Configuration
@brentpicasso
brentpicasso / RaceCapture_GPS_IMU_CAN_broadcast.lua
Created November 15, 2017 23:57
Broadcast GPS and IMU data over CAN bus
--This script broadcasts current GPS and IMU channels over CAN
setTickRate(20)
function sendCAN(can, id, data)
local res = txCAN(can, id, 0, data,100)
if res == 0 then println('send CAN res ' ..res) end
end
function split32(val)
return bit.band(val, 0xFF), bit.band(bit.rshift(val,8), 0xFF), bit.band(bit.rshift(val,16),0xFF),bit.band(bit.rshift(val,24),0xFF)
@brentpicasso
brentpicasso / tire_temperature_simulator.lua
Last active January 27, 2020 20:48
Simulated tire and brake temperature data based on g-force readings.
--Note, If 2.10.2 firmware, AccelX and AccelY need to be inverted in the RCP configuration.
tires = 4
tireZones = 4
tirePrefixes = {'TireTmpLF', 'TireTmpRF', 'TireTmpLR', 'TireTmpRR'}
tireValues = {}
tireIds = {}
minTireVal = 0
maxTireVal = 300
@brentpicasso
brentpicasso / e46_expanded_channels.lua
Last active January 26, 2020 18:12
E46 expanded channels using 2.8.7 firmware and bitOp library
--This example configured for E46 CAN
-- Automatically starts logging with engine 'on' (RPM triggered)
--how frequently we poll for CAN messages
tickRate = 30
--the CAN baud rate
CAN_baud = 500000
--CAN channel to listen on. 0=first CAN channel, 1=second
CAN_chan = 0
--add your virtual channels here
val = 0
-- transmit on CAN1 and receive on CAN2
function onTick()
--transmit value on CAN1
txCAN(0, 1234, 0, {val})
--receive on CAN2
id, e, data = rxCAN(1)
@brentpicasso
brentpicasso / car_overview_simulator.lua
Last active September 30, 2019 01:53
Simulated tire, brake temperature, TPMS and engine sensors. Tire and brake data based on g-force readings.
--Note, If 2.10.2 firmware, AccelX and AccelY need to be inverted in the RCP configuration.
tires = 4
tireZones = 4
tirePrefixes = {'TireTmpLF', 'TireTmpRF', 'TireTmpLR', 'TireTmpRR'}
tireValues = {}
tireIds = {}
minTireVal = 0
maxTireVal = 300
@brentpicasso
brentpicasso / pct_gsum_max_calculator.lua
Created June 17, 2019 16:37
Percentage of Max Gsum calculator
-- Calculates and tracks how much of your maximum grip you are using, in real-time
setTickRate(25)
maxGsumId = addChannel("MaxGsum", 25, 2, -2.0, 2.0)
pctGsumMaxId = addChannel("PctMaxGsum", 25, 0, 0, 100)
maxGsum = 0
function updateGsumStats()
local gsum = getChannel("Gsum")
if gsum ~= nil and gsum > 0 then
@brentpicasso
brentpicasso / shiftx3_controlling_secondary.lua
Last active April 16, 2019 22:10
ShiftX3 with control of alternate ShiftX2/3
setTickRate(30)
-- Set ShiftX3 configuration parameters with default parameters
-- orientation: 0=normal, 1=inverted (display above LED bar)
-- brightness: 0-100%, 0 = auto brightness
-- can bus: 0=CAN1, 1=CAN2
sxSetConfig(0,0,1)
--create gear channel
gearId = addChannel("Gear", 10, 0, 0, 6)
setTickRate(30)
-- Set ShiftX3 configuration parameters with default parameters
-- orientation: 0=normal, 1=inverted (display above LED bar)
-- brightness: 0-100%, 0 = auto brightness
-- can bus: 0=CAN1, 1=CAN2
sxSetConfig(0,0,1)
--config shift light
sxCfgLinearGraph(0,0,0,10000) --left to right graph, smooth style, 0 - 7000 RPM range
@brentpicasso
brentpicasso / gist:488a78d8f558c223e1634226dd8f07b6
Created February 12, 2019 23:38
iOS keep sleep timer from enabling
// Prevent sleep
[NSTimer scheduledTimerWithTimeInterval:2.0 repeats:YES block: ^(NSTimer * _Nonnull timer) {
[UIApplication sharedApplication].idleTimerDisabled = NO;
[UIApplication sharedApplication].idleTimerDisabled = YES;
NSLog(@"idle timer");
}];
NSLog(@"Initializing python");
Py_Initialize();