mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-22 01:27:59 +02:00
Separate headers (#57)
* WIP, ctb * WIP, eiger * WIP, gotthard * WIP, jungfrau * WIP, gotthard2 * WIP, mythen3 * WIP, moench * fixed gotthard apiversioning mismatch with gotthard2
This commit is contained in:
36
slsDetectorServers/slsDetectorServer/src/common.c
Executable file
36
slsDetectorServers/slsDetectorServer/src/common.c
Executable file
@ -0,0 +1,36 @@
|
||||
#include "common.h"
|
||||
#include "clogger.h"
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int outputMax,
|
||||
int inputValue, int* outputValue) {
|
||||
FILE_LOG(logDEBUG1, (" Input Value: %d (Input:(%d - %d), Output:(%d - %d))\n",
|
||||
inputValue, inputMin, inputMax, outputMin, outputMax));
|
||||
|
||||
// validate within bounds
|
||||
// eg. MAX1932 range is v(60 - 200) to dac(255 - 1), here inputMin > inputMax (when dac to voltage)
|
||||
int smaller = inputMin;
|
||||
int bigger = inputMax;
|
||||
if (smaller > bigger) {
|
||||
smaller = inputMax;
|
||||
bigger = inputMin;
|
||||
}
|
||||
if ((inputValue < smaller) || (inputValue > bigger)) {
|
||||
FILE_LOG(logERROR, ("Input Value is outside bounds (%d to %d): %d\n", smaller, bigger, inputValue));
|
||||
*outputValue = -1;
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
double value = ((double)(inputValue - inputMin) * (double)(outputMax - outputMin))
|
||||
/ (double)(inputMax - inputMin) + outputMin;
|
||||
|
||||
// double to integer conversion (if decimal places, round to integer)
|
||||
if ((value - (int)value) > 0.0001) {
|
||||
value += 0.5;
|
||||
}
|
||||
*outputValue = value;
|
||||
|
||||
FILE_LOG(logDEBUG1, (" Converted Output Value: %d\n", *outputValue));
|
||||
return OK;
|
||||
}
|
||||
|
Reference in New Issue
Block a user