mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 01:58:00 +02:00
format slsdetectorservers .c
This commit is contained in:
19
slsDetectorServers/slsDetectorServer/src/common.c
Executable file → Normal file
19
slsDetectorServers/slsDetectorServer/src/common.c
Executable file → Normal file
@ -2,13 +2,14 @@
|
||||
#include "clogger.h"
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int outputMax,
|
||||
int inputValue, int* outputValue) {
|
||||
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin,
|
||||
int outputMax, int inputValue, int *outputValue) {
|
||||
LOG(logDEBUG1, (" Input Value: %d (Input:(%d - %d), Output:(%d - %d))\n",
|
||||
inputValue, inputMin, inputMax, outputMin, outputMax));
|
||||
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)
|
||||
// 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) {
|
||||
@ -16,13 +17,16 @@ int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int outpu
|
||||
bigger = inputMin;
|
||||
}
|
||||
if ((inputValue < smaller) || (inputValue > bigger)) {
|
||||
LOG(logERROR, ("Input Value is outside bounds (%d to %d): %d\n", smaller, bigger, inputValue));
|
||||
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 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) {
|
||||
@ -33,4 +37,3 @@ int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int outpu
|
||||
LOG(logDEBUG1, (" Converted Output Value: %d\n", *outputValue));
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user