diff --git a/.vscode/ipch/50dec0c3b2c204ec/MAINMENU.ipch b/.vscode/ipch/50dec0c3b2c204ec/MAINMENU.ipch new file mode 100644 index 0000000..29ab791 Binary files /dev/null and b/.vscode/ipch/50dec0c3b2c204ec/MAINMENU.ipch differ diff --git a/.vscode/ipch/50dec0c3b2c204ec/mmap_address.bin b/.vscode/ipch/50dec0c3b2c204ec/mmap_address.bin new file mode 100644 index 0000000..862b842 Binary files /dev/null and b/.vscode/ipch/50dec0c3b2c204ec/mmap_address.bin differ diff --git a/.vscode/ipch/6b082762e1adc445/LANGUAGE_PL.ipch b/.vscode/ipch/6b082762e1adc445/LANGUAGE_PL.ipch new file mode 100644 index 0000000..8c9bd55 Binary files /dev/null and b/.vscode/ipch/6b082762e1adc445/LANGUAGE_PL.ipch differ diff --git a/.vscode/ipch/6b082762e1adc445/mmap_address.bin b/.vscode/ipch/6b082762e1adc445/mmap_address.bin new file mode 100644 index 0000000..862b842 Binary files /dev/null and b/.vscode/ipch/6b082762e1adc445/mmap_address.bin differ diff --git a/.vscode/ipch/898cd4311745004d/LCDTEST.ipch b/.vscode/ipch/898cd4311745004d/LCDTEST.ipch new file mode 100644 index 0000000..c8ad40f Binary files /dev/null and b/.vscode/ipch/898cd4311745004d/LCDTEST.ipch differ diff --git a/.vscode/ipch/898cd4311745004d/mmap_address.bin b/.vscode/ipch/898cd4311745004d/mmap_address.bin new file mode 100644 index 0000000..862b842 Binary files /dev/null and b/.vscode/ipch/898cd4311745004d/mmap_address.bin differ diff --git a/.vscode/ipch/8ef03cb639804c5e/LANGUAGE_EN.ipch b/.vscode/ipch/8ef03cb639804c5e/LANGUAGE_EN.ipch new file mode 100644 index 0000000..3526f81 Binary files /dev/null and b/.vscode/ipch/8ef03cb639804c5e/LANGUAGE_EN.ipch differ diff --git a/.vscode/ipch/8ef03cb639804c5e/mmap_address.bin b/.vscode/ipch/8ef03cb639804c5e/mmap_address.bin new file mode 100644 index 0000000..862b842 Binary files /dev/null and b/.vscode/ipch/8ef03cb639804c5e/mmap_address.bin differ diff --git a/.vscode/ipch/99cba134f7a7373/SHUTTER.ipch b/.vscode/ipch/99cba134f7a7373/SHUTTER.ipch index 138b9cb..a8c2171 100644 Binary files a/.vscode/ipch/99cba134f7a7373/SHUTTER.ipch and b/.vscode/ipch/99cba134f7a7373/SHUTTER.ipch differ diff --git a/.vscode/ipch/ae9c0bfe9840cd4a/MANUAL_CONTROL.ipch b/.vscode/ipch/ae9c0bfe9840cd4a/MANUAL_CONTROL.ipch new file mode 100644 index 0000000..f8ce1b8 Binary files /dev/null and b/.vscode/ipch/ae9c0bfe9840cd4a/MANUAL_CONTROL.ipch differ diff --git a/.vscode/ipch/ae9c0bfe9840cd4a/mmap_address.bin b/.vscode/ipch/ae9c0bfe9840cd4a/mmap_address.bin new file mode 100644 index 0000000..862b842 Binary files /dev/null and b/.vscode/ipch/ae9c0bfe9840cd4a/mmap_address.bin differ diff --git a/.vscode/ipch/b62bc01825d892db/LCD16X2.ipch b/.vscode/ipch/b62bc01825d892db/LCD16X2.ipch new file mode 100644 index 0000000..788bc39 Binary files /dev/null and b/.vscode/ipch/b62bc01825d892db/LCD16X2.ipch differ diff --git a/.vscode/ipch/b62bc01825d892db/mmap_address.bin b/.vscode/ipch/b62bc01825d892db/mmap_address.bin new file mode 100644 index 0000000..862b842 Binary files /dev/null and b/.vscode/ipch/b62bc01825d892db/mmap_address.bin differ diff --git a/.vscode/ipch/be1a6bee4fe968f1/MENU.ipch b/.vscode/ipch/be1a6bee4fe968f1/MENU.ipch new file mode 100644 index 0000000..c136f6c Binary files /dev/null and b/.vscode/ipch/be1a6bee4fe968f1/MENU.ipch differ diff --git a/.vscode/ipch/be1a6bee4fe968f1/mmap_address.bin b/.vscode/ipch/be1a6bee4fe968f1/mmap_address.bin new file mode 100644 index 0000000..862b842 Binary files /dev/null and b/.vscode/ipch/be1a6bee4fe968f1/mmap_address.bin differ diff --git a/.vscode/ipch/c8307ced0f7c51ce/READKNOB.ipch b/.vscode/ipch/c8307ced0f7c51ce/READKNOB.ipch new file mode 100644 index 0000000..ea7eefa Binary files /dev/null and b/.vscode/ipch/c8307ced0f7c51ce/READKNOB.ipch differ diff --git a/.vscode/ipch/c8307ced0f7c51ce/mmap_address.bin b/.vscode/ipch/c8307ced0f7c51ce/mmap_address.bin new file mode 100644 index 0000000..862b842 Binary files /dev/null and b/.vscode/ipch/c8307ced0f7c51ce/mmap_address.bin differ diff --git a/.vscode/ipch/ccd566860d258573/DEFINITIONS.ipch b/.vscode/ipch/ccd566860d258573/DEFINITIONS.ipch new file mode 100644 index 0000000..698f0c6 Binary files /dev/null and b/.vscode/ipch/ccd566860d258573/DEFINITIONS.ipch differ diff --git a/.vscode/ipch/ccd566860d258573/mmap_address.bin b/.vscode/ipch/ccd566860d258573/mmap_address.bin new file mode 100644 index 0000000..862b842 Binary files /dev/null and b/.vscode/ipch/ccd566860d258573/mmap_address.bin differ diff --git a/.vscode/ipch/e4474fbc0824ecaa/LCDTEST.ipch b/.vscode/ipch/e4474fbc0824ecaa/LCDTEST.ipch new file mode 100644 index 0000000..36a8394 Binary files /dev/null and b/.vscode/ipch/e4474fbc0824ecaa/LCDTEST.ipch differ diff --git a/.vscode/ipch/e4474fbc0824ecaa/mmap_address.bin b/.vscode/ipch/e4474fbc0824ecaa/mmap_address.bin new file mode 100644 index 0000000..862b842 Binary files /dev/null and b/.vscode/ipch/e4474fbc0824ecaa/mmap_address.bin differ diff --git a/SliderSoftware.ino b/SliderSoftware.ino index 414028b..b94dc0d 100644 --- a/SliderSoftware.ino +++ b/SliderSoftware.ino @@ -1,31 +1,41 @@ #include "definitions.h" #include "lcd16x2.h" #include "motor.h" - -#ifdef REMOTE_SHUTTER - #include "shutter.h" -#endif //REMOTE_SHUTTER - +#include +#include "readKnob.h" +#include "shutter.h" Motor stepper = Motor(PIN_STEPPER_A1, PIN_STEPPER_A2, PIN_STEPPER_B1, PIN_STEPPER_B2,\ - PIN_ENDSTOP, PIN_CANCEL, STEPS_PER_MM, DEFAULT_SPEED, FLIP_DIRECTION, ENABLE_ENDSTOPS, MAX_STEPS); + PIN_ENDSTOP, PIN_CANCEL, STEPS_PER_MM, DEFAULT_SPEED, FLIP_DIRECTION); Display lcd = Display(PIN_LCD_RS, PIN_LCD_E, PIN_LCD_D4, PIN_LCD_D5, PIN_LCD_D6, PIN_LCD_D7); +Encoder encoder = Encoder(PIN_ENCODER_A, PIN_ENCODER_B); -#ifdef USE_AF Shutter shutter = Shutter(PIN_SHUTTER, PIN_AF, SHUTTER_INVERT); -#else -Shutter shutter = Shutter(PIN_SHUTTER, SHUTTER_INVERT); -#endif //USE_AF +#include "menu.h" -void setup() -{ +pinMode(PIN_ENCODER_PRESS, INPUT_PULLUP); +pinMode(PIN_CANCEL, INPUT_PULLUP); +// -- INCLUDE SUBPROGRAMS HERE-- // +#include "manualControl.h" +//#include "home.h" +//#include "setup.h" + +// -- MAIN MENU -- // +MenuItem subprograms[] = \ +{ + MenuItem(T_MANUAL_CONTROL, &manualControl::main()), + //MenuItem(T_HOME, &home()), + //MenuItem(T_SETUP_MENU, &setupMenu()), } +Menu mainMenu = Menu(&lcd, &encoder, PIN_ENCODER_PRESS, PIN_CANCEL, &subprograms) + + void loop() { - -} \ No newline at end of file + mainMenu.run(); +} diff --git a/definitions.h b/definitions.h index 4221083..d44249f 100644 --- a/definitions.h +++ b/definitions.h @@ -3,16 +3,15 @@ //--------------------------------------------------------------- //--CONFIG //--------------------------------------------------------------- -#define REMOTE_SHUTTER -#ifdef REMOTE_SHUTTER - #define SHUTTER_INVERT false //set to true if shutter triggers on LOW - #define USE_AF -#endif //REMOTE_SHUTTER +//LANGUAGE: -#define USB_SERIAL -#define ENCODER +#include "language_en.h" //ENGLISH +//#include "language_pl.h" //POLISH + +#define USB_SERIAL +#define REMOTE_SHUTTER #define LCD_16x2 //#define LCD_BACKLIGHT #ifdef LCD_BACKLIGHT @@ -20,33 +19,35 @@ #define LCD_BACKLIGHT_DIGITAL #endif //LCD_BACKLIGHT -#define STEPS_PER_MM 1600L //steps per rotation * screw pitch +#define STEPS_PER_MM 25.f // screw pitch / steps per rotation +#define MANUAL_STEPS {1,5,25,125,1250} #define DEFAULT_SPEED 10.f //in mm/s +#define FLIP_DIRECTION false //stepper direction #define SOFTWARE_ENDSTOPS #ifdef SOFTWARE_ENDSTOPS - #define SLIDER_LENGHT_MM 200L + #define SLIDER_LENGHT_MM 200f #endif //SOFTWARE_ENDSTOPS +#define SHUTTER_INVERT false //set to true if shutter triggers on LOW + + //--------------------------------------------------------------- //--PINS //--------------------------------------------------------------- -#ifdef ENCODER - #define PIN_ENCODER_A - #define PIN_ENCODER_B - #define PIN_ENCODER_PRESS -#endif //ENCODER - -#define PIN_CANCEL -#define PIN_ENDSTOP +#define PIN_ENCODER_A 6 +#define PIN_ENCODER_B 5 +#define PIN_ENCODER_PRESS 4 +#define PIN_CANCEL 3 +#define PIN_ENDSTOP 2 #ifdef LCD_16x2 - #define PIN_LCD_RS 1 - #define PIN_LCD_E 2 - #define PIN_LCD_D4 4 - #define PIN_LCD_D5 3 - #define PIN_LCD_D6 5 - #define PIN_LCD_D7 6 + #define PIN_LCD_RS 7 + #define PIN_LCD_E 8 + #define PIN_LCD_D4 9 + #define PIN_LCD_D5 10 + #define PIN_LCD_D6 11 + #define PIN_LCD_D7 12 #endif //LCD_16x2 #ifdef LCD_BACKLIGHT @@ -54,24 +55,14 @@ #endif //PIN_LCD_BACKLIGHT #ifdef REMOTE_SHUTTER - #define PIN_SHUTTER + #define PIN_SHUTTER A1 + #define PIN_AF A0 #endif //REMOTE_SHUTTER -#ifdef USE_AF - #define PIN_AF -#endif +#define PIN_STEPPER_A1 A3 +#define PIN_STEPPER_A2 A2 +#define PIN_STEPPER_B1 A5 +#define PIN_STEPPER_B2 A4 -#define PIN_STEPPER_A1 -#define PIN_STEPPER_A2 -#define PIN_STEPPER_B1 -#define PIN_STEPPER_B2 - -//------------------------------------------------------------------ -//--LIBRARIES -//------------------------------------------------------------------ -#ifdef ENCODER - #define ENCODER_LIBRARY -#endif //ENCODER - -#endif //definitions_h +#endif diff --git a/language_en.h b/language_en.h new file mode 100644 index 0000000..1c39790 --- /dev/null +++ b/language_en.h @@ -0,0 +1,8 @@ +// "0123456789ABCDEF" +#define T_MANUAL_CONTROL "Manual control" + #define T_MANUAL_POSITION "Position" + #define T_MANUAL_SET_STEP "Step" + #define T_MANUAL_MOVE "Move" + #define T_MANUAL_STEP "Set step" +#define T_HOME "Home slider" +#define T_SETUP_MENU "Auto shooting" \ No newline at end of file diff --git a/language_pl.h b/language_pl.h new file mode 100644 index 0000000..a8605ad --- /dev/null +++ b/language_pl.h @@ -0,0 +1,8 @@ +// "0123456789ABCDEF" +#define T_MANUAL_CONTROL "Ster. reczne" + #define T_MANUAL_POSITION "Pozycja" + #define T_MANUAL_SET_STEP "Krok" + #define T_MANUAL_MOVE "Sterowanie" + #define T_MANUAL_STEP "Ustaw. kroku" +#define T_HOME "Zerowanie" +#define T_SETUP_MENU "Ster. auto" \ No newline at end of file diff --git a/lcd16x2.h b/lcd16x2.h index 64f325a..7626d90 100644 --- a/lcd16x2.h +++ b/lcd16x2.h @@ -1,11 +1,8 @@ #ifndef lcd16x2_h #define lcd16x2_h #include -#include /* - - Bottom line layout: 0123456789ABCDEF @@ -21,22 +18,22 @@ class Display public: void writeTopLine(String text); void writeBottomLine(String text); - void writeBottomLeft(String text); - void writeBottomMiddle(String text); - void writeBottomRight(String text); + String getTopLine(); + String getBottomLine(); Display(int pin_E, int pin_RS, int pin_D4, int pin_D5, int pin_D6, int pin_D7); + void update(); private: String currentText[2]; - LiquidCrystal lcd; - void update(); + LiquidCrystal* lcd; + }; -Display::Display(int pin_RS, int pin_E, int pin_D4, int pin_D5, int pin_D6, int pin_D7): +Display::Display(int pin_RS, int pin_E, int pin_D4, int pin_D5, int pin_D6, int pin_D7) { - lcd = LiquidCrystal(pin_RS,pin_E,pin_D4,pin_D5,pin_D6,pin_D7); - lcd.begin(16,2); + *lcd = LiquidCrystal(pin_RS,pin_E,pin_D4,pin_D5,pin_D6,pin_D7); + lcd->begin(16,2); currentText[0].reserve(16); currentText[1].reserve(16); @@ -44,27 +41,15 @@ Display::Display(int pin_RS, int pin_E, int pin_D4, int pin_D5, int pin_D6, int void Display::update() { - lcd.clear(); - lcd.print(currentText[0]); - lcd.setCursor(1,0); - lcd.print(currentText[1]); + lcd->clear(); + lcd->print(currentText[0]); + lcd->setCursor(1,0); + lcd->print(currentText[1]); } -/* - - -Bottom line layout: - -0123456789ABCDEF -LEFT| - MIDDLE - |RIGH -0123456789ABCDEF - -*/ void Display::writeTopLine(String text) { - while(text.lenght() < 0xF) text += " "; + while(text.length() < 0xF) text += " "; text = text.substring(0x0,0xF); currentText[0]=text; update(); @@ -72,36 +57,20 @@ void Display::writeTopLine(String text) void Display::writeBottomLine(String text) { - while(text.lenght() < 0xF) text += " "; + while(text.length() < 0xF) text += " "; text = text.substring(0x0,0xF); currentText[1]=text; update(); } -void Display::writeBottomLeft(String text) -{ - - while(text.lenght() < 0x5) text += " "; - text = text.substring(0x0,0x5); - currentText[1]= text + currentText[1].substring(0x5); - update(); -} - -void Display::writeBottomMiddle(String text) +String Display::getTopLine() { - while(text.lenght() < 0x6) text += " "; - text = text.substring(0x0,0x6); - currentText[1]= currentText[1].substring(0x0,0x5) + text + currentText[1].substring(0xB); - update(); + return currentText[0]; } -void Display::writeBottomRight(String text) +String Display::getBottomLine() { - while(text.lenght < 0x5) text += " "; - text = text.substring(0x0,0x5); - currentText[1]= currentText[1].substring(0x0,0xB)+text; - update(); + return currentText[1]; } #endif //lcd16x2_h - diff --git a/lcdTest.ino b/lcdTest.ino new file mode 100644 index 0000000..ced5624 --- /dev/null +++ b/lcdTest.ino @@ -0,0 +1,15 @@ +#include "definitions.h" +#include "lcd16x2.h" + +Display lcd = Display(PIN_LCD_RS, PIN_LCD_E, PIN_LCD_D4, PIN_LCD_D5, PIN_LCD_D6, PIN_LCD_D7); + +void setup() +{ + lcd.writeTopLine("0123456789ABCDEF"); + lcd.writeBottomLine("FEDCBA9876543210"); +} + +void loop() +{ + +} diff --git a/lcdTest/definitions.h b/lcdTest/definitions.h new file mode 100644 index 0000000..a763d21 --- /dev/null +++ b/lcdTest/definitions.h @@ -0,0 +1,67 @@ +#ifndef definitions_h +#define definitions_h +//--------------------------------------------------------------- +//--CONFIG +//--------------------------------------------------------------- + +//LANGUAGE: + +//#include "language_en.h" //ENGLISH +//#include "language_pl.h" //POLISH + +#ifdef REMOTE_SHUTTER + #define SHUTTER_INVERT false //set to true if shutter triggers on LOW +#endif //REMOTE_SHUTTER + +#define USB_SERIAL +#define REMOTE_SHUTTER +#define LCD_16x2 +//#define LCD_BACKLIGHT +#ifdef LCD_BACKLIGHT + #define LCD_BACKLIGHT_ANALOG + #define LCD_BACKLIGHT_DIGITAL +#endif //LCD_BACKLIGHT + +#define STEPS_PER_MM 25.f // screw pitch / steps per rotation +#define MANUAL_STEPS {1,5,25,125,1250} +#define DEFAULT_SPEED 10.f //in mm/s + +#define SOFTWARE_ENDSTOPS +#ifdef SOFTWARE_ENDSTOPS + #define SLIDER_LENGHT_MM 200f +#endif //SOFTWARE_ENDSTOPS + +//--------------------------------------------------------------- +//--PINS +//--------------------------------------------------------------- +#define PIN_ENCODER_A 6 +#define PIN_ENCODER_B 5 +#define PIN_ENCODER_PRESS 4 +#define PIN_CANCEL 3 +#define PIN_ENDSTOP 2 + +#ifdef LCD_16x2 + #define PIN_LCD_RS 7 + #define PIN_LCD_E 8 + #define PIN_LCD_D4 9 + #define PIN_LCD_D5 10 + #define PIN_LCD_D6 11 + #define PIN_LCD_D7 12 +#endif //LCD_16x2 + +#ifdef LCD_BACKLIGHT + #define PIN_LCD_BACKLIGHT +#endif //PIN_LCD_BACKLIGHT + +#ifdef REMOTE_SHUTTER + #define PIN_SHUTTER A1 + #define PIN_AF A0 +#endif //REMOTE_SHUTTER + +#define PIN_STEPPER_A1 A3 +#define PIN_STEPPER_A2 A2 +#define PIN_STEPPER_B1 A5 +#define PIN_STEPPER_B2 A4 + + +#endif diff --git a/lcdTest/lcd16x2.h b/lcdTest/lcd16x2.h new file mode 100644 index 0000000..689005a --- /dev/null +++ b/lcdTest/lcd16x2.h @@ -0,0 +1,105 @@ +#ifndef lcd16x2_h +#define lcd16x2_h +#include + +/* +Bottom line layout: + +0123456789ABCDEF +LEFT| + MIDDLE + |RIGH +0123456789ABCDEF + +*/ + +class Display +{ + public: + void writeTopLine(String text); + void writeBottomLine(String text); + void writeBottomLeft(String text); + void writeBottomMiddle(String text); + void writeBottomRight(String text); + Display(int pin_RS, int pin_E, int pin_D4, int pin_D5, int pin_D6, int pin_D7); + private: + String currentText[2]; + LiquidCrystal* lcd; + void update(); + + +}; + +Display::Display(int pin_RS, int pin_E, int pin_D4, int pin_D5, int pin_D6, int pin_D7) +{ + *lcd = LiquidCrystal(pin_RS,pin_E,pin_D4,pin_D5,pin_D6,pin_D7); + lcd->begin(16,2); + + currentText[0].reserve(16); + currentText[1].reserve(16); + + lcd->write("TEST"); +} + +void Display::update() +{ + lcd->clear(); + lcd->print(currentText[0]); + lcd->setCursor(1,0); + lcd->print(currentText[1]); +} + +/* + + +Bottom line layout: + +0123456789ABCDEF +LEFT| + MIDDLE + |RIGH +0123456789ABCDEF + +*/ +void Display::writeTopLine(String text) +{ + while(text.length() < 0xF) text += " "; + text = text.substring(0x0,0xF); + currentText[0]=text; + update(); +} + +void Display::writeBottomLine(String text) +{ + while(text.length() < 0xF) text += " "; + text = text.substring(0x0,0xF); + currentText[1]=text; + update(); +} + +void Display::writeBottomLeft(String text) +{ + + while(text.length() < 0x5) text += " "; + text = text.substring(0x0,0x5); + currentText[1]= text + currentText[1].substring(0x5); + update(); +} + +void Display::writeBottomMiddle(String text) +{ + while(text.length() < 0x6) text += " "; + text = text.substring(0x0,0x6); + currentText[1]= currentText[1].substring(0x0,0x5) + text + currentText[1].substring(0xB); + update(); +} + +void Display::writeBottomRight(String text) +{ + while(text.length() < 0x5) text += " "; + text = text.substring(0x0,0x5); + currentText[1]= currentText[1].substring(0x0,0xB)+text; + update(); +} + +#endif //lcd16x2_h diff --git a/lcdTest/lcdTest.ino b/lcdTest/lcdTest.ino new file mode 100644 index 0000000..532661d --- /dev/null +++ b/lcdTest/lcdTest.ino @@ -0,0 +1,18 @@ + + +#include "definitions.h" +#include "lcd16x2.h" + + +Display lcd = Display(PIN_LCD_RS, PIN_LCD_E, PIN_LCD_D4, PIN_LCD_D5, PIN_LCD_D6, PIN_LCD_D7); + +void setup() +{ + lcd.writeTopLine("0123456789ABCDEF"); + lcd.writeBottomLine("FEDCBA9876543210"); +} + +void loop() +{ + +} diff --git a/manualControl.h b/manualControl.h new file mode 100644 index 0000000..0dc23e9 --- /dev/null +++ b/manualControl.h @@ -0,0 +1,114 @@ +#ifndef manualControl_h +#define manualControl_h +#include "menu.h" +#include "motor.h" + +namespace manualControl +{ + long steps[] = MANUAL_STEPS; + long sizeofSteps = sizeof(steps)/sizeof(steps[0]); + int motor_step_index = 0; + int current_step_index = 0; + bool exit_flag = false; + + // -- STEP SELECTION -- // + void stepUp() + { + if(current_step_index + 1 < sizeofSteps) + current_step_index++; + } + void stepDown() + { + if(current_step_index >0) + current_step_index--; + } + void stepOK() + { + motor_step_index = current_step_index; + exit_flag = true; + } + void stepCancel() + { + exit_flag = true; + } + + //0123456789ABCDEF + // 000.00 mm + void step() + { + current_step_index = motor_step_index; + while(!exit_flag) + { + lcd->writeTopLine(T_MANUAL_SET_STEP); + lcd->writeBottomLine(" "+String(steps[current_step_index]/STEPS_PER_MM,2)+" mm"); + readKnob(&encoder, PIN_ENCODER_PRESS, PIN_CANCEL, &stepUp, &stepDown, &stepOK, &stepCancel); + } + exit_flag = false; + + } + + + // -- MOVE -- // + + long steps_to_move = 0 + + void moveUp() + { + if(steps_to_move + position + 1 < MAX_STEPS) + steps_to_move++; + } + + void moveDown() + { + if(steps_to_move + position - 1 >= 0) + steps_to_move--; + + } + + void moveOK() + { + stepper.move(steps_to_move); + } + + void moveCancel() + { + exit_flag = true; + } + + void move() + { + long position = stepper.getStep(); + float position_mm = stepper.getStep()/STEPS_PER_MM; + + while (!exit_flag) + { + lcd->writeTopLine(T_MANUAL_POSITION+" "+String(position_mm,2)+"mm"); + + float steps_to_move_mm = steps_to_move / STEPS_PER_MM; + lcd->writeBottomLine(String(steps_to_move_mm,2)+"mm "+\ + String(position_mm+steps_to_move_mm,2)+"mm"); + + readKnob(&encoder, PIN_ENCODER_PRESS, PIN_CANCEL, \ + &moveUp, &moveDown, &moveOK, &moveCancel); + } + exit_flag = false; + } + + + // -- SUBMENU -- // + + + MenuItem* submenu_items = \ + [ + MenuItem(T_MANUAL_MOVE, &move), + MenuItem(T_MANUAL_STEP, &step) + ]; + + Menu submenu = Menu(&lcd, &encoder, PIN_ENCODER_PRESS, PIN_CANCEL, submenu_items); + + void main() + { + submenu.run(); + } +} +#endif \ No newline at end of file diff --git a/menu.h b/menu.h new file mode 100644 index 0000000..8647eee --- /dev/null +++ b/menu.h @@ -0,0 +1,110 @@ +#ifndef menu_h +#define menu_h + +#include "lcd16x2.h" +#include +#include "readKnob.h" + +typedef struct s_menuItem {String subprogram_name; void(*subprogram)();} MenuItem; + +class Menu +{ + public: + unsigned int current_item = 0; + private: + Encoder* knob; + Display* lcd; + int pinOK; + int pinCancel; + MenuItem* items; + unsigned int menuLenght; + bool exitFlag = false; + void run(unsigned int start_from_item=0); + public: + void menuUp(); + void menuDown(); + void menuOK(); + void menuCancel(); + + public: + + Menu(Display* lcd, Encoder* knob, int pinOK, int pinCancel, MenuItem* items,\ + unsigned int start_from_item = 0): lcd(lcd),knob(knob), pinOK(pinOK), \ + pinCancel(pinCancel),items(items) + { + pinMode(pinOK, INPUT_PULLUP); + pinMode(pinCancel, INPUT_PULLUP); + menuLenght = sizeof(items)/sizeof(items[0]); + } +}; + +void Menu::menuUp() +{ + if(current_item < menuLenght - 1) + { + current_item++; + lcd->writeTopLine(">"+items[current_item].subprogram_name); + + if(current_item < menuLenght - 1) + lcd->writeBottomLine(" "+items[current_item+1].subprogram_name); + else + lcd->writeBottomLine(" "); + } +} + +void Menu::menuDown() +{ + if(current_item > 0) + { + current_item--; + lcd->writeTopLine(">"+items[current_item].subprogram_name); + + if(current_item < menuLenght - 1) + lcd->writeBottomLine(" "+items[current_item+1].subprogram_name); + else + lcd->writeBottomLine(" "); + + } +} + +void Menu::menuOK() +{ + items[current_item].subprogram(); +} + +void Menu::menuCancel() +{ + exitFlag = true; +} + +void Menu::run(unsigned int start_from_item) +{ + current_item = start_from_item; + + lcd->writeTopLine(">"+items[current_item].subprogram_name); + + if(current_item < menuLenght - 1) + lcd->writeBottomLine(" "+items[current_item+1].subprogram_name); + else + lcd->writeBottomLine(" "); + + while(!exitFlag) + { + int knobPosition = knob->read()/4; + while (knobPosition > 0) + { + menuUp(); + knobPosition--; + } + while (knobPosition < 0) + { + menuDown(); + knobPosition++; + } + knob->write(0); + if(digitalRead(pinOK)==LOW) menuOK(); + if(digitalRead(pinCancel)==LOW) menuCancel(); + } +} + +#endif //menu_h diff --git a/motor.h b/motor.h index 1ad3921..eb67aa3 100644 --- a/motor.h +++ b/motor.h @@ -1,18 +1,23 @@ #ifndef motor_h #define motor_h +#include + volatile bool motorStopFlag = false; volatile bool endstopFlag = false; + //improvement - use namespace for flags class Motor { + public: long move(long steps, bool enable_endstops = true); - float move(float distance_mm, enable_endstops = true); - float setSpeed(float speed_mm_per_second); + float move(float distance_mm, bool enable_endstops = true); + void setSpeed(float speed_mm_per_second); long getStep(); float getPosition(); Motor(int pinA1, int pinA2, int pinB1, int pinB2, int pinEndstop, int pinCancel, long steps_per_mm,\ float speed_mm_per_second, bool flip_direction = false, long max_steps = LONG_MAX); long autoHome(); + long fullHome(); private: void makeStep(bool clockwise); @@ -25,13 +30,17 @@ class Motor int pinA2; int pinB1; int pinB2; + int pinEndstop; + int pinCancel; + bool enable_endstops; bool flip_direction; long max_steps; +}; Motor::Motor(int pinA1, int pinA2, int pinB1, int pinB2, int pinEndstop, int pinCancel, long steps_per_mm, \ float speed_mm_per_second, bool flip_direction = false, long max_steps = LONG_MAX):\ - pinA1(pinA1),pinA2(pinA2),pinB1(pinB1),pinB2(pin_B2),pinEndstop(),pinCancel(), \ + pinA1(pinA1),pinA2(pinA2),pinB1(pinB1),pinB2(pinB2),pinEndstop(pinEndstop),pinCancel(pinCancel), \ steps_per_mm(steps_per_mm),flip_direction(flip_direction),enable_endstops(enable_endstops) { pinMode(pinA1, OUTPUT); @@ -47,8 +56,18 @@ void Motor::setSpeed(float speed_mm_per_second) { interval = 1e6 / steps_per_mm / speed_mm_per_second; } +void interruptEndstop() +{ + motorStopFlag = true; + endstopFlag = true; +} + +void interruptCancel() +{ + motorStopFlag = true; +} -long Motor::move(long steps, bool enable_endstops = true;) +long Motor::move(long steps, bool enable_endstops = true) { attachInterrupt(digitalPinToInterrupt(pinEndstop),interruptEndstop, FALLING); attachInterrupt(digitalPinToInterrupt(pinCancel),interruptCancel, FALLING); @@ -63,7 +82,7 @@ long Motor::move(long steps, bool enable_endstops = true;) long remaining_steps = abs(steps_to_do); - bool dir = (distance >= 0) ? 1 : 0; + bool dir = (steps >= 0) ? 1 : 0; if(flip_direction) dir = !dir; while(remaining_steps>0 && motorStopFlag == false) @@ -167,16 +186,6 @@ float Motor::getPosition() return (float)stepNumber/steps_per_mm; } -void interruptEndstop() -{ - motorStopFlag = true; - endstopFlag = true; -} - -void interruptCancel() -{ - motorStopFlag = true; -} long Motor::autoHome() { @@ -192,12 +201,12 @@ long Motor::autoHome() long Motor::fullHome() { autoHome(); - move(LONG_MAX,false) + move(LONG_MAX,false); if (endstopFlag) { max_steps = stepNumber; endstopFlag = false; } - return stepNumber(); + return stepNumber; } -#endif //motor_h \ No newline at end of file +#endif //motor_h diff --git a/shutter.h b/shutter.h index 471e612..fbb4a96 100644 --- a/shutter.h +++ b/shutter.h @@ -15,7 +15,7 @@ class Shutter Shutter(int pin_shutter, bool invert = false); void af(unsigned long af_time_ms = 100); void shutter(unsigned long shutter_time_ms = 100); - void afShutter(unsigned long af_time_ms = 100, shutter_time_ms = 100); + void afShutter(unsigned long af_time_ms = 100, unsigned long shutter_time_ms = 100); };