Fork of Smoothie to port to mbed non-LPC targets.
Fork of Smoothie by
SlowTicker.h
00001 /* 00002 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl). 00003 Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 00004 Smoothie 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 General Public License for more details. 00005 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>. 00006 */ 00007 00008 00009 00010 #ifndef SLOWTICKER_H 00011 #define SLOWTICKER_H 00012 00013 using namespace std; 00014 #include <vector> 00015 #include "libs/nuts_bolts.h" 00016 #include "libs/Module.h" 00017 #include "libs/Kernel.h" 00018 #include "libs/Hook.h" 00019 00020 #include "libs/Pin.h" 00021 00022 #include <math.h> 00023 00024 class SlowTicker : public Module{ 00025 public: 00026 SlowTicker(); 00027 00028 void on_module_loaded(void); 00029 void on_idle(void*); 00030 void on_gcode_received(void*); 00031 void on_gcode_execute(void*); 00032 00033 void set_frequency( int frequency ); 00034 void tick(); 00035 // For some reason this can't go in the .cpp, see : http://mbed.org/forum/mbed/topic/2774/?page=1#comment-14221 00036 template<typename T> Hook* attach( uint32_t frequency, T *optr, uint32_t ( T::*fptr )( uint32_t ) ){ 00037 Hook* hook = new Hook(); 00038 hook->interval = int(floor((SystemCoreClock/4)/frequency)); 00039 hook->attach(optr, fptr); 00040 hook->countdown = hook->interval; 00041 if( frequency > this->max_frequency ){ 00042 this->max_frequency = frequency; 00043 this->set_frequency(frequency); 00044 } 00045 this->hooks.push_back(hook); 00046 return hook; 00047 } 00048 00049 bool flag_1s(); 00050 00051 vector<Hook*> hooks; 00052 uint32_t max_frequency; 00053 uint32_t interval; 00054 00055 uint32_t g4_ticks; 00056 bool g4_pause; 00057 00058 Pin ispbtn; 00059 protected: 00060 int flag_1s_count; 00061 volatile int flag_1s_flag; 00062 Ticker ticker; 00063 }; 00064 00065 00066 00067 00068 00069 #endif
Generated on Tue Jul 12 2022 20:09:02 by 1.7.2