- refactored variables
git-svn-id: http://moon:8086/svn/projects/HendiControl@176 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
@@ -42,14 +42,23 @@
|
|||||||
|
|
||||||
FILE uart_file = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
|
FILE uart_file = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
|
||||||
|
|
||||||
int16_t adc_poti = 0;
|
|
||||||
int16_t adc_swin = 0;
|
|
||||||
int sw_in_last = 0;
|
|
||||||
size_t cmdStrSize = 0;
|
size_t cmdStrSize = 0;
|
||||||
Fifo messageFifo;
|
Fifo messageFifo;
|
||||||
uint16_t g_power = 0;
|
|
||||||
int g_debug = 0;
|
int g_debug = 0;
|
||||||
int g_switch = 0;
|
|
||||||
|
// Switch IN
|
||||||
|
int16_t g_switch_in_digits = 0;
|
||||||
|
int g_switch_in = 0;
|
||||||
|
int g_switch_in_last = 0;
|
||||||
|
|
||||||
|
// Switch OUT
|
||||||
|
int g_switch_out = 0;
|
||||||
|
|
||||||
|
// Poti IN
|
||||||
|
uint16_t g_poti_in_digits = 0;
|
||||||
|
|
||||||
|
// Poti OUT
|
||||||
|
uint16_t g_poti_out_digits = 0;
|
||||||
|
|
||||||
typedef enum _eState_t
|
typedef enum _eState_t
|
||||||
{
|
{
|
||||||
@@ -72,7 +81,7 @@ typedef enum _eSwitch
|
|||||||
|
|
||||||
void setSwitch(int on)
|
void setSwitch(int on)
|
||||||
{
|
{
|
||||||
g_switch = on;
|
g_switch_out = on;
|
||||||
const char *sw_str[2] = {"OFF", "ON"};
|
const char *sw_str[2] = {"OFF", "ON"};
|
||||||
PRINT_DEBUG("Set switch to %s\n", sw_str[on != 0]);
|
PRINT_DEBUG("Set switch to %s\n", sw_str[on != 0]);
|
||||||
portSet(PwrSwitch_out, on != 0);
|
portSet(PwrSwitch_out, on != 0);
|
||||||
@@ -84,12 +93,12 @@ typedef enum _ePower
|
|||||||
PowerMax = 0
|
PowerMax = 0
|
||||||
} Power;
|
} Power;
|
||||||
|
|
||||||
void setPower(uint16_t power)
|
void setPower(uint16_t digits)
|
||||||
{
|
{
|
||||||
g_power = power;
|
g_poti_out_digits = digits;
|
||||||
PRINT_DEBUG("Set Power to %u\n", power);
|
PRINT_DEBUG("Set Power to %u digits\n", digits);
|
||||||
uint8_t dac_cmd[] = {0x00, 0x00}; // 6.2 Write Volatile Memory (C2:C0 = ‘010’)
|
uint8_t dac_cmd[] = {0x00, 0x00}; // 6.2 Write Volatile Memory (C2:C0 = ‘010’)
|
||||||
size_t res = MCP47x6_write_volatile_dac(power, dac_cmd, sizeof(dac_cmd));
|
size_t res = MCP47x6_write_volatile_dac(digits, dac_cmd, sizeof(dac_cmd));
|
||||||
i2c_send(0x60, I2C_WRITE, dac_cmd, res);
|
i2c_send(0x60, I2C_WRITE, dac_cmd, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,7 +166,7 @@ int main(void)
|
|||||||
if ((*pArgs) == '?')
|
if ((*pArgs) == '?')
|
||||||
{
|
{
|
||||||
pArgs++;
|
pArgs++;
|
||||||
PRINT_ANSWER("OK:%04u", g_power);
|
PRINT_ANSWER("OK:%04u", g_poti_out_digits);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -169,7 +178,7 @@ int main(void)
|
|||||||
if (state == StateRemote)
|
if (state == StateRemote)
|
||||||
{
|
{
|
||||||
setPower(arg);
|
setPower(arg);
|
||||||
PRINT_ANSWER("OK:%04u", g_power);
|
PRINT_ANSWER("OK:%04u", g_poti_out_digits);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,7 +190,7 @@ int main(void)
|
|||||||
if ((*pArgs) == '?')
|
if ((*pArgs) == '?')
|
||||||
{
|
{
|
||||||
pArgs++;
|
pArgs++;
|
||||||
PRINT_ANSWER("OK:%u", g_switch);
|
PRINT_ANSWER("OK:%u", g_switch_out);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -194,7 +203,7 @@ int main(void)
|
|||||||
if (state == StateRemote)
|
if (state == StateRemote)
|
||||||
{
|
{
|
||||||
setSwitch(arg);
|
setSwitch(arg);
|
||||||
PRINT_ANSWER("OK:%u", g_switch);
|
PRINT_ANSWER("OK:%u", g_switch_out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -308,18 +317,19 @@ int main(void)
|
|||||||
int16_t adc_curr = (int16_t)msg.m.adc.data;
|
int16_t adc_curr = (int16_t)msg.m.adc.data;
|
||||||
if (adc_ch == 0)
|
if (adc_ch == 0)
|
||||||
{
|
{
|
||||||
if (((adc_curr - adc_poti) <= -(int16_t)POTI_HSYTERSE) || ((adc_curr - adc_poti) >= (int16_t)POTI_HSYTERSE))
|
if (((adc_curr - (int16_t)g_poti_in_digits) <= -(int16_t)POTI_HSYTERSE) || ((adc_curr - (int16_t)g_poti_in_digits) >= (int16_t)POTI_HSYTERSE))
|
||||||
{
|
{
|
||||||
if (state == StateNormal)
|
if (state == StateNormal)
|
||||||
{
|
{
|
||||||
setPower(adc_curr << 2);
|
setPower(adc_curr << 2);
|
||||||
}
|
}
|
||||||
adc_poti = adc_curr;
|
g_poti_in_digits = (uint16_t)adc_curr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (adc_ch == 2)
|
if (adc_ch == 2)
|
||||||
{
|
{
|
||||||
adc_swin = adc_curr;
|
g_switch_in_digits = adc_curr;
|
||||||
|
g_switch_in = (int)(g_switch_in_digits > 512);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -365,11 +375,10 @@ int main(void)
|
|||||||
case TIMER_ADC:
|
case TIMER_ADC:
|
||||||
{
|
{
|
||||||
timer_start(timer_id, TIMER_SW_DELAY_MS(50));
|
timer_start(timer_id, TIMER_SW_DELAY_MS(50));
|
||||||
int sw_in = adc_swin > 512;
|
if (g_switch_in != g_switch_in_last)
|
||||||
if (sw_in != sw_in_last)
|
|
||||||
{
|
{
|
||||||
PRINT_DEBUG ("PwrSwitch_in = %d\n", sw_in);
|
PRINT_DEBUG ("PwrSwitch_in = %d\n", g_switch_in);
|
||||||
if (sw_in == 0)
|
if (g_switch_in == 0)
|
||||||
{
|
{
|
||||||
if (state == StateError || state == StateRemote)
|
if (state == StateError || state == StateRemote)
|
||||||
{
|
{
|
||||||
@@ -378,7 +387,7 @@ int main(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sw_in_last = sw_in;
|
g_switch_in_last = g_switch_in;
|
||||||
adc_enqueue_conversion(0);
|
adc_enqueue_conversion(0);
|
||||||
adc_enqueue_conversion(2);
|
adc_enqueue_conversion(2);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user