Skip to content

Commit

Permalink
Working offset angle for compression
Browse files Browse the repository at this point in the history
  • Loading branch information
noisymime committed Apr 30, 2024
1 parent 4198ee0 commit 98d1ff5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 37 deletions.
10 changes: 5 additions & 5 deletions UI/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<div class="row">
<div class="col-7">Configuration: </div>
<div class="col-2">
<select id="compressionMode" onChange="setCompressionMode()" disabled>
<select id="compressionMode" onChange="sendConfig()" disabled>
<option value="1">2-cyl 4 stroke</option>
<option value="3">4-cyl 4 stroke</option>
<option value="4">6-cyl 4 stroke</option>
Expand All @@ -98,15 +98,15 @@
</div>
</div>
<div class="row">
<div class="col-7">Compression RPM: </div>
<div class="col-2">
<input type="number" id="compressionRPM" min="20" max="1000" step="1" value="400" onChange="setCompressionRPM()" disabled>
<div class="col-7">Compression below: </div>
<div class="col-4">
<input type="number" id="compressionRPM" min="20" max="1000" step="1" value="400" onChange="sendConfig()" disabled> RPM
</div>
</div>
<div class="row">
<div class="col-7">Offset (Deg): </div>
<div class="col-2">
<input type="number" id="compressionOffset" min="0" max="359" step="1" value="0" onChange="setCompressionRPM()" disabled>
<input type="number" id="compressionOffset" min="0" max="359" step="1" value="0" onChange="sendConfig()" disabled>
</div>
</div>

Expand Down
25 changes: 9 additions & 16 deletions UI/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@ function sendConfig()
configBuffer[0] = 0x63; // 'c' character command
configBuffer[1] = parseInt(document.getElementById('patternSelect').value);
configBuffer[2] = parseInt(document.getElementById('rpmSelect').value);
configBuffer.writeInt16LE(parseInt(document.getElementById('fixedRPM').value), 3);
configBuffer.writeInt16LE(parseInt(document.getElementById('rpmSweepMin').value), 5);
configBuffer.writeInt16LE(parseInt(document.getElementById('rpmSweepMax').value), 7);
configBuffer.writeInt16LE(parseInt(document.getElementById('rpmSweepSpeed').value), 9);
configBuffer.writeUInt16LE(parseInt(document.getElementById('fixedRPM').value), 3);
configBuffer.writeUInt16LE(parseInt(document.getElementById('rpmSweepMin').value), 5);
configBuffer.writeUInt16LE(parseInt(document.getElementById('rpmSweepMax').value), 7);
configBuffer.writeUInt16LE(parseInt(document.getElementById('rpmSweepSpeed').value), 9);
configBuffer[11] = document.getElementById('compressionEnable').checked;
configBuffer[12] = parseInt(document.getElementById('compressionMode').value);
configBuffer.writeInt16LE(parseInt(document.getElementById('compressionRPM').value), 13);
configBuffer.writeInt16LE(parseInt(document.getElementById('compressionOffset').value), 15);
configBuffer.writeUInt16LE(parseInt(document.getElementById('compressionRPM').value), 13);
configBuffer.writeUInt16LE(parseInt(document.getElementById('compressionOffset').value), 15);

console.log("Sending full config: ", configBuffer);

