jeffm852 / grbl-jm

An open source, embedded, high performance g-code-parser and CNC milling controller written in optimized C that will run on a straight Arduino
https://github.com/grbl/grbl/wiki
Other
0 stars 0 forks source link

add status lights #1

Open jeffm852 opened 8 years ago

jeffm852 commented 8 years ago

see https://github.com/grbl/grbl/issues/628

RabbitMountain commented 3 years ago

+1

RabbitMountain commented 3 years ago

@jeffm852 , Would you like to collaborate on this?

If yes, please see my comments on issue grbl#628 (https://github.com/grbl/grbl/issues/628).

I have partially working status led code, but I am having trouble getting it to fully work. Any help would be appreciated.

RabbitMountain commented 3 years ago

After much tinkering with the code i seem to have solved my own issue. In the end I had to get rid of the macro that was programmed in the example code. It also didn't hurt to learn a tiny bit about bit setting in C / C# programming. I'm still not a great programmer by any means, but I'm slightly better now. In the end the KISS method helped to simplify the code to where I both understood what the code was doing within the state machine AND worked as expected.

So... go me! Yay! :)

here is the working simplified code:

for cpu_map.h file:

// Define flood and mist coolant enable output pins.

define COOLANT_FLOOD_DDR DDRC

define COOLANT_FLOOD_PORT PORTC

define COOLANT_FLOOD_BIT 3 // Uno Analog Pin 3

//#define COOLANT_MIST_DDR DDRC //#define COOLANT_MIST_PORT PORTC //#define COOLANT_MIST_BIT 4 // Uno Analog Pin 4

////////////////// // Define ALARM LED OUTPUT

define SIGNAL_LIGHT_DDR DDRC

define SIGNAL_LIGHT_PORT PORTC

define SIGNAL_LIGHT_BIT 4 // Uno Analog Pin 4

define signal_light_init signal_light_off

define signal_light_on (SIGNAL_LIGHT_DDR |= SIGNAL_LIGHT_PORT |= (1<<SIGNAL_LIGHT_BIT) )

define signal_light_off (SIGNAL_LIGHT_DDR |= SIGNAL_LIGHT_PORT &= ~(1<<SIGNAL_LIGHT_BIT) )

//////////////////

and for protocol.c file:

// Executes run-time commands, when required. This function primarily operates as Grbl's state // machine and controls the various real-time features Grbl has to offer. // NOTE: Do not alter this unless you know exactly what you are doing! void protocol_exec_rt_system() {

uint8_t rt_exec; // Temp variable to avoid calling volatile multiple times. rt_exec = sys_rt_exec_alarm; // Copy volatile sys_rt_exec_alarm.

/////////////////////// // Define ALARM LED OUTPUT signal_light_init; //init LED in off state if (sys.state==STATE_ALARM) {signal_light_on;} else if (sys.state!=STATE_ALARM) {signal_light_off;} // else {signal_light_off;} ///////////////////////