#include "base64.h"
#include "rtc.h"
#include "stepper.h"
-#include "log.h"
#include "cpp_magic.h"
#include <util/atomic.h>
static uint32_t timeout;
-void io_rtc_callback() {
+void io_callback() {
if (active_cmd.port == -1) return;
bool done = false;
float result = 0;
- if (active_cmd.mode == INPUT_IMMEDIATE ||
- rtc_expired(active_cmd.timeout)) done = true;
+ if (active_cmd.mode == INPUT_IMMEDIATE || rtc_expired(timeout)) done = true;
// TODO handle modes
if (active_cmd.digital) { // TODO
} else result = analog_get(active_cmd.port);
- // TODO find a better way to send this
printf_P(PSTR("{\"result\": %f}\n"), (double)result);
active_cmd.port = -1;
}
} input_mode_t;
-void io_rtc_callback();
+void io_callback();
+++ /dev/null
-/******************************************************************************\
-
- This file is part of the Buildbotics firmware.
-
- Copyright (c) 2015 - 2018, Buildbotics LLC
- All rights reserved.
-
- This file ("the software") is free software: you can redistribute it
- and/or modify it under the terms of the GNU General Public License,
- version 2 as published by the Free Software Foundation. You should
- have received a copy of the GNU General Public License, version 2
- along with the software. If not, see <http://www.gnu.org/licenses/>.
-
- The software is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the software. If not, see
- <http://www.gnu.org/licenses/>.
-
- For information regarding this software email:
- "Joseph Coffland" <joseph@buildbotics.com>
-
-\******************************************************************************/
-
-#pragma once
-
-#ifdef __AVR__
-#define LOG(...)
-#else
-#include <stdio.h>
-#define LOG(...) fprintf(stderr, __VA_ARGS__)
-#endif
#include "pgmspace.h"
#include "outputs.h"
#include "analog.h"
+#include "modbus.h"
+#include "io.h"
#include "exec.h"
#include "state.h"
#include "emu.h"
hw_reset_handler(); // handle hard reset requests
state_callback(); // manage state
command_callback(); // process next command
+ modbus_callback(); // handle modbus events
+ io_callback(); // handle io input
report_callback(); // report changes
}
//
// At 9600 baud the minimum delay is 4.01ms. At 19200 it's 2.005ms. All
// supported higher baud rates require the 1.75ms minimum delay. We round up
- // and add 1ms to ensure the delay is never less than the required minimum
- // using our 1ms RTC clock callback.
+ // and add 1ms to ensure the delay is never less than the required minimum.
if (state.last_read &&
!rtc_expired(state.last_read + (cfg.baud == USART_BAUD_9600 ? 5 : 3)))
return;
}
-void modbus_rtc_callback() {
+void modbus_callback() {
if (state.transmit_complete) {
state.last_write = rtc_get_time();
state.transmit_complete = false;
_handle_response();
_start_write();
+ // Timeout out writes
if (!state.last_write || !rtc_expired(state.last_write + MODBUS_TIMEOUT))
return;
state.last_write = 0;
uint8_t receive, modbus_cb_t cb);
void modbus_read(uint16_t addr, uint16_t count, modbus_rw_cb_t cb);
void modbus_write(uint16_t addr, uint16_t value, modbus_rw_cb_t cb);
-void modbus_rtc_callback();
+void modbus_callback();
#include "switch.h"
#include "analog.h"
-#include "io.h"
-#include "modbus.h"
#include "motor.h"
#include "lcd.h"
#include "vfd_spindle.h"
lcd_rtc_callback();
switch_rtc_callback();
analog_rtc_callback();
- io_rtc_callback();
- modbus_rtc_callback();
vfd_spindle_rtc_callback();
if (!(ticks & 255)) motor_rtc_callback();
wdt_reset();
#include <stdarg.h>
-stat_t status_code; // allocate a variable for the RITORNO macro
-
-
#define STAT_MSG(NAME, TEXT) static const char stat_##NAME[] PROGMEM = TEXT;
#include "messages.def"
#undef STAT_MSG
#include "pgmspace.h"
-// RITORNO is a handy way to provide exception returns
-// It returns only if an error occurred. (ritorno is Italian for return)
-#define RITORNO(a) if ((status_code = a) != STAT_OK) {return status_code;}
-
typedef enum {
#define STAT_MSG(NAME, TEXT) STAT_##NAME,
#include "messages.def"
buf[i * 2] = 0;
}
-
-
-void print_vector(float v[4]) {
- printf_P(PSTR("%f %f %f %f\n"),
- (double)v[0], (double)v[1], (double)v[2], (double)v[3]);
-}
bool decode_float(char **s, float *f);
stat_t decode_axes(char **cmd, float axes[AXES]);
void format_hex_buf(char *buf, const uint8_t *data, unsigned len);
-void print_vector(float v[4]);
// Constants
#define MM_PER_INCH 25.4