📄 emeter-basic-display.c
字号:
}
static void LCDicon(int pos, int on)
{
static const lcd_cell_t segs[] =
{
SEG_a,
SEG_b,
SEG_c,
SEG_d,
SEG_e,
SEG_f,
#if !defined(USE_STARBURST)
SEG_g,
SEG_h,
#else
SEG_i,
SEG_h,
SEG_12,
SEG_1,
SEG_3,
SEG_5,
SEG_6,
SEG_7,
SEG_9,
SEG_11
#endif
};
LCDmodify_char(segs[pos >> 5], pos & 0x1F, on);
}
static void LCDoverrange(void)
{
LCDcharsx(lcd_high, FIRST_POSITION, TEXT_MESSAGE_LENGTH);
}
#if defined(MAINS_FREQUENCY_SUPPORT)
#if defined(SINGLE_PHASE)
static __inline__ void display_mains_frequency(void)
#else
static __inline__ void display_mains_frequency(struct phase_parms_s *phase)
#endif
{
int32_t x;
/* Display mains frequency in 0.1Hz or 0.01Hz increments */
#if !defined(ICON_HERTZ) && defined(DISPLAY_TYPE_POSITION)
LCDchar(CHAR_F, DISPLAY_TYPE_POSITION);
#endif
#if defined(PRECALCULATED_PARAMETER_SUPPORT)
x = phase->frequency;
#else
#if defined(SINGLE_PHASE)
x = frequency();
#else
x = frequency(phase);
#endif
#endif
LCDdecu32(x, FIRST_POSITION, NUMBER_WIDTH, FREQUENCY_RESOLUTION);
#if defined(ICON_DECIMAL_FREQUENCY)
LCDicon(ICON_DECIMAL_FREQUENCY, TRUE);
#endif
#if defined(ICON_HERTZ)
LCDicon(ICON_HERTZ, TRUE);
#endif
}
#endif
#if defined(VRMS_SUPPORT)
#if defined(SINGLE_PHASE)
static void display_vrms(void)
#else
static __inline__ void display_vrms(struct phase_parms_s *phase, struct phase_nv_parms_s const *phase_nv)
#endif
{
int32_t x;
/* Display RMS voltage in 0.1V or 0.01V increments */
#if defined(PRECALCULATED_PARAMETER_SUPPORT)
if (phase->V_rms == 0xFFFF)
x = -1;
else
x = phase->V_rms;
#else
#if defined(SINGLE_PHASE)
x = voltage();
#else
x = voltage(phase, phase_nv);
#endif
#endif
#if !defined(ICON_VOLTAGE) && defined(DISPLAY_TYPE_POSITION)
#if defined(USE_STARBURST)
LCDchar(CHAR_V, DISPLAY_TYPE_POSITION);
#else
LCDchar(CHAR_U, DISPLAY_TYPE_POSITION);
#endif
#endif
if (x < 0)
{
LCDoverrange();
}
else
{
#if defined(VOLTAGE_DISPLAY_DIVISOR)
x /= VOLTAGE_DISPLAY_DIVISOR;
#endif
LCDdecu32(x, FIRST_POSITION, NUMBER_WIDTH, VOLTAGE_RESOLUTION);
#if defined(ICON_DECIMAL_VOLTAGE)
LCDicon(ICON_DECIMAL_VOLTAGE, TRUE);
#endif
}
#if defined(ICON_V)
LCDicon(ICON_V, TRUE);
#endif
#if defined(ICON_VOLTAGE)
LCDicon(ICON_VOLTAGE, TRUE);
#endif
}
#endif
#if defined(IRMS_SUPPORT)
#if defined(SINGLE_PHASE)
static __inline__ void display_irms(void)
#else
static __inline__ void display_irms(struct phase_parms_s *phase, struct phase_nv_parms_s const *phase_nv)
#endif
{
int32_t x;
/* Display RMS current in 1mA increments */
#if defined(PRECALCULATED_PARAMETER_SUPPORT)
if (phase->I_rms == 0xFFFF)
x = -1;
else
x = phase->I_rms;
#else
#if defined(SINGLE_PHASE)
x = current();
#else
x = current(phase, phase_nv);
#endif
#endif
#if !defined(ICON_CURRENT) && defined(DISPLAY_TYPE_POSITION)
LCDchar(CHAR_C, DISPLAY_TYPE_POSITION);
#endif
if (x < 0)
{
LCDoverrange();
}
else
{
#if defined(CURRENT_DISPLAY_DIVISOR)
x /= CURRENT_DISPLAY_DIVISOR;
#endif
LCDdecu32(x, FIRST_POSITION, NUMBER_WIDTH, CURRENT_RESOLUTION);
#if defined(ICON_DECIMAL_CURRENT)
LCDicon(ICON_DECIMAL_CURRENT, TRUE);
#endif
}
#if defined(ICON_A)
LCDicon(ICON_A, TRUE);
#endif
#if defined(ICON_CURRENT)
LCDicon(ICON_CURRENT, TRUE);
#endif
}
#endif
#if !defined(SINGLE_PHASE) && defined(NEUTRAL_MONITOR_SUPPORT) && defined(IRMS_SUPPORT)
static __inline__ void display_neutral_irms(void)
{
int32_t x;
/* Display RMS current in 1mA increments */
#if defined(PRECALCULATED_PARAMETER_SUPPORT)
if (neutral.I_rms == 0xFFFF)
x = -1;
else
x = neutral.I_rms;
#else
x = current(xxx);
#endif
if (x < 0)
{
LCDoverrange();
}
else
{
#if defined(CURRENT_DISPLAY_DIVISOR)
x /= CURRENT_DISPLAY_DIVISOR;
#endif
LCDdecu32(x, FIRST_POSITION, NUMBER_WIDTH, CURRENT_RESOLUTION);
#if defined(ICON_DECIMAL_CURRENT)
LCDicon(ICON_DECIMAL_CURRENT, TRUE);
#endif
}
#if !defined(ICON_CURRENT) && defined(DISPLAY_TYPE_POSITION)
LCDchar(CHAR_C, DISPLAY_TYPE_POSITION);
#endif
#if defined(ICON_A)
LCDicon(ICON_A, TRUE);
#endif
#if defined(ICON_CURRENT)
LCDicon(ICON_CURRENT, TRUE);
#endif
}
#endif
#if defined(TOTAL_ENERGY_SUPPORT)
static __inline__ void display_total_consumed_energy(void)
{
//Display energy in 0.1kWh increments
#if !(defined(ICON_kW) && defined(ICON_H)) && !defined(ICON_kWH) && defined(DISPLAY_TYPE_POSITION)
LCDchar(CHAR_E, DISPLAY_TYPE_POSITION);
#endif
#if FIRST_POSITION > 2
LCDchar(CHAR_SPACE, 2);
#endif
#if ENERGY_RESOLUTION == 1
LCDdecu32(total_consumed_energy/10L, FIRST_POSITION, NUMBER_WIDTH, ENERGY_RESOLUTION);
#else
LCDdecu32(total_consumed_energy/100L, FIRST_POSITION, NUMBER_WIDTH, ENERGY_RESOLUTION);
#endif
#if defined(ICON_DECIMAL_ENERGY)
LCDicon(ICON_DECIMAL_ENERGY, TRUE);
#endif
#if defined(ICON_kWH)
LCDicon(ICON_kWH, TRUE);
#elif defined(ICON_kW) && defined(ICON_H)
LCDicon(ICON_kW, TRUE);
LCDicon(ICON_H, TRUE);
#endif
}
#endif
#if defined(PER_PHASE_ENERGY_SUPPORT)
#if defined(SINGLE_PHASE)
static __inline__ void display_phase_consumed_energy(void)
#else
static __inline__ void display_phase_consumed_energy(struct phase_parms_s *phase)
#endif
{
//Display energy in 0.1kWh increments
#if !(defined(ICON_kW) && defined(ICON_H)) && !defined(ICON_kWH) && defined(DISPLAY_TYPE_POSITION)
LCDchar(CHAR_E, DISPLAY_TYPE_POSITION);
#endif
#if ENERGY_RESOLUTION == 1
LCDdecu32(phase->consumed_energy/10L, FIRST_ENERGY_POSITION, NUMBER_WIDTH, ENERGY_RESOLUTION);
#else
LCDdecu32(phase->consumed_energy/100L, FIRST_ENERGY_POSITION, NUMBER_WIDTH, ENERGY_RESOLUTION);
#endif
#if defined(ICON_DECIMAL_ENERGY)
LCDicon(ICON_DECIMAL_ENERGY, TRUE);
#endif
#if defined(ICON_kWH)
LCDicon(ICON_kWH, TRUE);
#elif defined(ICON_kW) && defined(ICON_H)
LCDicon(ICON_kW, TRUE);
LCDicon(ICON_H, TRUE);
#endif
}
#endif
#if defined(TOTAL_ENERGY_SUPPORT)
static __inline__ void display_total_power(void)
{
/* Display total power (all phased summed) in 0.01W increments */
#if !defined(ICON_kW) && defined(DISPLAY_TYPE_POSITION)
LCDchar(CHAR_P, DISPLAY_TYPE_POSITION);
#endif
#if FIRST_POWER_POSITION > 2
LCDchar(CHAR_SPACE, 2);
#endif
#if POWER_RESOLUTION == 1
LCDdecu32(total_power/10L, FIRST_POWER_POSITION, NUMBER_WIDTH, POWER_RESOLUTION);
#else
LCDdecu32(total_power, FIRST_POWER_POSITION, NUMBER_WIDTH, POWER_RESOLUTION);
#endif
#if defined(ICON_DECIMAL_POWER)
LCDicon(ICON_DECIMAL_POWER, TRUE);
#endif
#if defined(ICON_kW)
LCDicon(ICON_kW, TRUE);
#endif
}
#endif
#if defined(PER_PHASE_ENERGY_SUPPORT)
#if defined(SINGLE_PHASE)
static __inline__ void display_phase_power(void)
#else
static __inline__ void display_phase_power(struct phase_parms_s *phase)
#endif
{
//Display per phase power in 0.01W increments
#if !defined(ICON_kW) && defined(DISPLAY_TYPE_POSITION)
LCDchar(CHAR_P, DISPLAY_TYPE_POSITION);
#endif
#if POWER_RESOLUTION == 1
LCDdecu32(phase->power/10L, FIRST_POWER_POSITION, NUMBER_WIDTH, POWER_RESOLUTION);
#else
LCDdecu32(phase->power, FIRST_POWER_POSITION, NUMBER_WIDTH, POWER_RESOLUTION);
#endif
#if defined(ICON_DECIMAL_POWER)
LCDicon(ICON_DECIMAL_POWER, TRUE);
#endif
#if defined(ICON_kW)
LCDicon(ICON_kW, TRUE);
#endif
}
#endif
#if defined(IRMS_SUPPORT) && defined(VRMS_SUPPORT) && defined(POWER_FACTOR_SUPPORT)
#if defined(SINGLE_PHASE)
static __inline__ void display_power_factor(void)
#else
static __inline__ void display_power_factor(struct phase_parms_s *phase, struct phase_nv_parms_s const *phase_nv)
#endif
{
int16_t x;
#if !defined(ICON_COS_PHI) && defined(DISPLAY_TYPE_POSITION)
LCDchar(CHAR_F, DISPLAY_TYPE_POSITION);
#endif
#if defined(PRECALCULATED_PARAMETER_SUPPORT)
x = phase->power_factor;
#else
#if defined(SINGLE_PHASE)
x = power_factor();
#else
x = power_factor(phase, phase_nv);
#endif
#endif
if (x < 0)
{
LCDchar(CHAR_L, FIRST_POWER_FACTOR_POSITION);
x = -x;
}
else
{
LCDchar(CHAR_C, FIRST_POWER_FACTOR_POSITION);
}
LCDdec16(x/10, FIRST_POWER_FACTOR_POSITION + 1, NUMBER_WIDTH - 2, 2);
#if defined(ICON_DECIMAL_2)
LCDicon(ICON_DECIMAL_2, TRUE);
#endif
#if defined(ICON_COS_PHI)
LCDicon(ICON_COS_PHI, TRUE);
#endif
}
#if defined(REACTIVE_POWER_SUPPORT)
#if defined(SINGLE_PHASE)
static __inline__ void display_reactive_power(void)
#else
static __inline__ void display_reactive_power(struct phase_parms_s *phase)
#endif
{
int32_t x;
// power_factor [ie cos(phase angle)] = (v.i)/sqrt(v.v * i.i)
// real power = (2/N) * v.i
// imag (reactive) power = (2/N) * sqrt(v.v * i.i - v.i * v.i)
//Display reactive power in 0.01W increments
#if !defined(ICON_kW) && defined(DISPLAY_TYPE_POSITION)
#if defined(USE_STARBURST)
LCDchar(CHAR_R, DISPLAY_TYPE_POSITION);
#else
LCDchar(CHAR_r, DISPLAY_TYPE_POSITION);
#endif
#endif
#if defined(PRECALCULATED_PARAMETER_SUPPORT)
x = labs(phase->reactive_power);
#else
#if defined(SINGLE_PHASE)
x = reactive_power();
#else
x = reactive_power(phase);
#endif
#endif
//Needs scaling
#if POWER_RESOLUTION == 1
x /= 10;
#endif
LCDdecu32(x, FIRST_REACTIVE_POWER_POSITION, NUMBER_WIDTH, POWER_RESOLUTION);
LCDicon(ICON_DECIMAL_POWER, TRUE);
#if defined(ICON_kW)
LCDicon(ICON_kW, TRUE);
#endif
}
#endif
#if defined(VA_POWER_SUPPORT)
#if defined(SINGLE_PHASE)
static __inline__ void display_VA_power(void)
#else
static __inline__ void display_VA_power(struct phase_parms_s *phase)
#endif
{
int32_t x;
//Display apparent (VA) power in 0.01W increments
#if !defined(ICON_kW) && defined(DISPLAY_TYPE_POSITION)
#if defined(USE_STARBURST)
LCDchar(CHAR_A, DISPLAY_TYPE_POSITION);
#else
LCDchar(CHAR_n, DISPLAY_TYPE_POSITION);
#endif
#endif
#if defined(PRECALCULATED_PARAMETER_SUPPORT)
x = phase->VA_power;
#else
#if defined(SINGLE_PHASE)
x = VA_power();
#else
x = VA_power(phase);
#endif
#endif
//Needs scaling
#if POWER_RESOLUTION == 1
x /= 10;
#endif
LCDdecu32(x, FIRST_VA_POWER_POSITION, NUMBER_WIDTH, POWER_RESOLUTION);
LCDicon(ICON_DECIMAL_POWER, TRUE);
#if defined(ICON_kW)
LCDicon(ICON_kW, TRUE);
#endif
}
#endif
#endif
#if defined(RTC_SUPPORT)
static /*__inline__*/ void display_current_date(void)
{
#if !defined(ICON_DATE) && defined(DISPLAY_TYPE_POSITION)
#if defined(USE_STARBURST)
LCDchar(CHAR_D, DISPLAY_TYPE_POSITION);
#else
LCDchar(CHAR_d, DISPLAY_TYPE_POSITION);
#endif
#if FIRST_POSITION > 2
LCDchar(CHAR_t, DISPLAY_TYPE_POSITION + 1);
#endif
#endif
#if defined(ZAP_COLON_CELL)
LCDchar(CHAR_SPACE, ZAP_COLON_CELL);
#endif
LCDdecu16(rtc.year, YEAR_POSITION, 2, 1);
LCDdecu16(rtc.month, MONTH_POSITION, 2, 1);
LCDdecu16(rtc.day, DAY_POSITION, 2, 1);
#if defined(ICON_DATE_COLON_1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -