Skip to content

Commit

Permalink
Make power button disable stepper drive and turn off control panel.
Browse files Browse the repository at this point in the history
  • Loading branch information
clough42 committed Oct 10, 2020
1 parent 1f81220 commit 7711032
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 53 deletions.
7 changes: 7 additions & 0 deletions els-f280049c/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Core :: Core( Encoder *encoder, StepperDrive *stepperDrive )
this->previousSpindlePosition = 0;
this->previousFeedDirection = 0;
this->previousFeed = NULL;

this->powerOn = true; // default to power on
}

void Core :: setReverse(bool reverse)
Expand All @@ -54,6 +56,11 @@ void Core :: setReverse(bool reverse)
}
}

void Core :: setPowerOn(bool powerOn)
{
this->powerOn = powerOn;
this->stepperDrive->setEnabled(powerOn);
}



Expand Down
10 changes: 10 additions & 0 deletions els-f280049c/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class Core

int32 feedRatio(Uint32 count);

bool powerOn;

public:
Core( Encoder *encoder, StepperDrive *stepperDrive );

Expand All @@ -62,6 +64,9 @@ class Core
Uint16 getRPM(void);
bool isAlarm();

bool isPowerOn();
void setPowerOn(bool);

void ISR( void );
};

Expand All @@ -84,6 +89,11 @@ inline bool Core :: isAlarm()
return this->stepperDrive->isAlarm();
}

inline bool Core :: isPowerOn()
{
return this->powerOn;
}

inline int32 Core :: feedRatio(Uint32 count)
{
#ifdef USE_FLOATING_POINT
Expand Down
13 changes: 13 additions & 0 deletions els-f280049c/StepperDrive.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class StepperDrive
void incrementCurrentPosition(int32 increment);
void setCurrentPosition(int32 position);

void setEnabled(bool);

bool isAlarm();

void ISR(void);
Expand All @@ -119,6 +121,17 @@ inline void StepperDrive :: setCurrentPosition(int32 position)
this->currentPosition = position;
}

inline void StepperDrive :: setEnabled(bool enabled)
{
if( enabled ) {
GPIO_SET_ENABLE;
}
else
{
GPIO_CLEAR_ENABLE;
}
}

inline bool StepperDrive :: isAlarm()
{
#ifdef USE_ALARM_PIN
Expand Down
112 changes: 60 additions & 52 deletions els-f280049c/UserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ const MESSAGE SETTINGS_MESSAGE_1 =
.next = &SETTINGS_MESSAGE_2
};

const Uint16 VALUE_BLANK[4] = { BLANK, BLANK, BLANK, BLANK };

UserInterface :: UserInterface(ControlPanel *controlPanel, Core *core, FeedTableFactory *feedTableFactory)
{
this->controlPanel = controlPanel;
Expand All @@ -66,6 +68,8 @@ UserInterface :: UserInterface(ControlPanel *controlPanel, Core *core, FeedTable

this->keys.all = 0xff;

loadFeedTable();

setMessage(&STARTUP_MESSAGE_1);
}

Expand All @@ -75,15 +79,23 @@ const FEED_THREAD *UserInterface::loadFeedTable()
return this->feedTable->current();
}

LED_REG UserInterface::calculateLEDs(const FEED_THREAD *selectedFeed)
LED_REG UserInterface::calculateLEDs()
{
// get the LEDs for this feed
LED_REG leds = selectedFeed->leds;
LED_REG leds = feedTable->current()->leds;

// and add a few of our own
leds.bit.POWER = 1;
leds.bit.REVERSE = this->reverse;
leds.bit.FORWARD = ! this->reverse;
if( this->core->isPowerOn() )
{
// and add a few of our own
leds.bit.POWER = 1;
leds.bit.REVERSE = this->reverse;
leds.bit.FORWARD = ! this->reverse;
}
else
{
// power is off
leds.all = 0;
}

return leds;
}
Expand Down Expand Up @@ -114,45 +126,44 @@ void UserInterface :: overrideMessage( void )

void UserInterface :: loop( void )
{
const FEED_THREAD *newFeed = NULL;

// read the RPM up front so we can use it to make decisions
Uint16 currentRpm = core->getRPM();

// display an override message, if there is one
overrideMessage();

// just in case, initialize the first time through
if( feedTable == NULL ) {
newFeed = loadFeedTable();
}

// read keypresses from the control panel
keys = controlPanel->getKeys();

// respond to keypresses
if( currentRpm == 0 )
{
// these keys should only be sensitive when the machine is stopped
if( keys.bit.IN_MM )
{
this->metric = ! this->metric;
newFeed = loadFeedTable();
}
if( keys.bit.FEED_THREAD )
{
this->thread = ! this->thread;
newFeed = loadFeedTable();
if( keys.bit.POWER ) {
this->core->setPowerOn(!this->core->isPowerOn());
}
if( keys.bit.FWD_REV )
{
this->reverse = ! this->reverse;
// feed table hasn't changed, but we need to trigger an update
newFeed = loadFeedTable();
}
if( keys.bit.SET )
{
setMessage(&SETTINGS_MESSAGE_1);

// these should only work when the power is on
if( this->core->isPowerOn() ) {
if( keys.bit.IN_MM )
{
this->metric = ! this->metric;
core->setFeed(loadFeedTable());
}
if( keys.bit.FEED_THREAD )
{
this->thread = ! this->thread;
core->setFeed(loadFeedTable());
}
if( keys.bit.FWD_REV )
{
this->reverse = ! this->reverse;
core->setReverse(this->reverse);
}
if( keys.bit.SET )
{
setMessage(&SETTINGS_MESSAGE_1);
}
}
}

Expand All @@ -161,35 +172,32 @@ void UserInterface :: loop( void )
{
#endif // IGNORE_ALL_KEYS_WHEN_RUNNING

// these keys can be operated when the machine is running
if( keys.bit.UP )
{
newFeed = feedTable->next();
}
if( keys.bit.DOWN )
{
newFeed = feedTable->previous();
// these should only work when the power is on
if( this->core->isPowerOn() ) {
// these keys can be operated when the machine is running
if( keys.bit.UP )
{
core->setFeed(feedTable->next());
}
if( keys.bit.DOWN )
{
core->setFeed(feedTable->previous());
}
}

#ifdef IGNORE_ALL_KEYS_WHEN_RUNNING
}
#endif // IGNORE_ALL_KEYS_WHEN_RUNNING

// if we have changed the feed
if( newFeed != NULL ) {
// update the display
LED_REG leds = this->calculateLEDs(newFeed);
controlPanel->setLEDs(leds);
controlPanel->setValue(newFeed->display);
// update the control panel
controlPanel->setLEDs(calculateLEDs());
controlPanel->setValue(feedTable->current()->display);
controlPanel->setRPM(currentRpm);

// update the core
core->setFeed(newFeed);
core->setReverse(this->reverse);
if( ! core->isPowerOn() )
{
controlPanel->setValue(VALUE_BLANK);
}

// update the RPM display
controlPanel->setRPM(currentRpm);

// write data out to the display
controlPanel->refresh();
}
2 changes: 1 addition & 1 deletion els-f280049c/UserInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class UserInterface
Uint16 messageTime;

const FEED_THREAD *loadFeedTable();
LED_REG calculateLEDs(const FEED_THREAD *selectedFeed);
LED_REG calculateLEDs();
void setMessage(const MESSAGE *message);
void overrideMessage( void );

Expand Down

4 comments on commit 7711032

@WOODPRO
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

James, this update worked sorta. I entered everything and when first powered up the stepper doesn't function, however after I cycle thru the feed/thread every thing works even after the new power on/off feature.
I'm going to check every entry now.

Tim Abblett

@clough42
Copy link
Owner Author

@clough42 clough42 commented on 7711032 Oct 16, 2020 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WOODPRO
Copy link

@WOODPRO WOODPRO commented on 7711032 Oct 16, 2020 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clough42
Copy link
Owner Author

@clough42 clough42 commented on 7711032 Oct 16, 2020 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.