add external connection check
This commit is contained in:
76
src/main.c
76
src/main.c
@@ -10,6 +10,8 @@
|
||||
void led_pwm(void);
|
||||
void probe_int_on(ButtonKey_t *key);
|
||||
void probe_int_off(ButtonKey_t *key);
|
||||
void probe_ext_on(ButtonKey_t *key);
|
||||
void probe_ext_off(ButtonKey_t *key);
|
||||
void estop_on(ButtonKey_t *key);
|
||||
void estop_off(ButtonKey_t *key);
|
||||
|
||||
@@ -23,9 +25,19 @@ ButtonKey_t probe_int = {
|
||||
.buttonReleased = probe_int_off,
|
||||
.buttonPressed = probe_int_on,
|
||||
};
|
||||
ButtonKey_t probe_ext = {
|
||||
.instance = {2, &PINA, PROBE_EXT_PIN},
|
||||
.state = IDLE,
|
||||
.last_state = IDLE,
|
||||
.active_state = GPIO_PIN_RESET,
|
||||
.timer_debounce_on = 10, // 1000 ms
|
||||
.timer_debounce_off = 10, // 1 ms
|
||||
.buttonReleased = probe_ext_off,
|
||||
.buttonPressed = probe_ext_on,
|
||||
};
|
||||
|
||||
ButtonKey_t estop_in = {
|
||||
.instance = {2, &PINA, ESTOP_IN_PIN},
|
||||
.instance = {3, &PINA, ESTOP_IN_PIN},
|
||||
.state = IDLE,
|
||||
.last_state = IDLE,
|
||||
.active_state = GPIO_PIN_RESET,
|
||||
@@ -34,12 +46,15 @@ ButtonKey_t estop_in = {
|
||||
.buttonReleased = estop_off,
|
||||
.buttonPressed = estop_on,
|
||||
};
|
||||
ButtonKey_t *inputs[2] = {
|
||||
ButtonKey_t *inputs[3] = {
|
||||
&probe_int,
|
||||
&probe_ext,
|
||||
&estop_in,
|
||||
};
|
||||
|
||||
uint8_t ext_divece_connected = 0;
|
||||
uint8_t ext_probe_connected = 0;
|
||||
uint8_t estop_triggered = 0;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
LED12_SW_DDR |= (1 << LED12_SW_PIN);
|
||||
@@ -53,7 +68,26 @@ int main(void)
|
||||
|
||||
while (1)
|
||||
{
|
||||
ext_divece_connected = is_device_connected();
|
||||
// if (estop_triggered)
|
||||
// {
|
||||
// LED12_SW_PORT |= (1 << LED12_SW_PIN);
|
||||
// LED34_SW_PORT &= ~(1 << LED34_SW_PIN);
|
||||
|
||||
// LED12_SW_PORT &= ~(1 << LED12_SW_PIN);
|
||||
// LED34_SW_PORT |= (1 << LED34_SW_PIN);
|
||||
// }
|
||||
if (ext_probe_connected != is_device_connected())
|
||||
{
|
||||
ext_probe_connected = is_device_connected();
|
||||
if (ext_probe_connected)
|
||||
{
|
||||
LED34_SW_PORT |= (1 << LED34_SW_PIN);
|
||||
}
|
||||
else
|
||||
{
|
||||
LED34_SW_PORT &= ~(1 << LED34_SW_PIN);
|
||||
}
|
||||
}
|
||||
for (uint8_t i = 0; i < sizeof(inputs) / sizeof(inputs[0]); i++)
|
||||
{
|
||||
buttonHandler(inputs[i]);
|
||||
@@ -77,36 +111,40 @@ void led_pwm(void)
|
||||
void probe_int_on(ButtonKey_t *key)
|
||||
{
|
||||
LED12_SW_PORT |= (1 << LED12_SW_PIN);
|
||||
if (ext_divece_connected)
|
||||
{
|
||||
LED34_SW_PORT &= ~(1 << LED34_SW_PIN);
|
||||
}
|
||||
else
|
||||
if (!ext_probe_connected)
|
||||
{
|
||||
LED34_SW_PORT |= (1 << LED34_SW_PIN);
|
||||
}
|
||||
// LED34_SW_PORT &= ~(1 << LED34_SW_PIN);
|
||||
}
|
||||
|
||||
void probe_int_off(ButtonKey_t *key)
|
||||
{
|
||||
LED12_SW_PORT &= ~(1 << LED12_SW_PIN);
|
||||
if (ext_divece_connected)
|
||||
{
|
||||
LED34_SW_PORT |= (1 << LED34_SW_PIN);
|
||||
}
|
||||
else
|
||||
if (!ext_probe_connected)
|
||||
{
|
||||
LED34_SW_PORT &= ~(1 << LED34_SW_PIN);
|
||||
}
|
||||
// LED34_SW_PORT |= (1 << LED34_SW_PIN);
|
||||
}
|
||||
|
||||
void probe_ext_on(ButtonKey_t *key)
|
||||
{
|
||||
LED34_SW_PORT &= ~(1 << LED34_SW_PIN);
|
||||
}
|
||||
|
||||
void probe_ext_off(ButtonKey_t *key)
|
||||
{
|
||||
LED34_SW_PORT |= (1 << LED34_SW_PIN);
|
||||
}
|
||||
|
||||
void estop_on(ButtonKey_t *key)
|
||||
{
|
||||
TCCR1A &= ~(1 << COM1A1); // Wyłącz PWM
|
||||
LED_PWM_PORT &= ~(1 << LED_PWM1_PIN);
|
||||
estop_triggered = 1;
|
||||
// TCCR1A &= ~(1 << COM1A1); // Wyłącz PWM
|
||||
// LED_PWM_PORT &= ~(1 << LED_PWM1_PIN);
|
||||
}
|
||||
|
||||
void estop_off(ButtonKey_t *key)
|
||||
{
|
||||
TCCR1A |= (1 << COM1A1); // Włącz PWM
|
||||
// TCCR1A |= (1 << COM1A1); // Włącz PWM
|
||||
// LED_PWM_PORT |= (1 << LED_PWM_PIN);
|
||||
}
|
||||
Reference in New Issue
Block a user