- adaptions to PCB Hend-Control, Rev.0

git-svn-id: http://moon:8086/svn/projects/HendiControl@152 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
2019-03-29 21:33:32 +00:00
parent 3ff77ccb66
commit a7a46940b5
10 changed files with 119 additions and 86 deletions
+31 -34
View File
@@ -32,8 +32,8 @@
#define TIMER_SW_DELAY_MS(dly) ((dly*TIMER_IRQ_CLOCK)/1000UL)
uint8_t ledState = 0;
int16_t adc_last = 0;
int16_t adc_poti = 0;
int16_t adc_swin = 0;
int sw_in_last = 0;
size_t cmdStrSize = 0;
Fifo messageFifo;
@@ -77,6 +77,7 @@ typedef enum _eState_t
int main(void)
{
int hb_state = 0;
cli();
wdt_reset();
wdt_disable();
@@ -124,8 +125,8 @@ int main(void)
{
// Process Uart message
cmdStr[cmdStrSize] = 0;
char c = msg.data;
char c = (char)msg.m.uart.data;
// Command finished with CR/LF
if (c == 0x0A || c == 0x0D)
{
@@ -178,57 +179,42 @@ int main(void)
case AdcComplete:
{
int16_t adc_curr = adc_getData();
if (adc_getChannel() == 6)
uint8_t adc_ch = msg.m.adc.ch;
int16_t adc_curr = (int16_t)msg.m.adc.data;
if (adc_ch == 0)
{
if (((adc_curr - adc_last) < -1) || ((adc_curr - adc_last) > 1))
if (((adc_curr - adc_poti) < -1) || ((adc_curr - adc_poti) > 1))
{
if (state == StateNormal)
{
setPower(adc_curr << 2);
}
adc_poti = adc_curr;
}
}
adc_last = adc_curr;
if (adc_ch == 2)
{
adc_swin = adc_curr;
}
}
break;
case Timer:
{
int timer_id = msg.data;
int timer_id = msg.m.timer.ch;
switch(timer_id)
{
case TIMER_GENERAL:
{
timer_start(timer_id, TIMER_SW_DELAY_MS(500));
switch(ledState)
{
case 0:
PORTB = (PORTB & 0xFC) | 0x00;
break;
case 1:
PORTB = (PORTB & 0xFC) | 0x01;
break;
case 2:
PORTB = (PORTB & 0xFC) | 0x03;
break;
case 3:
PORTB = (PORTB & 0xFC) | 0x02;
break;
}
ledState++;
if (ledState == 4)
{
ledState = 0;
}
hb_state = !hb_state;
portSet(Led_HB, hb_state);
}
break;
case TIMER_TIMEOUT:
{
PRINT("Timeout!\n");
setPower(PowerLow);
setSwitch(SwitchOff);
state_next = StateError;
}
break;
@@ -236,10 +222,10 @@ int main(void)
case TIMER_ADC:
{
timer_start(timer_id, TIMER_SW_DELAY_MS(50));
int sw_in = portGet(PwrSwitch_in);
int sw_in = adc_swin > 512;
if (sw_in != sw_in_last)
{
PRINT ("PwrSwitch_in = %d\n", portGet(PwrSwitch_in));
PRINT ("PwrSwitch_in = %d\n", sw_in);
if (sw_in == 0)
{
if (state == StateError || state == StateRemote)
@@ -250,7 +236,8 @@ int main(void)
}
}
sw_in_last = sw_in;
adc_start_conversion(0x06);
adc_enqueue_conversion(0);
adc_enqueue_conversion(2);
}
break;
}
@@ -264,6 +251,16 @@ int main(void)
if (state != state_next)
{
PRINT("State change \"%s\" => \"%s\"\n", state_str[state], state_str[state_next]);
if (state_next == StateError)
{
setPower(PowerLow);
setSwitch(SwitchOff);
portSet(Led_ERR, 1);
}
if (state_next == StateNormal)
{
portSet(Led_ERR, 0);
}
}
state = state_next;