add estop trigger indicator

This commit is contained in:
2025-05-30 18:50:13 +02:00
parent ee136cc840
commit 943a92869f

View File

@@ -54,12 +54,20 @@ ButtonKey_t *inputs[3] = {
uint8_t ext_probe_connected = 0;
uint8_t estop_triggered = 0;
uint8_t blink_state = 0;
uint16_t last_blink_time = 0;
int main(void)
{
LED12_SW_DDR |= (1 << LED12_SW_PIN);
LED34_SW_DDR |= (1 << LED34_SW_PIN);
PROBE_OUT_DDR |= (1<< PROBE_OUT_PIN);
ESTOP_OUT_DDR |= (1<< ESTOP_OUT_PIN);
PROBE_OUT_PORT |= (1<< PROBE_OUT_PIN);
ESTOP_OUT_PORT |= (1<< ESTOP_OUT_PIN);
led_pwm();
timer0_init();
adc_init();
@@ -68,15 +76,34 @@ int main(void)
while (1)
{
// if (estop_triggered)
// {
// LED12_SW_PORT |= (1 << LED12_SW_PIN);
// LED34_SW_PORT &= ~(1 << LED34_SW_PIN);
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())
// LED12_SW_PORT &= ~(1 << LED12_SW_PIN);
// LED34_SW_PORT |= (1 << LED34_SW_PIN);
uint16_t now = ticks100us(); // Musisz mieć funkcję zwracającą czas w ms, np. z timer0
if (now - last_blink_time >= 5000) // 0.5 sekundy
{
last_blink_time = now;
blink_state = !blink_state;
if (blink_state)
{
LED12_SW_PORT |= (1 << LED12_SW_PIN);
LED34_SW_PORT &= ~(1 << LED34_SW_PIN);
}
else
{
LED12_SW_PORT &= ~(1 << LED12_SW_PIN);
LED34_SW_PORT |= (1 << LED34_SW_PIN);
}
}
}
else if (ext_probe_connected != is_device_connected())
{
ext_probe_connected = is_device_connected();
if (ext_probe_connected)
@@ -110,7 +137,9 @@ void led_pwm(void)
void probe_int_on(ButtonKey_t *key)
{
PROBE_OUT_PORT &= ~(1 << PROBE_OUT_PIN);
LED12_SW_PORT |= (1 << LED12_SW_PIN);
if (!ext_probe_connected)
{
LED34_SW_PORT |= (1 << LED34_SW_PIN);
@@ -119,7 +148,10 @@ void probe_int_on(ButtonKey_t *key)
void probe_int_off(ButtonKey_t *key)
{
estop_triggered = 0; // Reset estop when probe back to normal
PROBE_OUT_PORT |= (1 << PROBE_OUT_PIN);
LED12_SW_PORT &= ~(1 << LED12_SW_PIN);
if (!ext_probe_connected)
{
LED34_SW_PORT &= ~(1 << LED34_SW_PIN);
@@ -128,23 +160,28 @@ void probe_int_off(ButtonKey_t *key)
void probe_ext_on(ButtonKey_t *key)
{
PROBE_OUT_PORT &= ~(1 << PROBE_OUT_PIN);
LED34_SW_PORT &= ~(1 << LED34_SW_PIN);
}
void probe_ext_off(ButtonKey_t *key)
{
estop_triggered = 0; // Reset estop when probe back to normal
PROBE_OUT_PORT |= (1 << PROBE_OUT_PIN);
LED34_SW_PORT |= (1 << LED34_SW_PIN);
}
void estop_on(ButtonKey_t *key)
{
estop_triggered = 1;
ESTOP_OUT_PORT &= ~(1 << ESTOP_OUT_PIN);
// TCCR1A &= ~(1 << COM1A1); // Wyłącz PWM
// LED_PWM_PORT &= ~(1 << LED_PWM1_PIN);
}
void estop_off(ButtonKey_t *key)
{
ESTOP_OUT_PORT |= (1 << ESTOP_OUT_PIN);
// TCCR1A |= (1 << COM1A1); // Włącz PWM
// LED_PWM_PORT |= (1 << LED_PWM_PIN);
}