From e75fb7c47b640ea329984d95fc9f4b2d7cd3efe4 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sat, 9 Apr 2016 10:56:10 +0200 Subject: because arduino is sooooooo frustrating Signed-off-by: Olivier Gayot --- arduino/Belt.h | 39 ------------------------- arduino/logs.cpp | 61 --------------------------------------- arduino/logs.h | 37 ------------------------ arduino/sketch_apr09a.ino | 64 ----------------------------------------- sketch_apr09a/Belt.h | 39 +++++++++++++++++++++++++ sketch_apr09a/logs.cpp | 61 +++++++++++++++++++++++++++++++++++++++ sketch_apr09a/logs.h | 37 ++++++++++++++++++++++++ sketch_apr09a/sketch_apr09a.ino | 64 +++++++++++++++++++++++++++++++++++++++++ 8 files changed, 201 insertions(+), 201 deletions(-) delete mode 100644 arduino/Belt.h delete mode 100644 arduino/logs.cpp delete mode 100644 arduino/logs.h delete mode 100644 arduino/sketch_apr09a.ino create mode 100644 sketch_apr09a/Belt.h create mode 100644 sketch_apr09a/logs.cpp create mode 100644 sketch_apr09a/logs.h create mode 100644 sketch_apr09a/sketch_apr09a.ino diff --git a/arduino/Belt.h b/arduino/Belt.h deleted file mode 100644 index 8a5cf6d..0000000 --- a/arduino/Belt.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _BELT_H -#define _BELT_H - -class Belt { -public: - Belt(); - - void read_pressure_top(); - void read_pressure_bottom(); - void read_flexion(); - void read_angle_x(); - void read_angle_y(); - void read_angle_z(); - - int get_pressure_top() const { return _pressure_top; }; - int get_pressure_bottom() const { return _pressure_bottom; }; - int get_flexion() const { return _flexion; }; - int get_angle_x() const { return _angle_x; }; - int get_angle_y() const { return _angle_y; }; - int get_angle_z() const { return _angle_z; }; - -protected: - int _pressure_bottom; - int _pressure_top; - int _flexion; - int _angle_x; - int _angle_y; - int _angle_z; - -private: - int _pin_pressure_top; - int _pin_pressure_bottom; - int _pin_flexion; - int _pin_gyro_x; - int _pin_gyro_y; - int _pin_gyro_z; -}; - -#endif /* ! _BELT_H */ diff --git a/arduino/logs.cpp b/arduino/logs.cpp deleted file mode 100644 index 901fd25..0000000 --- a/arduino/logs.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include - -int serial_write(uint8_t val) -{ - Serial.write(&val, 1); -} - -int serial_put_string(const char *str) -{ - while (*str) { - serial_write(*str++); - } - - return 0; -} - -int serial_puts(const char *str) -{ - serial_put_string(str); - - serial_write('\n'); - - return 0; -} - -int serial_printf(const char *fmt, ...) -{ - va_list ap; - - static char buf[256]; - - va_start(ap, fmt); - - vsnprintf(buf, sizeof(buf), fmt, ap); - - serial_put_string(buf); - - va_end(ap); - - return 0; -} - -#if 0 -int serial_print_dec(uint8_t opcode, int32_t integer) -{ - Serial.write(&opcode, 1); - Serial.println(integer, DEC); - return 0; -} - -int serial_print_hex(uint8_t opcode, int32_t integer) -{ - Serial.write(&opcode, 1); - Serial.println(integer, HEX); - return 0; -} -#endif - - - diff --git a/arduino/logs.h b/arduino/logs.h deleted file mode 100644 index 4124d03..0000000 --- a/arduino/logs.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef LOGS_H -#define LOGS_H - -#include - -#if 0 -enum { - OPCODE_LOGS = 0x89, - OPCODE_OK = 0x70, - OPCODE_ERR = 0x70, -}; - -#define serial_log serial_log_puts - -#define serial_log_puts(_str) serial_puts(OPCODE_LOGS, _str); -#define serial_log_print_dec(_int) serial_print_dec(OPCODE_LOGS, _int) -#define serial_log_print_hex(_int) serial_print_dec(OPCODE_LOGS, _int) - -#define serial_ok(_str) serial_puts(OPCODE_OK, _str); -#define serial_err(_str) serial_puts(OPCODE_ERR, _str); - -#endif - -int serial_puts(const char *str); -int serial_put_string(const char *str); -int serial_write(uint8_t value); -int serial_printf(const char *str, ...); - -#if 0 -int serial_print_dec(uint8_t opcode, int32_t integer); -int serial_print_hex(uint8_t opcode, int32_t integer); -#endif - -#endif - - - diff --git a/arduino/sketch_apr09a.ino b/arduino/sketch_apr09a.ino deleted file mode 100644 index af05cef..0000000 --- a/arduino/sketch_apr09a.ino +++ /dev/null @@ -1,64 +0,0 @@ -#include "Belt.h" -#include "logs.h" - -Belt::Belt() -{ - _pin_pressure_bottom = 0; - _pin_pressure_top = 1; - _pin_flexion = 2; - _pin_gyro_x = 3; - _pin_gyro_y = 4; - _pin_gyro_z = 5; -} - -void Belt::read_pressure_top() -{ - _pressure_top = analogRead(_pin_pressure_top); -} -void Belt::read_pressure_bottom() -{ - _pressure_bottom = analogRead(_pin_pressure_bottom); -} -void Belt::read_flexion() -{ - _flexion = analogRead(_pin_flexion); -} -void Belt::read_angle_x() -{ - _angle_x = analogRead(_pin_gyro_x); -} -void Belt::read_angle_y() -{ - _angle_y = analogRead(_pin_gyro_y); -} -void Belt::read_angle_z() -{ - _angle_z = analogRead(_pin_gyro_z); -} - -static Belt belt; - -void setup() -{ - Serial.begin(9600); -} - -void loop() -{ - delay(500); - - /* fetch the values from the sensors */ - belt.read_pressure_bottom(); - belt.read_pressure_top(); - belt.read_flexion(); - belt.read_angle_x(); - belt.read_angle_y(); - belt.read_angle_z(); - - serial_printf("PRESSURE_BOTTOM: bottom:%d\n", belt.get_pressure_bottom()); - serial_printf("PRESSURE_TOP:%d\n", belt.get_pressure_top()); - serial_printf("FLEXION:%d\n", belt.get_flexion()); - serial_printf("ANGLE_X:%d\n", belt.get_angle_x()); - serial_printf("ANGLE_Y:%d\n", belt.get_angle_y()); - serial_printf("ANGLE_Z:%d\n", belt.get_angle_z()); -} diff --git a/sketch_apr09a/Belt.h b/sketch_apr09a/Belt.h new file mode 100644 index 0000000..8a5cf6d --- /dev/null +++ b/sketch_apr09a/Belt.h @@ -0,0 +1,39 @@ +#ifndef _BELT_H +#define _BELT_H + +class Belt { +public: + Belt(); + + void read_pressure_top(); + void read_pressure_bottom(); + void read_flexion(); + void read_angle_x(); + void read_angle_y(); + void read_angle_z(); + + int get_pressure_top() const { return _pressure_top; }; + int get_pressure_bottom() const { return _pressure_bottom; }; + int get_flexion() const { return _flexion; }; + int get_angle_x() const { return _angle_x; }; + int get_angle_y() const { return _angle_y; }; + int get_angle_z() const { return _angle_z; }; + +protected: + int _pressure_bottom; + int _pressure_top; + int _flexion; + int _angle_x; + int _angle_y; + int _angle_z; + +private: + int _pin_pressure_top; + int _pin_pressure_bottom; + int _pin_flexion; + int _pin_gyro_x; + int _pin_gyro_y; + int _pin_gyro_z; +}; + +#endif /* ! _BELT_H */ diff --git a/sketch_apr09a/logs.cpp b/sketch_apr09a/logs.cpp new file mode 100644 index 0000000..901fd25 --- /dev/null +++ b/sketch_apr09a/logs.cpp @@ -0,0 +1,61 @@ +#include +#include + +int serial_write(uint8_t val) +{ + Serial.write(&val, 1); +} + +int serial_put_string(const char *str) +{ + while (*str) { + serial_write(*str++); + } + + return 0; +} + +int serial_puts(const char *str) +{ + serial_put_string(str); + + serial_write('\n'); + + return 0; +} + +int serial_printf(const char *fmt, ...) +{ + va_list ap; + + static char buf[256]; + + va_start(ap, fmt); + + vsnprintf(buf, sizeof(buf), fmt, ap); + + serial_put_string(buf); + + va_end(ap); + + return 0; +} + +#if 0 +int serial_print_dec(uint8_t opcode, int32_t integer) +{ + Serial.write(&opcode, 1); + Serial.println(integer, DEC); + return 0; +} + +int serial_print_hex(uint8_t opcode, int32_t integer) +{ + Serial.write(&opcode, 1); + Serial.println(integer, HEX); + return 0; +} +#endif + + + diff --git a/sketch_apr09a/logs.h b/sketch_apr09a/logs.h new file mode 100644 index 0000000..4124d03 --- /dev/null +++ b/sketch_apr09a/logs.h @@ -0,0 +1,37 @@ +#ifndef LOGS_H +#define LOGS_H + +#include + +#if 0 +enum { + OPCODE_LOGS = 0x89, + OPCODE_OK = 0x70, + OPCODE_ERR = 0x70, +}; + +#define serial_log serial_log_puts + +#define serial_log_puts(_str) serial_puts(OPCODE_LOGS, _str); +#define serial_log_print_dec(_int) serial_print_dec(OPCODE_LOGS, _int) +#define serial_log_print_hex(_int) serial_print_dec(OPCODE_LOGS, _int) + +#define serial_ok(_str) serial_puts(OPCODE_OK, _str); +#define serial_err(_str) serial_puts(OPCODE_ERR, _str); + +#endif + +int serial_puts(const char *str); +int serial_put_string(const char *str); +int serial_write(uint8_t value); +int serial_printf(const char *str, ...); + +#if 0 +int serial_print_dec(uint8_t opcode, int32_t integer); +int serial_print_hex(uint8_t opcode, int32_t integer); +#endif + +#endif + + + diff --git a/sketch_apr09a/sketch_apr09a.ino b/sketch_apr09a/sketch_apr09a.ino new file mode 100644 index 0000000..af05cef --- /dev/null +++ b/sketch_apr09a/sketch_apr09a.ino @@ -0,0 +1,64 @@ +#include "Belt.h" +#include "logs.h" + +Belt::Belt() +{ + _pin_pressure_bottom = 0; + _pin_pressure_top = 1; + _pin_flexion = 2; + _pin_gyro_x = 3; + _pin_gyro_y = 4; + _pin_gyro_z = 5; +} + +void Belt::read_pressure_top() +{ + _pressure_top = analogRead(_pin_pressure_top); +} +void Belt::read_pressure_bottom() +{ + _pressure_bottom = analogRead(_pin_pressure_bottom); +} +void Belt::read_flexion() +{ + _flexion = analogRead(_pin_flexion); +} +void Belt::read_angle_x() +{ + _angle_x = analogRead(_pin_gyro_x); +} +void Belt::read_angle_y() +{ + _angle_y = analogRead(_pin_gyro_y); +} +void Belt::read_angle_z() +{ + _angle_z = analogRead(_pin_gyro_z); +} + +static Belt belt; + +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ + delay(500); + + /* fetch the values from the sensors */ + belt.read_pressure_bottom(); + belt.read_pressure_top(); + belt.read_flexion(); + belt.read_angle_x(); + belt.read_angle_y(); + belt.read_angle_z(); + + serial_printf("PRESSURE_BOTTOM: bottom:%d\n", belt.get_pressure_bottom()); + serial_printf("PRESSURE_TOP:%d\n", belt.get_pressure_top()); + serial_printf("FLEXION:%d\n", belt.get_flexion()); + serial_printf("ANGLE_X:%d\n", belt.get_angle_x()); + serial_printf("ANGLE_Y:%d\n", belt.get_angle_y()); + serial_printf("ANGLE_Z:%d\n", belt.get_angle_z()); +} -- cgit v1.2.3