0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

概要

TunerStudioを、究める。
一から、iniファイルを作ってみる。
ダッシュボードのゲージが全部動く、プログラム。
poll使ってみる。

写真

image.png

ダッシュボードのゲージが全部動く、プログラム。

import time
import sys
import math
import struct
import uselect

signature = 'MShift v0.01'

def get_outputs():
	t = time.ticks_ms()
	sin_fast = math.sin(t * 2.0)
	sin_slow = math.sin(t * 0.63)
	rpm = max(0, int(3000 + sin_slow * 2000))
	tdc = float(10.0 + sin_fast * 10.0)
	ign = float(25.0 + sin_slow * 15.0)
	dwell = float(3.5 + sin_fast * 0.5)
	inj_ang = 90.0
	inj_dur = float(7.0 + sin_slow * 5.0)
	air = 0
	clt = int(500 + sin_slow * 100)
	tps = int(512 + sin_slow * 511)
	map_raw = int(400 + sin_slow * 300)
	batt = int(835 + sin_fast * 65)
	o2 = 0
	status = 0b00100001 if (int(t) % 2 == 1) else 0b00000100
	return struct.pack('<HfffffHHHHHHH', rpm, tdc, ign, dwell, inj_ang, inj_dur, air, clt, tps, map_raw, batt, o2, status)

poll = uselect.poll()
poll.register(sys.stdin, uselect.POLLIN)

while True:
	if poll.poll(100):
		input_byte = sys.stdin.buffer.read(1)
		if input_byte == b'F':
			print(signature, end='')
		elif input_byte == b'C':
			print(signature, end='')
		elif input_byte == b'O':
			data_block = get_outputs()
			sys.stdout.buffer.write(data_block)



以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?