direction commands updated to Up down RPM value
Dependencies: MAX7219pot MCP23S17 mbed
Fork of POT_V_1_0 by
Diff: main.cpp
- Revision:
- 1:e116808d8b00
- Parent:
- 0:ba33a62aea4e
- Child:
- 3:ae45e29f5d4f
--- a/main.cpp Thu Sep 28 05:10:42 2017 +0000 +++ b/main.cpp Fri Jan 05 04:35:22 2018 +0000 @@ -69,81 +69,22 @@ bool CMD_key; bool switch_CH, pot_MCR_err, pot_ER_err, ACH_SW_over; -char *key;// = new char[RX_BUFFER_SIZE]; //memory allocation for Receive buffer -char* valid; +char *key; // = new char[RX_BUFFER_SIZE]; //memory allocation for Receive buffer +char valid; int device_addr = -1; -/************************************************************************************** - EOT LED CLASS - **************************************************************************************/ -class LED{ -public: - LED(PinName led); //constructor declaration - void set_Brightness(float bright); - void ON(); - void OFF(); - void FLASHH(); -private: - Ticker _flash; - bool on_off; - bool Fllash; - float brightness; - PwmOut _LED; - void __flash(); -}; -LED::LED(PinName led): _LED(led) //constructor defination -{ - brightness = 0.000; - on_off = false; - Fllash = false; - _LED = brightness; -} - -void LED::set_Brightness(float bright) -{ - brightness = bright; - if(!Fllash) - _LED = bright; - else - __nop(); -} +char rx_buf[RX_BUFFER_SIZE+1]; +char tx_buf[TX_BUFFER_SIZE+1]; +char RTC_buffer[5] = {1,2,3,4,0}; -void LED::ON() -{ - _LED = brightness; - Fllash = false; - _flash.detach(); -} - -void LED::OFF() -{ - _LED = 0; - Fllash = false; - _flash.detach(); -} +DigitalOut LED_CMD(_CMD_ACK); //ack command in slave devices only +DigitalOut LED_CTRL[2] = {_REQ,_ACK}; //control transfer +DigitalOut LED_DIR[2] = {_AHEAD,_ASTERN}; //dir command +DigitalOut LED_ACH[8] = {_WH,_BRDG,_MCR,_ER,_WP,_WS,_OPS,_ASP}; //active channels -void LED::FLASHH() -{ - Fllash = true; - _flash.attach(callback(this, &LED::__flash),0.5); -} +//DigitalOut myled(PB_13); //for internal test LED1 -void LED::__flash() -{ - if(on_off) - _LED = brightness; - else - _LED = 0; - - on_off = !on_off; -} -/************************************************************************************** - EOT LED CLASS END - **************************************************************************************/ -//array of objects/instances of class LED & PwmOut// -LED LED_DIR[2] = {_AHEAD,_ASTERN}; // direction control -LED LED_CTRL[2] = {_REQ,_ACK}; //transfer control -LED LED_ACH[8] = {_WH,_BRDG,_MCR,_ER,_WP,_WS,_OPS,_ASP}; //active channels +PwmOut mypwm(_PWM); uint8_t rpm_data[4] = {0,0,0,0}; //digits 0-3 uint8_t last_entry[4] = {0,0,0,0}; //digits 0-3 @@ -168,11 +109,16 @@ pot_Listner_ASP = 8 }; -enum pin_STATUS -{ - _OFF =0, - _ON =1 -}; +enum LED_STATUS +{ + OFF = 0, + ON, + _FLASH = 2 +}; +LED_STATUS led_cmd_ack[1]; //only in slave devices +LED_STATUS led_ctrl[2]; +LED_STATUS led_dir[2]; +LED_STATUS led_ach[8]; enum KEY { @@ -247,18 +193,155 @@ { if(RTC_disp) { + RTC_disp = false; for(uint8_t i = 0; i <= 3; i++) //to write all the four digits { - max7219.write_digit(2, i+1, *(digits+i)); //device 2, digit 1-4 ,data 0x01 + if(i == 1) + RTC_buffer[i] = RTC_buffer[i]|0b10000000; // to inc + else + __nop(); + max7219.write_digit(1, i+1, *(digits+i)); //device 2, digit 1-4 ,data 0x01 } } else { for(uint8_t i = 0; i <= 3; i++) //to write all the four digits { - max7219.write_digit(1, i+1, *(digits+i)); //device 1, digit 1-4 ,data pointer + max7219.write_digit(2, i+1, *(digits+i)); //device 1, digit 1-4 ,data pointer + } + } +} + +/************************************************************************************** +EOT RTC read FUNCTION + **************************************************************************************/ +void read_RTC() +{ + time_t seconds = time(NULL); + strftime(RTC_buffer, 5, "%H%M\n", localtime(&seconds)); + wait_ms(5); + display_update(true, RTC_buffer); + wait_ms(1); +} + +/************************************************************************************** +EOT CHECK LED STATUS FUNCTION + **************************************************************************************/ +void update_led() +{ + if(++ticker_count == 25) //25x20 = 500ms + { + ticker_count = 0; + toggle = !toggle; //normal cmd flash + } + else + __nop(); + + if(++ticker_count_fast == 10) //20x10 =200 + { + ticker_count_fast = 0; + toggle_fast = !toggle_fast; //error flashing + } + else + __nop(); + + if(test) + { + LED_CMD = ON; + + for(uint8_t i=0;i<=1;i++) //control + { + LED_CTRL[i] = ON; + } + for(uint8_t i=0;i<=1;i++) //control + { + LED_DIR[i] = ON; /////////////////working here + } + for(uint8_t i=0;i<=7;i++) //active channel + { + LED_ACH[i] = ON; //duty cycle 10% } } + else + { + for(uint8_t i=0;i<=10;i++) //cmd + { + if(led_cmd[i] == ON) + LED_CMD[i] = ON; + else + __nop(); + + if(led_cmd[i] == OFF) + LED_CMD[i] = OFF; + else + __nop(); + + if(led_cmd[i] == _FLASH) + { + if(toggle) + LED_CMD[i]= ON; + else + LED_CMD[i] = OFF; + } + else + __nop(); + } + for(uint8_t i=0;i<=1;i++) //control + { + if(led_ctrl[i] == ON) + LED_CTRL[i] = ON; + else + __nop(); + + if(led_ctrl[i] == OFF) + LED_CTRL[i] = OFF; //duty cycle 10% + else + __nop(); + + if(led_ctrl[i] == _FLASH) + { + if(toggle) + LED_CTRL[i]= ON; + else + LED_CTRL[i] = OFF; + } + else + __nop(); + } + for(uint8_t i=0;i<=7;i++) //active channel + { + if(led_ach[i] == ON) + LED_ACH[i] = ON; //duty cycle 10% + else + __nop(); + + if(led_ach[i] == OFF) + LED_ACH[i] = OFF; //duty cycle 10 + else + __nop(); + + if(led_ach[i] == _FLASH) + { + if(toggle_fast) + LED_ACH[i]= ON; + else + LED_ACH[i] = OFF; + } + else + __nop(); + } + } + if(display_flash) //if command executed or command received + { + if(toggle) + max7219.enable_device(2); //enable device 1 or normal mode + else + max7219.disable_device(2); //shutdown mode + } + else if(!device_ERR) //specific device is not in error device + max7219.enable_device(2); //enable device 1 or normal mode; + else + __nop(); } /************************************************************************************** @@ -795,7 +878,7 @@ switch(key_status) { case 0xfe: //0xfe GPA0 - num_KEY = ZER0; + num_KEY = ZERO; break; case 0xfd: //0xfd GPA1 num_KEY = ONE;