Expand Down Expand Up @@ -427,16 +427,9 @@ function setRPMMode()
{
//Change between pot, fixed and sweep RPM modes


var newMode = parseInt(document.getElementById('rpmSelect').value);

const parser = port.pipe(new Readline({ delimiter: '\r\n' }));
console.log(`Sending 'M' command to change RPM mode to ${newMode}`);

var buffer = Buffer.alloc(2);
buffer[0] = 0x4D; // Ascii 'M'
buffer[1] = newMode;
port.write(buffer); //Send the new pattern ID

//If the new mode is fixed RPM or linear sweep, then send the RPM set values for them
if(newMode == 0)
{
Expand Down Expand Up @@ -625,8 +618,8 @@ window.onload = function ()
{
refreshSerialPorts();
redrawGears(toothPatterns[0]);
//window.location.hash = '#connect';
window.location.hash = '#live';
window.location.hash = '#connect';
//window.location.hash = '#live';
checkForUpdates();
//animateGauges();

Expand Down
1 change: 1 addition & 0 deletions ardustim/ardustim/ardustim.ino
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ uint16_t calculateCurrentCrankAngle()
if( pgm_read_byte(&Wheels[config.wheel].wheel_degrees) == 720 ) { cycleTime = cycleTime / 2; }

uint16_t tmpCrankAngle = ((cycleTime * 360U) / cycleDuration);
tmpCrankAngle += config.compressionOffset;
while(tmpCrankAngle > 360) { tmpCrankAngle -= 360; }

return tmpCrankAngle;
Expand Down
16 changes: 0 additions & 16 deletions ardustim/ardustim/comms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ void commandParser()
{
char buf[80];
byte tmp_wheel;
byte tmp_mode;
void* pnt_Config = &config;
if (cmdPending == false) { currentCommand = Serial.read(); }

Expand All @@ -65,12 +64,6 @@ void commandParser()
case 'a':
break;

case 'f': //Set the fixed RPM value
config.mode = FIXED_RPM;
while(Serial.available() < 2) {} //Wait for the new RPM bytes
config.fixed_rpm = word(Serial.read(), Serial.read());
break;

case 'c': //Receive a full config buffer
//uint8_t targetBytes = (sizeof(struct configTable)-1); //No byte is sent for the version
while(Serial.available() < (sizeof(struct configTable)-1) ) {} //Wait for all bytes
Expand Down Expand Up @@ -99,15 +92,6 @@ void commandParser()
}
break;

case 'M': ///Change the RPM mode
while(Serial.available() < 1) {} //Wait for the new mode byte
tmp_mode = Serial.read();
if(tmp_mode <= POT_RPM)
{
config.mode = tmp_mode;
}
break;

case 'n': //Send the number of wheels
Serial.println(MAX_WHEELS);
break;
Expand Down
1 change: 1 addition & 0 deletions ardustim/ardustim/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define EEPROM_USE_COMPRESSION 14
#define EEPROM_COMPRESSION_TYPE 15
#define EEPROM_COMPRESSION_RPM 16 //Note this is 2 bytes
#define EEPROM_COMPRESSION_OFFSET 18 //Note this is 2 bytes

void loadConfig();
void saveConfig();
8 changes: 8 additions & 0 deletions ardustim/ardustim/storage.ino
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ void loadConfig()
highByte = EEPROM.read(EEPROM_COMPRESSION_RPM);
lowByte = EEPROM.read(EEPROM_COMPRESSION_RPM+1);
config.compressionRPM = word(highByte, lowByte);
highByte = EEPROM.read(EEPROM_COMPRESSION_OFFSET);
lowByte = EEPROM.read(EEPROM_COMPRESSION_OFFSET+1);
config.compressionOffset = word(highByte, lowByte);
//config.compressionType = COMPRESSION_TYPE_6CYL_4STROKE;

//Error checking
Expand All @@ -67,6 +70,7 @@ void loadConfig()
if(currentStatus.base_rpm > 15000) { currentStatus.base_rpm = 4000; }
if(config.compressionType > COMPRESSION_TYPE_8CYL_4STROKE) { config.compressionType = COMPRESSION_TYPE_4CYL_4STROKE; }
if(config.compressionRPM > 1000) { config.compressionRPM = 400; }
if(config.compressionOffset > 359) { config.compressionOffset = 0; }
}
}

Expand Down Expand Up @@ -107,4 +111,8 @@ void saveConfig()
lowByte = lowByte(config.compressionRPM);
EEPROM.update(EEPROM_COMPRESSION_RPM, highByte);
EEPROM.update(EEPROM_COMPRESSION_RPM+1, lowByte);
highByte = highByte(config.compressionOffset);
lowByte = lowByte(config.compressionOffset);
EEPROM.update(EEPROM_COMPRESSION_OFFSET, highByte);
EEPROM.update(EEPROM_COMPRESSION_OFFSET+1, lowByte);
}

0 comments on commit 98d1ff5

Please sign in to comment.