예제 #1
0
파일: main.c 프로젝트: nytopop/alter-evic
// Collect runtime data.
void collectData() {
	// state
	ctx.state.firing = Atomizer_IsOn();
	ctx.state.error = Atomizer_GetError();

	// atomizer
	Atomizer_ReadInfo(&ctx.atomizer);

	// device
	ctx.device.temp = Atomizer_ReadBoardTemp();

	// coil
	ctx.coil.temp = readCoilTemp();
	// TODO lock resistance setting here
	if(!ctx.settings.lockRes)
		ctx.coil.baseRes = ctx.atomizer.baseResistance;
		//ctx.coil.baseRes = 377;

	// battery
	ctx.battery.volts = Battery_GetVoltage();
	if(!ctx.state.firing)
		ctx.battery.percent = Battery_VoltageToPercent(ctx.battery.volts);
	if(ctx.state.firing)
		ctx.battery.loadVolts = ctx.battery.volts;

	// calculate max watts as [w = ((bPct / 100) * 50 + 30) * 1000)]
	// At 50 - 100%, 75W
	// At 30 - 49%   59W
	// At 0  - 29%   45W
	/*if(ctx.battery.percent >= 50) {
		ctx.settings.maxWatts = 75000;
	} else if(ctx.battery.percent >= 30) {
		ctx.settings.maxWatts = 59000;
	} else {
		ctx.settings.maxWatts = 45000;
	}*/
	float r = (float)ctx.battery.percent / 100;
	r *= 50;
	r += 30;
	ctx.settings.maxWatts = (int)r * 1000;

	// calculate bypass watts as [w = e^2 / r]
	if(ctx.battery.loadVolts != 0) {
		ctx.settings.bW = ctx.battery.loadVolts * ctx.battery.loadVolts;
		ctx.settings.bW /= ctx.atomizer.resistance;
	} else {
		ctx.settings.bW = ctx.battery.volts * ctx.battery.volts;
		ctx.settings.bW /= ctx.atomizer.resistance;
	}
}
예제 #2
0
void bt_send_sensor_data(void) {
	portTickType lastWakeTime;
	wirelessMessage_t msg;
	int16_t bat;

	msg.data[0] = 0;
	msg.dataLength = 16;
	msg.destinationId = 0;
	msg.messageType = PT_ANDROID_SENSORDATA;
	msg.priority = 0;

	lastWakeTime = os_getTime();

	for (;;) {
		os_frequency(&lastWakeTime, 100);

		bat = Battery_GetVoltage();

		msg.data[1] = Us_Data.Front_Distance & 0xff;
		msg.data[2] = (Us_Data.Front_Distance >> 8) & 0xff;
		msg.data[3] = Us_Data.Rear_Distance & 0xff;
		msg.data[4] = (Us_Data.Rear_Distance >> 8) & 0xff;
		msg.data[5] = Us_Data.Left_Distance & 0xff;
		msg.data[6] = (Us_Data.Left_Distance >> 8) & 0xff;
		msg.data[7] = Us_Data.Right_Distance & 0xff;
		msg.data[8] = (Us_Data.Right_Distance >> 8) & 0xff;
		msg.data[9] = linefound;
		msg.data[10] = averagePos & 0xff;
		msg.data[11] = (averagePos >> 8) & 0xff;
		msg.data[12] = (averagePos >> 16) & 0xff;
		msg.data[13] = (averagePos >> 24) & 0xff;
		msg.data[14] = bat & 0xff;
		msg.data[15] = (bat >> 8) & 0xff;
		wirelessSend(WI_IF_BLUETOOTH, &msg);
	}
}