|
@@ -12,14 +12,14 @@
|
|
|
#include <MCP79410_Timer.h> //Scullcom Hobby Electronics library http://www.scullcom.com/MCP79410Timer-master.zip
|
|
|
#include <EEPROM.h> //include EEPROM library used for storing setup data
|
|
|
#include <config.h>
|
|
|
+#include <input.h>
|
|
|
#include <screen.h>
|
|
|
#include <SoftwareSerial.h>
|
|
|
|
|
|
SoftwareSerial nexSerial (rxPin,txPin);
|
|
|
|
|
|
-static uint8_t __buffer[10];
|
|
|
-uint16_t i1;
|
|
|
-uint8_t c1;
|
|
|
+
|
|
|
+
|
|
|
void setupLimits (void);
|
|
|
void transientSwitch(float current_setting, boolean toggle_status);
|
|
|
void transientListSetup();
|
|
@@ -55,9 +55,9 @@ void wait_for_key(bool wait =true );
|
|
|
|
|
|
|
|
|
|
|
|
-char customKey;
|
|
|
+uint8_t customKey;
|
|
|
|
|
|
-char decimalPoint; //used to test for more than one press of * key (decimal point)
|
|
|
+bool decimalPoint=false; //used to test for more than one press of * key (decimal point)
|
|
|
|
|
|
|
|
|
|
|
@@ -128,11 +128,6 @@ volatile float encoderPosition = 0; //
|
|
|
volatile unsigned long factor= 0; //number of steps to jump
|
|
|
volatile unsigned long encoderMax = 999000; //sets maximum Rotary Encoder value allowed CAN BE CHANGED AS REQUIRED (was 50000)
|
|
|
|
|
|
-float LiPoCutOffVoltage = 3.0; //set cutoff voltage for LiPo battery
|
|
|
-float LiFeCutOffVoltage = 2.8; //set cutoff voltage for LiFe battery
|
|
|
-float NiCdCutOffVoltage = 1.0; //set cutoff voltage for NiCd battery
|
|
|
-float ZiZnCutOffVoltage = 1.0; //set cutoff voltage for ZiZn battery
|
|
|
-float PbAcCutOffVoltage = 1.75; //set cutoff voltage for PbAc battery
|
|
|
String BatteryType =" ";
|
|
|
|
|
|
byte exitMode = 0; //used to exit battery selection menu and return to CC Mode
|
|
@@ -163,14 +158,28 @@ char line0_old[line_len]= {0};
|
|
|
char line1_old[line_len]= {0};
|
|
|
char line2_old[line_len]= {0};
|
|
|
char line3_old[line_len]= {0};
|
|
|
+char line_current[7]={0};
|
|
|
+char line_volt[7]={0};
|
|
|
+char line_power[7]={0};
|
|
|
+char line_current_old[7]={0};
|
|
|
+char line_volt_old[7]={0};
|
|
|
+char line_power_old[7]={0};
|
|
|
char temperature_val[5]={0x00};
|
|
|
char temperature_buf[5]={0x00};
|
|
|
+char line_input[10]={0};
|
|
|
bool old_load=true;
|
|
|
|
|
|
bool usb_enable=false;
|
|
|
bool trig_key = false;
|
|
|
void setmode(void);
|
|
|
void color_load (bool load);
|
|
|
+
|
|
|
+// Variables will change:
|
|
|
+int OnOfflastSteadyState = LOW; // the previous steady state from the input pin
|
|
|
+int OnOfflastFlickerableState = LOW; // the previous flickerable state from the input pin
|
|
|
+int OnOffcurrentState; // the current reading from the input pin
|
|
|
+unsigned long OnOfflastDebounceTime = 0; // the last time the output pin was toggled
|
|
|
+
|
|
|
bool setVoltage(uint16_t output, bool writeEEPROM) {
|
|
|
|
|
|
uint8_t packet[3];
|
|
@@ -218,103 +227,7 @@ void toggle_usb(void){
|
|
|
usb_enable=!usb_enable;
|
|
|
}
|
|
|
|
|
|
-void serialEvent() {
|
|
|
- while (nexSerial.available() > 0 ){
|
|
|
-
|
|
|
- c1 = nexSerial.read();
|
|
|
- Serial.println(c1,HEX);
|
|
|
- if (0x65 == c1 ||__buffer[0] == 0x65)
|
|
|
- {
|
|
|
- if (0x65 == c1){
|
|
|
- __buffer[0] = c1;
|
|
|
- i1++;
|
|
|
- }else{
|
|
|
- __buffer[i1]=c1;
|
|
|
- i1++;
|
|
|
- if (i1>=7)
|
|
|
- {
|
|
|
- __buffer[i1] = 0x00;
|
|
|
- if (0xFF == __buffer[4] && 0xFF == __buffer[5] && 0xFF == __buffer[6])
|
|
|
- {
|
|
|
- if (__buffer[1]==0){
|
|
|
- switch(__buffer[2]){
|
|
|
- case 11:
|
|
|
- customKey='0';
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- customKey='1';
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- customKey='2';
|
|
|
- break;
|
|
|
- case 4:
|
|
|
- customKey='3';
|
|
|
- break;
|
|
|
- case 5:
|
|
|
- customKey='4';
|
|
|
- break;
|
|
|
- case 6:
|
|
|
- customKey='5';
|
|
|
- break;
|
|
|
- case 7:
|
|
|
- customKey='6';
|
|
|
- break;
|
|
|
- case 8:
|
|
|
- customKey='7';
|
|
|
- break;
|
|
|
- case 9:
|
|
|
- customKey='8';
|
|
|
- break;
|
|
|
- case 10:
|
|
|
- customKey='9';
|
|
|
- break;
|
|
|
- case 20:
|
|
|
- customKey='F';
|
|
|
- break;
|
|
|
- case 13:
|
|
|
- customKey='>';
|
|
|
- break;
|
|
|
- case 12:
|
|
|
- customKey='<';
|
|
|
- break;
|
|
|
- case 21:
|
|
|
- customKey='E';
|
|
|
- break;
|
|
|
- case 19:
|
|
|
- customKey='D';
|
|
|
- break;
|
|
|
- case 16:
|
|
|
- customKey='A';
|
|
|
- break;
|
|
|
- case 17:
|
|
|
- customKey='B';
|
|
|
- break;
|
|
|
- case 18:
|
|
|
- customKey='#';
|
|
|
- break;
|
|
|
- case 15:
|
|
|
- customKey='*';
|
|
|
- break;
|
|
|
- case 14:
|
|
|
- customKey='C';
|
|
|
- break;
|
|
|
- case 29:
|
|
|
- toggle_usb();
|
|
|
- break;
|
|
|
- case button_trig:
|
|
|
- trig_key = true;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- memset(__buffer,0x00,8);
|
|
|
- i1=0;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+
|
|
|
|
|
|
//---------------------------------Initial Set up---------------------------------------
|
|
|
void setup() {
|
|
@@ -336,7 +249,7 @@ void setup() {
|
|
|
}
|
|
|
nexSerial.read(); // Read and delete bytes
|
|
|
}
|
|
|
-
|
|
|
+ memset(line_input,' ',10);
|
|
|
CurrentCutOff = EEPROM.read(0x00);
|
|
|
PowerCutOff = EEPROM.read(0x20);
|
|
|
tempCutOff = EEPROM.read(0x40);
|
|
@@ -388,8 +301,12 @@ nDevices = 0;
|
|
|
analogReference(INTERNAL); //use Arduino internal reference for tempurature monitoring
|
|
|
attachInterrupt(digitalPinToInterrupt(pinA), isr, LOW);
|
|
|
|
|
|
- screen_clear('\0');
|
|
|
+ screen_clear(0x00);
|
|
|
writeNum2("t0.xcen", 1); //print SCULLCOM to display with 5 leading spaces (you can change to your own)
|
|
|
+ writeNum2("t0.xcen",(int) 1);
|
|
|
+ writeNum2("t1.xcen",(int) 1);
|
|
|
+ writeNum2("t2.xcen",(int) 1);
|
|
|
+ writeNum2("t3.xcen",(int) 1);
|
|
|
memcpy(line0,(char*)"SCULLCOM",9);
|
|
|
print_chars2(0,9);
|
|
|
|
|
@@ -399,10 +316,20 @@ nDevices = 0;
|
|
|
memcpy(line2,(char*)"DC Electronic Load",19);
|
|
|
print_chars2(2,19);
|
|
|
|
|
|
- memcpy(line3,(char*)"Ver. 35 (5x4 Keypad)",21);
|
|
|
+ memcpy(line3,(char*)"Ver. ",5);
|
|
|
+ memcpy(line3+5,(char*)DC_LOAD_VER,2);
|
|
|
+ memcpy(line3+7,(char*)" (Nextion)",11);
|
|
|
print_chars2(3,21);
|
|
|
+ memcpy(line_current," ",1);
|
|
|
+ memcpy(line_volt," ",1);
|
|
|
+ memcpy(line_power," ",1);
|
|
|
+ print_reading();
|
|
|
|
|
|
- delay(2000); //3000 mSec delay for intro display
|
|
|
+ delay(2000);
|
|
|
+ writeNum2("t0.xcen",(int) 1);
|
|
|
+ writeNum2("t1.xcen",(int) 0);
|
|
|
+ writeNum2("t2.xcen",(int) 0);
|
|
|
+ writeNum2("t3.xcen",(int) 0); //3000 mSec delay for intro display
|
|
|
screen_clear(' ');
|
|
|
setupLimits();
|
|
|
delay(3000);
|
|
@@ -415,7 +342,7 @@ nDevices = 0;
|
|
|
color_load(0);
|
|
|
Current(); //sets initial mode to be CC (Constant Current) at Power Up
|
|
|
//EEPROM.write(0x00, 0xff);
|
|
|
- customKey='\0';
|
|
|
+ customKey=NO_KEY;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -427,14 +354,21 @@ void loop() {
|
|
|
if(CurrentCutOff > 5){ //Test and go to user set limits if required
|
|
|
userSetUp();
|
|
|
writeNum2("t0.xcen", 0);
|
|
|
- customKey='\0';
|
|
|
+ customKey=NO_KEY;
|
|
|
}else{
|
|
|
|
|
|
readKeypadInput(); //read Keypad entry
|
|
|
-
|
|
|
- if (digitalRead(LoadOnOff) == LOW) {
|
|
|
- LoadSwitch(); //Load on/off
|
|
|
+ OnOffcurrentState = digitalRead(LoadOnOff);
|
|
|
+ if (OnOffcurrentState != OnOfflastFlickerableState) {
|
|
|
+ OnOfflastDebounceTime = millis();
|
|
|
+ OnOfflastFlickerableState = OnOffcurrentState;
|
|
|
}
|
|
|
+ if ((millis() - OnOfflastDebounceTime) > DEBOUNCE_DELAY && OnOffcurrentState == LOW) {
|
|
|
+ LoadSwitch(); //Load On Off
|
|
|
+ OnOfflastSteadyState = OnOffcurrentState;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
transient(); //test for Transient Mode
|
|
|
setmode() ;
|
|
@@ -475,37 +409,37 @@ void readKeypadInput (void) {
|
|
|
// Serial.println(customKey); //only used for testing keypad (uncomment if required for testing keypad)
|
|
|
// } //only used for testing keypad (uncomment if required for testing keypad)
|
|
|
|
|
|
- if(customKey == 'E'){ //check for Load on/off
|
|
|
+ if(customKey == DIGIT_ONOFF){ //check for Load on/off
|
|
|
LoadSwitch();
|
|
|
- customKey='\0';
|
|
|
+ customKey=NO_KEY;
|
|
|
}
|
|
|
|
|
|
- if(customKey == 'D'){ //check if Set-Up Mode Selected
|
|
|
+ if(customKey == DIGIT_SETUP){ //check if Set-Up Mode Selected
|
|
|
delay(200);
|
|
|
- toggle = false;
|
|
|
- customKey='\0'; //switch Load OFF
|
|
|
+ toggle = true;
|
|
|
+ customKey=NO_KEY; //switch Load OFF
|
|
|
LoadSwitch();
|
|
|
userSetUp();
|
|
|
encoderPosition = 0; //reset encoder reading to zero
|
|
|
index = 0;
|
|
|
z = 1; //sets column position for LCD displayed character
|
|
|
- decimalPoint = (' '); //clear decimal point text character reset
|
|
|
+ decimalPoint = false; //clear decimal point text character reset
|
|
|
|
|
|
}
|
|
|
|
|
|
- if(customKey == 'C'){ //check if Transient Mode Selected
|
|
|
+ if(customKey == DIGIT_TRANS){ //check if Transient Mode Selected
|
|
|
toggle = false;
|
|
|
- customKey='\0'; //switch Load OFF
|
|
|
+ customKey=NO_KEY; //switch Load OFF
|
|
|
transientType();
|
|
|
|
|
|
encoderPosition = 0; //reset encoder reading to zero
|
|
|
index = 0;
|
|
|
z = 1; //sets column position for LCD displayed character
|
|
|
- decimalPoint = (' '); //clear decimal point text character reset
|
|
|
+ decimalPoint = false; //clear decimal point text character reset
|
|
|
|
|
|
}
|
|
|
|
|
|
- if(customKey == 'A'){ //check if Constant Current button pressed
|
|
|
+ if(customKey == DIGIT_CURRENT){ //check if Constant Current button pressed
|
|
|
toggle = false; //switch Load OFF
|
|
|
color_load(0);
|
|
|
print_chars2(0,20);
|
|
@@ -513,11 +447,11 @@ void readKeypadInput (void) {
|
|
|
encoderPosition = 0; //reset encoder reading to zero
|
|
|
index = 0;
|
|
|
z = 1; //sets column position for LCD displayed character
|
|
|
- decimalPoint = (' '); //clear decimal point test character reset
|
|
|
- customKey='\0';
|
|
|
+ decimalPoint = false; //clear decimal point test character reset
|
|
|
+ customKey=NO_KEY;
|
|
|
}
|
|
|
|
|
|
- if(customKey == 'B'){ //check if Constant Power button pressed
|
|
|
+ if(customKey == DIGIT_POWER){ //check if Constant Power button pressed
|
|
|
toggle = false; //switch Load OFF
|
|
|
color_load(0);
|
|
|
print_chars2(0,20);
|
|
@@ -525,11 +459,11 @@ void readKeypadInput (void) {
|
|
|
encoderPosition = 0; //reset encoder reading to zero
|
|
|
index = 0;
|
|
|
z = 1; //sets column position for LCD displayed character
|
|
|
- decimalPoint = (' '); //clear decimal point test character reset
|
|
|
- customKey='\0';
|
|
|
+ decimalPoint = false; //clear decimal point test character reset
|
|
|
+ customKey=NO_KEY;
|
|
|
}
|
|
|
|
|
|
- if(customKey == '#'){ //check if Constant Resistance button pressed
|
|
|
+ if(customKey == DIGIT_RESISTANS){ //check if Constant Resistance button pressed
|
|
|
toggle = false; //switch Load OFF
|
|
|
color_load(0);
|
|
|
print_chars2(0,20);
|
|
@@ -537,23 +471,23 @@ void readKeypadInput (void) {
|
|
|
encoderPosition = 0; //reset encoder reading to zero
|
|
|
index = 0;
|
|
|
z = 1; //sets column position for LCD displayed character
|
|
|
- decimalPoint = (' '); //clear decimal point test character reset
|
|
|
- customKey='\0';
|
|
|
+ decimalPoint = false; //clear decimal point test character reset
|
|
|
+ customKey=NO_KEY;
|
|
|
}
|
|
|
|
|
|
- if(customKey == '*'){ //check if Battery Capacity button pressed
|
|
|
+ if(customKey == DIGIT_BATTERY){ //check if Battery Capacity button pressed
|
|
|
setVoltage(0,false); //Ensures Load is OFF - sets DAC output voltage to 0
|
|
|
toggle = false; //switch Load OFF
|
|
|
batteryType(); //select battery type
|
|
|
index = 0;
|
|
|
z = 1; //sets column position for LCD displayed character
|
|
|
- decimalPoint = (' '); //clear decimal point test character reset
|
|
|
+ decimalPoint = false; //clear decimal point test character reset
|
|
|
if (exitMode == 1){ //if NO battery type selected revert to CC Mode
|
|
|
color_load(0);
|
|
|
print_chars2(0,20);
|
|
|
Current(); //if selected go to Constant Current Selected routine
|
|
|
encoderPosition = 0; //reset encoder reading to zero
|
|
|
- customKey = 'A';
|
|
|
+ customKey = DIGIT_CURRENT;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -569,18 +503,18 @@ void readKeypadInput (void) {
|
|
|
}
|
|
|
|
|
|
if (Mode != MODE_TC && Mode != MODE_TL && Mode != MODE_TP && Mode != MODE_TT){
|
|
|
-
|
|
|
- if(customKey >= '0' && customKey <= '9'){ //check for keypad number input
|
|
|
- numbers[index++] = customKey;
|
|
|
- numbers[index] = '\0';
|
|
|
- line3[z]=customKey;
|
|
|
- print_chars2(3,20);
|
|
|
- z = z+1;
|
|
|
- customKey ='\0';
|
|
|
- }
|
|
|
|
|
|
- if(customKey == '>'){ //check if decimal button key pressed
|
|
|
- if (decimalPoint != '>'){ //test if decimal point entered twice - if so skip
|
|
|
+ if(customKey >= DIGIT_1 && customKey <= DIGIT_0){ //check for keypad number input
|
|
|
+ numbers[index++] = (customKey-1 == 10 ? '0' : '0' +customKey-1 ); //Convert into into to ascii and fix 0
|
|
|
+ numbers[index] = 0x00;
|
|
|
+ line_input[z]=(customKey-1 == 10 ? '0' : '0' +customKey-1 );
|
|
|
+ print_input();
|
|
|
+ z = z+1;
|
|
|
+ customKey=NO_KEY;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(customKey == DIGIT_DECIMAL){ //check if decimal button key pressed
|
|
|
+ if (!decimalPoint){ //test if decimal point entered twice - if so skip
|
|
|
uint8_t index_old = index;
|
|
|
if (index==0){
|
|
|
numbers[index++] = '0';
|
|
@@ -588,35 +522,37 @@ void readKeypadInput (void) {
|
|
|
numbers[index++] = '.';
|
|
|
numbers[index] = 0x00;
|
|
|
if (index_old==0){
|
|
|
- line3[z++]='0';
|
|
|
+ line_input[z++]='0';
|
|
|
}
|
|
|
- line3[z]='.';
|
|
|
- print_chars2(3,20);
|
|
|
+ line_input[z]='.';
|
|
|
+ print_input();
|
|
|
z = z+1;
|
|
|
- decimalPoint = '>'; //used to indicate decimal point has been input
|
|
|
+ decimalPoint = true; //used to indicate decimal point has been input
|
|
|
}
|
|
|
- customKey ='\0';
|
|
|
+ customKey=NO_KEY;
|
|
|
}
|
|
|
|
|
|
- if(customKey == '<'){ //clear input entry
|
|
|
+ if(customKey == DIGIT_DELETE){ //clear input entry
|
|
|
index = 0;
|
|
|
- z = 1; //sets column position for LCD displayed character
|
|
|
- print_chars(3,z,(char *) " ",5);
|
|
|
- numbers[index] = '\0'; //
|
|
|
- decimalPoint = ' '; //clear decimal point test character reset
|
|
|
- customKey ='\0';
|
|
|
+ z = 1;
|
|
|
+ memcpy(line_input+z,(char *) " ",5); //sets column position for LCD displayed character
|
|
|
+ print_input();
|
|
|
+ numbers[index] = 0x00; //
|
|
|
+ decimalPoint = false; //clear decimal point test character reset
|
|
|
+ customKey=NO_KEY;
|
|
|
}
|
|
|
|
|
|
- if(customKey == 'F') { //use entered number
|
|
|
+ if(customKey == DIGIT_ENTER) { //use entered number
|
|
|
x = atof(numbers);
|
|
|
reading = x;
|
|
|
encoderPosition = reading*1000;
|
|
|
index = 0;
|
|
|
- numbers[index] = '\0';
|
|
|
+ numbers[index] = 0x00;
|
|
|
z = 1; //sets column position for LCD displayed character
|
|
|
- print_chars(3,z,(char *) " ",5);
|
|
|
- decimalPoint = (' '); //clear decimal point test character reset
|
|
|
- customKey ='\0';
|
|
|
+ memcpy(line_input+z,(char *) " ",5);
|
|
|
+ print_input();
|
|
|
+ decimalPoint = false; //clear decimal point test character reset
|
|
|
+ customKey=NO_KEY;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -687,10 +623,10 @@ void displayEncoderReading (void) {
|
|
|
if ( Mode == MODE_CP || Mode == MODE_CR ) {
|
|
|
//lcd.print (reading, 2); //show input reading from Rotary Encoder on LCD
|
|
|
dtostrf(reading, 5, 2, buff);
|
|
|
- print_chars(2,cursor_pos++,(char*)buff,5);
|
|
|
+ print_chars(1,cursor_pos++,(char*)buff,5);
|
|
|
} else {
|
|
|
dtostrf(reading, 5, 3, buff);
|
|
|
- print_chars(2,cursor_pos++,(char*)buff,5);
|
|
|
+ print_chars(1,cursor_pos++,(char*)buff,5);
|
|
|
}
|
|
|
//lcd.setCursor (CP, 2); //sets cursor position
|
|
|
//lcd.cursor(); //show cursor on LCD
|
|
@@ -765,8 +701,8 @@ void ActualReading(void) {
|
|
|
} else {
|
|
|
dtostrf(ActualCurrent, 4, 2, buff);
|
|
|
}
|
|
|
- memcpy(line1,buff ,5);
|
|
|
- memcpy(line1+5,(char *)"A " ,2);
|
|
|
+ memcpy(line_current,buff ,5);
|
|
|
+ memcpy(line_current+5,(char *)"A" ,1);
|
|
|
|
|
|
if (ActualVoltage < 10.0) {
|
|
|
//lcd.print(ActualVoltage, 3);
|
|
@@ -774,16 +710,18 @@ void ActualReading(void) {
|
|
|
} else {
|
|
|
dtostrf(ActualVoltage, 4, 2, buff);
|
|
|
}
|
|
|
- memcpy(line1+7,buff ,6);
|
|
|
- memcpy(line1+12,(char *)"V " ,2);
|
|
|
-
|
|
|
+ memcpy(line_volt,buff ,5);
|
|
|
+ memcpy(line_volt+5,(char *)"V" ,1);
|
|
|
if (ActualPower < 100 ) {
|
|
|
dtostrf(ActualPower, 4, 2, buff);
|
|
|
+
|
|
|
} else {
|
|
|
dtostrf(ActualPower, 4, 1, buff);
|
|
|
}
|
|
|
- memcpy(line1+14,buff ,6);
|
|
|
- print_chars(1,18,(char *)"W " ,2);
|
|
|
+ uint8_t len = strlen(buff);
|
|
|
+ memcpy(line_power,buff, 5);
|
|
|
+ memcpy(line_power+len,(char *)"W" ,1);
|
|
|
+ print_reading();
|
|
|
}
|
|
|
|
|
|
//-----------------------DAC Control Voltage for Mosfet---------------------------------------
|
|
@@ -910,7 +848,6 @@ void LoadSwitch(void) {
|
|
|
{
|
|
|
color_load(0);
|
|
|
|
|
|
- color_load(0);
|
|
|
current_instruction = 0; //reset current instruction for Transient List Mode to zero
|
|
|
last_time = 0; //reset last time to zero
|
|
|
transientPeriod = 0; //reset transient period time to zero
|
|
@@ -933,7 +870,9 @@ void Current(void) {
|
|
|
memcpy(line0,(char*)"DC LOAD ",12);
|
|
|
print_chars2(0,20);
|
|
|
writeNum2("t0.xcen",(uint16_t) 0);
|
|
|
- print_chars(2,0,(char*)"Set I = A",20);
|
|
|
+ print_chars(1,0,(char*)"Set I = A",20);
|
|
|
+ memset(line2,' ',20);
|
|
|
+ print_chars2(2,20);
|
|
|
memset(line3,' ',20);
|
|
|
print_chars2(3,20);
|
|
|
CP = 9; //sets cursor starting position to units.
|
|
@@ -946,7 +885,9 @@ void Power(void) {
|
|
|
writeNum2("t0.xcen",(int) 0);
|
|
|
memcpy(line0,(char*)"DC LOAD ",12);
|
|
|
print_chars2(0,20);
|
|
|
- print_chars(2,0,(char*)"Set W = W",22);
|
|
|
+ print_chars(1,0,(char*)"Set W = W",20);
|
|
|
+ memset(line2,' ',20);
|
|
|
+ print_chars2(2,20);
|
|
|
memset(line3,' ',20);
|
|
|
print_chars2(3,20);
|
|
|
CP = 10; //sets cursor starting position to units.
|
|
@@ -959,7 +900,9 @@ void Resistance(void) {
|
|
|
writeNum2("t0.xcen",(int) 0);
|
|
|
memcpy(line0,(char*)"DC LOAD ",12);
|
|
|
print_chars2(0,20);
|
|
|
- print_chars(2,0,(char*)"Set R = R",20);
|
|
|
+ print_chars(1,0,(char*)"Set R = R",20);
|
|
|
+ memset(line2,' ',20);
|
|
|
+ print_chars2(2,20);
|
|
|
memset(line3,' ',20);
|
|
|
print_chars2(3,20);
|
|
|
CP = 10; //sets cursor starting position to units.
|
|
@@ -975,7 +918,9 @@ void BatteryCapacity(void) {
|
|
|
memcpy(line0,"BATTERY ",20);
|
|
|
memcpy(line0+8,(char *)BatteryType.c_str(),4);
|
|
|
print_chars2(0,20);
|
|
|
- print_chars(2,0,(char*)"Set I = A",20);
|
|
|
+ print_chars(1,0,(char*)"Set I = A",20);
|
|
|
+ memset(line2,' ',20);
|
|
|
+ print_chars2(2,20);
|
|
|
memset(line3,' ',20);
|
|
|
print_chars2(3,20);
|
|
|
CP = 9; //sets cursor starting position to units.
|
|
@@ -991,47 +936,49 @@ void batteryType (void) {
|
|
|
print_chars(1,0,(char*)"1=LiPo/Li-Ion 2=LiFe",20);
|
|
|
print_chars(2,0,(char*)"3=NiCd/NiMH 4=ZiZn",20);
|
|
|
print_chars(3,0,(char*)"5=Set Voltage 6=Exit",20);
|
|
|
- customKey='\0';
|
|
|
- wait_for_key(true); //stop everything till the user press a key.
|
|
|
-
|
|
|
- if (customKey == '1'){
|
|
|
- BatteryCutoffVolts = LiPoCutOffVoltage;
|
|
|
- BatteryType = ("LiPo");
|
|
|
- }
|
|
|
-
|
|
|
- if (customKey == '2'){
|
|
|
- BatteryCutoffVolts = LiFeCutOffVoltage;
|
|
|
- BatteryType = ("LiFe");
|
|
|
- }
|
|
|
+ customKey=NO_KEY;
|
|
|
+ BatteryType =("");
|
|
|
+ while(customKey==0x00){
|
|
|
+ wait_for_key(true); //stop everything till the user press a key.
|
|
|
+
|
|
|
+ if (customKey == DIGIT_1){
|
|
|
+ BatteryCutoffVolts = LiPoCutOffVoltage;
|
|
|
+ BatteryType = ("LiPo");
|
|
|
+ }
|
|
|
+ else if (customKey == DIGIT_2){
|
|
|
+ BatteryCutoffVolts = LiFeCutOffVoltage;
|
|
|
+ BatteryType = ("LiFe");
|
|
|
+ }
|
|
|
|
|
|
- if (customKey == '3'){
|
|
|
- BatteryCutoffVolts = NiCdCutOffVoltage;
|
|
|
- BatteryType = ("NiCd");
|
|
|
- }
|
|
|
+ else if (customKey == DIGIT_3){
|
|
|
+ BatteryCutoffVolts = NiCdCutOffVoltage;
|
|
|
+ BatteryType = ("NiCd");
|
|
|
+ }
|
|
|
|
|
|
- if (customKey == '4'){
|
|
|
- BatteryCutoffVolts = ZiZnCutOffVoltage;
|
|
|
- BatteryType = ("ZiZn");
|
|
|
- }
|
|
|
+ else if (customKey == DIGIT_4){
|
|
|
+ BatteryCutoffVolts = ZiZnCutOffVoltage;
|
|
|
+ BatteryType = ("ZiZn");
|
|
|
+ }
|
|
|
|
|
|
- if (customKey == '5'){
|
|
|
- BatteryType = ("SetV");
|
|
|
- }
|
|
|
+ else if (customKey == DIGIT_5){
|
|
|
+ BatteryType = ("SetV");
|
|
|
+ }
|
|
|
|
|
|
- if (customKey == '6'){ //Exit selection screen
|
|
|
- exitMode = 1;
|
|
|
+ else if (customKey == DIGIT_6){ //Exit selection screen
|
|
|
+ exitMode = 1;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ customKey=NO_KEY;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (customKey == '7' || customKey == '8' || customKey == '9' || customKey == '0' || customKey == 'A' || customKey == 'B' || customKey == 'C' || customKey == 'D' || customKey == '*' || customKey == '#' || customKey == 'E' || customKey == 'F' || customKey == '<' || customKey == '>' ){
|
|
|
- batteryType(); //ignore other keys
|
|
|
- }
|
|
|
|
|
|
if(BatteryType == "SetV" && exitMode != 1){
|
|
|
setBatteryCutOff();
|
|
|
}
|
|
|
|
|
|
batteryTypeSelected(); //briefly display battery type selected and discharge cut off voltage
|
|
|
- customKey=0x00;
|
|
|
+ customKey=NO_KEY;
|
|
|
screen_clear(' ');
|
|
|
|
|
|
}
|
|
@@ -1101,18 +1048,18 @@ void wait_for_key(bool wait){
|
|
|
//------------------------Key input used for Battery Cut-Off and Transient Mode------------------------
|
|
|
void inputValue (int r=0){
|
|
|
|
|
|
- while(customKey != 'F'){ //check if enter pressed (was previously #)
|
|
|
- customKey=0x00;
|
|
|
+ while(customKey != DIGIT_ENTER){ //check if enter pressed (was previously #)
|
|
|
+ customKey=NO_KEY;
|
|
|
wait_for_key(true);
|
|
|
- if(customKey >= '0' && customKey <= '9'){ //check for keypad number input
|
|
|
- numbers[index++] = customKey;
|
|
|
- numbers[index] = '\0';
|
|
|
- print_char(r,z,customKey);
|
|
|
+ if(customKey >= DIGIT_1 && customKey <= DIGIT_0){ //check for keypad number input
|
|
|
+ numbers[index++] = (customKey-1 == 10 ? '0' : '0' +customKey-1 );
|
|
|
+ numbers[index] = 0x00;
|
|
|
+ print_char(r,z,(customKey-1 == 10 ? '0' : '0' +customKey-1 ));
|
|
|
z++;
|
|
|
}
|
|
|
|
|
|
- if(customKey == '>'){ //Decimal point
|
|
|
- if (decimalPoint != '>'){ //test if decimal point entered twice - if so skip
|
|
|
+ if(customKey == DIGIT_DECIMAL){ //Decimal point
|
|
|
+ if (!decimalPoint ){ //test if decimal point entered twice - if so skip
|
|
|
if (index==0){
|
|
|
numbers[index++] = '0';
|
|
|
print_char(r,z,'0');
|
|
@@ -1122,29 +1069,29 @@ void inputValue (int r=0){
|
|
|
numbers[index] = 0x00;
|
|
|
print_char(r,z,'.');
|
|
|
z++;
|
|
|
- decimalPoint = '>'; //used to indicate decimal point has been input
|
|
|
+ decimalPoint = true; //used to indicate decimal point has been input
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(customKey == '<'){ //clear entry
|
|
|
+ if(customKey == DIGIT_DELETE){ //clear entry
|
|
|
index = 0;
|
|
|
z = y;
|
|
|
|
|
|
numbers[index] = 0x00;
|
|
|
//
|
|
|
print_chars(r,z,(char *)" ",5);
|
|
|
- decimalPoint = (' '); //clear decimal point test character reset
|
|
|
+ decimalPoint = false; //clear decimal point test character reset
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- if(customKey == 'F') { //enter value
|
|
|
+ if(customKey == DIGIT_ENTER) { //enter value
|
|
|
x = atof(numbers);
|
|
|
index = 0;
|
|
|
numbers[index] = 0x00;
|
|
|
- decimalPoint = (' '); //clear decimal point test character reset
|
|
|
+ decimalPoint = false; //clear decimal point test character reset
|
|
|
}
|
|
|
- customKey=0x00;
|
|
|
+ customKey=NO_KEY;
|
|
|
}
|
|
|
|
|
|
//----------------------------------------Transient Mode--------------------------------------------
|
|
@@ -1171,7 +1118,7 @@ void transientMode (void) {
|
|
|
dtostrf(LowCurrent, 5, 3, buff);
|
|
|
print_chars(r,11,buff,5);
|
|
|
|
|
|
- customKey = 0x00;
|
|
|
+ customKey=NO_KEY;
|
|
|
|
|
|
z = 11;
|
|
|
memcpy(line2,(char *)"Set High I=",11);
|
|
@@ -1187,7 +1134,7 @@ void transientMode (void) {
|
|
|
dtostrf(HighCurrent, 5, 3, buff);
|
|
|
print_chars(r,11,buff,5);
|
|
|
|
|
|
- customKey = 0x00;
|
|
|
+ customKey=NO_KEY;
|
|
|
|
|
|
if(Mode == MODE_TC || Mode == MODE_TP){
|
|
|
z = 11;
|
|
@@ -1236,51 +1183,41 @@ void transientType (void) {
|
|
|
memcpy(line3+11,(char*)"5 = Exit",9);
|
|
|
print_chars2(3,0);
|
|
|
while ( customKey == 0x00 ||
|
|
|
- customKey == '6' ||
|
|
|
- customKey == '7' ||
|
|
|
- customKey == '8' ||
|
|
|
- customKey == '9' ||
|
|
|
- customKey == '0' ||
|
|
|
- customKey == 'A' ||
|
|
|
- customKey == 'B' ||
|
|
|
- customKey == 'C' ||
|
|
|
- customKey == 'D' ||
|
|
|
- customKey == '*' ||
|
|
|
- customKey == '#' ||
|
|
|
- customKey == 'E' ||
|
|
|
- customKey == 'F' ||
|
|
|
- customKey == '<' ||
|
|
|
- customKey == '>' ){
|
|
|
- customKey = 0x00;
|
|
|
+ customKey == DIGIT_6 ||
|
|
|
+ customKey == DIGIT_7 ||
|
|
|
+ customKey == DIGIT_8 ||
|
|
|
+ customKey == DIGIT_9 ||
|
|
|
+ customKey >= DIGIT_0){
|
|
|
+ customKey=NO_KEY;
|
|
|
wait_for_key(1); //stop everything till the user press a key.
|
|
|
}
|
|
|
- if (customKey == '1'){
|
|
|
+ if (customKey == DIGIT_1){
|
|
|
Mode = MODE_TC;
|
|
|
}
|
|
|
|
|
|
- if (customKey == '2'){
|
|
|
+ if (customKey == DIGIT_2){
|
|
|
Mode = MODE_TT;
|
|
|
}
|
|
|
|
|
|
- if (customKey == '3'){
|
|
|
+ if (customKey == DIGIT_3){
|
|
|
Mode = MODE_TP;
|
|
|
}
|
|
|
|
|
|
- if (customKey == '4'){
|
|
|
+ if (customKey == DIGIT_4){
|
|
|
Mode = MODE_TL;
|
|
|
}
|
|
|
|
|
|
- if (customKey == '5'){ //Exit selection screen
|
|
|
+ if (customKey == DIGIT_5){ //Exit selection screen
|
|
|
exitMode = 1;
|
|
|
}
|
|
|
|
|
|
screen_clear(' ');
|
|
|
- customKey=0x00;
|
|
|
+ customKey=NO_KEY;
|
|
|
if (exitMode == 1){ //if NO Transient Mode type selected revert to CC Mode
|
|
|
color_load(0);
|
|
|
Current(); //if selected go to Constant Current Selected routine
|
|
|
encoderPosition = 0; //reset encoder reading to zero
|
|
|
- customKey = 'A';
|
|
|
+ customKey = DIGIT_CURRENT;
|
|
|
}else{
|
|
|
transientMode();
|
|
|
}
|
|
@@ -1335,7 +1272,7 @@ void transientListSetup(){
|
|
|
z = 0;
|
|
|
inputValue(3);
|
|
|
total_instructions = int(x-1);
|
|
|
- customKey = 0x00;
|
|
|
+ customKey=NO_KEY;
|
|
|
//lcd.clear();
|
|
|
char buff[5] = {0x00};
|
|
|
for(int i=0; i<=(total_instructions); i++){
|
|
@@ -1352,7 +1289,7 @@ void transientListSetup(){
|
|
|
z = 0;
|
|
|
inputValue(1); //get the users input value
|
|
|
transientList[i][0] = x; //store the users entered value in the transient list
|
|
|
- customKey = 0x00;
|
|
|
+ customKey=NO_KEY;
|
|
|
memcpy(line2,"Set Time ",16);
|
|
|
length = snprintf( NULL, 0, "%d", i+1 );
|
|
|
itoa(i+1 ,buff,10);
|
|
@@ -1365,7 +1302,7 @@ void transientListSetup(){
|
|
|
z = 0;
|
|
|
inputValue(3); //get the users input value
|
|
|
transientList[i][1] = x; //store the users entered value in the transient list
|
|
|
- customKey = 0x00;
|
|
|
+ customKey=NO_KEY;
|
|
|
screen_clear(' ');
|
|
|
}
|
|
|
current_instruction = 0; //start at first instrution
|
|
@@ -1373,62 +1310,87 @@ void transientListSetup(){
|
|
|
|
|
|
//-------------------------------------Transcient Load Toggel-------------------------------------------
|
|
|
void transientLoadToggle(){
|
|
|
-
|
|
|
+ char buff[5] = {0x00};
|
|
|
if(Mode == MODE_TC){
|
|
|
current_time = micros(); //get the current time in micro seconds()
|
|
|
if (last_time == 0){
|
|
|
last_time = current_time;
|
|
|
} else {
|
|
|
+ memcpy(line1,"Set I = A",20);
|
|
|
switch (transient_mode_status){
|
|
|
case (false):
|
|
|
// we are in the low current setting
|
|
|
if ((current_time - last_time) >= (transientPeriod * 1000.0)){
|
|
|
- transientSwitch(LowCurrent, true);
|
|
|
+ transientSwitch(LowCurrent, true);
|
|
|
+ dtostrf(LowCurrent, 4, 3, buff);
|
|
|
+ memcpy(line1+8,buff ,5);
|
|
|
+ print_chars2(1,20);
|
|
|
}
|
|
|
break;
|
|
|
case (true):
|
|
|
// we are in the high current setting
|
|
|
if ((current_time - last_time) >= (transientPeriod * 1000.0)){
|
|
|
- transientSwitch(HighCurrent, true);
|
|
|
+ transientSwitch(HighCurrent, true);
|
|
|
+ dtostrf(HighCurrent, 4, 3, buff);
|
|
|
+ memcpy(line1+8,buff ,5);
|
|
|
+ print_chars2(1,20);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
|
|
|
if(Mode == MODE_TP){
|
|
|
current_time = micros(); //get the current time in micro seconds()
|
|
|
+ memcpy(line1,"Set I = A",20);
|
|
|
if (last_time == 0){
|
|
|
last_time = current_time;
|
|
|
transientSwitch(LowCurrent, true);
|
|
|
+ dtostrf(LowCurrent, 4, 3, buff);
|
|
|
+ memcpy(line1+8,buff ,5);
|
|
|
}
|
|
|
if (digitalRead(TriggerPulse) == LOW || trig_key){
|
|
|
// a trigger pluse is received
|
|
|
// set to the high current
|
|
|
trig_key=false;
|
|
|
transientSwitch(HighCurrent, true);
|
|
|
+ dtostrf(HighCurrent, 4, 3, buff);
|
|
|
+ memcpy(line1+8,buff ,5);
|
|
|
+ print_chars2(1,20);
|
|
|
} else {
|
|
|
if ((current_time - last_time) >= (transientPeriod * 1000.0)){
|
|
|
- transientSwitch(LowCurrent, true);
|
|
|
+ transientSwitch(LowCurrent, true);
|
|
|
+ dtostrf(LowCurrent, 4, 3, buff);
|
|
|
+ memcpy(line1+8,buff ,5);
|
|
|
+ print_chars2(1,20);
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
if(Mode == MODE_TT){ // this function will toggle between high and low current when the trigger pin is taken low
|
|
|
+
|
|
|
if (digitalRead(TriggerPulse) == LOW || trig_key){
|
|
|
+ memcpy(line1,"Set I = A",20);
|
|
|
trig_key=false;
|
|
|
switch (transient_mode_status){
|
|
|
case (false):
|
|
|
transientSwitch(LowCurrent, true);
|
|
|
+ dtostrf(LowCurrent, 4, 3, buff);
|
|
|
+ memcpy(line1+8,buff ,5);
|
|
|
delay(200); //added to prevent key bounce when transient button used (date of addition 31-03-2018)
|
|
|
break;
|
|
|
case (true):
|
|
|
transientSwitch(HighCurrent, true);
|
|
|
+ dtostrf(HighCurrent, 4, 3, buff);
|
|
|
+ memcpy(line1+8,buff ,5);
|
|
|
delay(200); //added to prevent key bounce when transient button used (date of addition 31-03-2018)
|
|
|
break;
|
|
|
}
|
|
|
+ print_chars2(1,20);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1488,7 +1450,7 @@ void userSetUp (void) {
|
|
|
CurrentCutOff = x;
|
|
|
EEPROM.write(0x00, CurrentCutOff);
|
|
|
|
|
|
- customKey = 0x00;
|
|
|
+ customKey=NO_KEY;
|
|
|
z = 15;
|
|
|
memcpy(line2,"Power Limit = W",21);
|
|
|
print_chars2(2,20);
|
|
@@ -1496,7 +1458,7 @@ void userSetUp (void) {
|
|
|
PowerCutOff = x;
|
|
|
EEPROM.write(0x20, PowerCutOff);
|
|
|
|
|
|
- customKey = 0x00;
|
|
|
+ customKey=NO_KEY;
|
|
|
z = 15;
|
|
|
line3[18]=0xB0;
|
|
|
memcpy(line3,"Temp. Limit = C",21);
|
|
@@ -1512,7 +1474,7 @@ void userSetUp (void) {
|
|
|
color_load(0);
|
|
|
Current(); //if selected go to Constant Current Selected routine
|
|
|
encoderPosition = 0; //reset encoder reading to zero
|
|
|
- customKey = 'A';
|
|
|
+ customKey = DIGIT_CURRENT;
|
|
|
}
|
|
|
|
|
|
//------------------------------------------High Temperature Cut-Off--------------------------------------------------------------
|