You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.5 KiB
C

/*
* ScaleCompute.h
*
* Author: Aleksey Gerasimenko
* gerasimenko.aleksey.n@gmail.com
*/
#include <math.h>
#include <stdint.h>
#ifndef SYSCTRL_SCALECOMPUTE_H_
#define SYSCTRL_SCALECOMPUTE_H_
namespace SYSCTRL
{
struct ScaleComputeEnableBit
{
uint16_t enable: 1;
};//ScaleComputeEnableBit
union ScaleComputeEnableRegister
{
uint16_t all;
ScaleComputeEnableBit bit;
};//ScaleComputeEnableRegister
struct ScaleComputeCommandBit
{
uint16_t start: 1;
};//ScaleComputeCommandBit
union ScaleComputeCommandRegister
{
uint16_t all;
ScaleComputeCommandBit bit;
};//ScaleComputeCommandRegister
class ScaleCompute
{
private:
ScaleComputeCommandRegister m_command;
ScaleComputeEnableRegister m_enable;
float m_reference_value;
//
float& m_p_phase_a;
float& m_p_phase_b;
float& m_p_phase_c;
//
float& m_p_scale_a;
float& m_p_scale_b;
float& m_p_scale_c;
//
float m_value_phase_a;
float m_value_phase_b;
float m_value_phase_c;
//
float m_scale_phase_a;
float m_scale_phase_b;
float m_scale_phase_c;
public:
ScaleCompute(float& phase_a, float& phase_b, float& phase_c, float& scale_a, float& scale_b, float& scale_c);
void set_reference(float reference);
void set_enable();
void clear_enable();
void fix();
private:
inline float new_scale_compute(float ref, float value, float scale);
//
};//class ScaleCompute
} /* namespace SYSCTRL */
#endif /* SYSCTRL_SCALECOMPUTE_H_ */