diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2025-11-01 20:32:55 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2025-11-01 20:32:55 -0400 |
| commit | b71dd676b5ebe3feec1eb2194e20453a3d01705d (patch) | |
| tree | 10e19b6fa21d27c97376cdaf2bcfa03c05b2a75a /fw/main.c | |
| parent | 96a85a2bb8e52cb8b15745bca617e3cc788d02ad (diff) | |
| download | can-gauge-interface-b71dd676b5ebe3feec1eb2194e20453a3d01705d.zip | |
lookup output value in table
Diffstat (limited to 'fw/main.c')
| -rw-r--r-- | fw/main.c | 51 |
1 files changed, 45 insertions, 6 deletions
@@ -60,12 +60,14 @@ static const CanId rxb1Mask = { }; // Calibration tables in EEPROM -static const Table tachTbl = {0ul*TAB_SIZE}; // tachometer -static const Table speedTbl = {1ul*TAB_SIZE}; // speedometer -static const Table an1Tbl = {2ul*TAB_SIZE}; // analog channels... -static const Table an2Tbl = {3ul*TAB_SIZE}; -static const Table an3Tbl = {4ul*TAB_SIZE}; -static const Table an4Tbl = {5ul*TAB_SIZE}; +static const Table tbls[NSIG] = { + [SIG_TACH] = {0ul*TAB_SIZE}, // tachometer + [SIG_SPEED] = {1ul*TAB_SIZE}, // speedometer + [SIG_AN1] = {2ul*TAB_SIZE}, // analog channels... + [SIG_AN2] = {3ul*TAB_SIZE}, + [SIG_AN3] = {4ul*TAB_SIZE}, + [SIG_AN4] = {5ul*TAB_SIZE}, +}; // EEPROM address of encoding format structure for each signal. // Each of these addresses point to a SigFmt structure in the EEPROM. @@ -199,8 +201,45 @@ handleIdCtrlFrame(const CanFrame *frame) { } // Generate the output signal being sent to one of the gauges. +// Raw is the raw signal value extracted from a CAN frame. static Status driveGauge(Signal sig, Number raw) { + Status status; + U16 val; + + if (sig >= NSIG) { + return FAIL; + } + + // Lookup gauge waveform value in EEPROM table + status = tabLookup(&tbls[sig], raw, &val); + if (status != OK) { + return FAIL; + } + + switch (sig) { + case SIG_TACH: + // TODO + break; + case SIG_SPEED: + // TODO + break; + case SIG_AN1: + dacSet1a(val); + break; + case SIG_AN2: + dacSet1b(val); + break; + case SIG_AN3: + dacSet2a(val); + break; + case SIG_AN4: + dacSet2b(val); + break; + default: + return FAIL; // invalid signal + } + // TODO } |