The field version of the solarnano grid on the ionQubes
Fork of SolarNanoGridv3 by
Diff: SolarNanoGrid.cpp
- Revision:
- 22:93fde34d9a94
- Parent:
- 16:919e37e5a895
- Child:
- 26:10e8b9908631
--- a/SolarNanoGrid.cpp Tue Jun 14 22:40:56 2016 +0000 +++ b/SolarNanoGrid.cpp Wed Jun 15 00:20:18 2016 +0000 @@ -36,7 +36,7 @@ DBG("Solar init"); // Leds ledRed = new DigitalOut(LED_RED,1); - ledGreen= new DigitalOut(LED_GREEN,1); + ledGreen= new DigitalOut(LED_RED,1); // The converter uses the saem DIO as the green led as an interrupt in. ledBlue = new DigitalOut(LED_BLUE,1); // Realtime clock time_t now= time(NULL); @@ -99,7 +99,7 @@ /** * Turns SPI on for SD card */ -void SolarNanoGrid::spiSD(void) +void spiSD(void) { //sd.select(); pin_function(PTE1 , 7); //Set SD_MISO as SPI, this is the same as the last number in those tables @@ -110,7 +110,7 @@ /** * Turns SPI on for nrf */ -void SolarNanoGrid::spiNRF(void) +void spiNRF(void) { //sd.deselect(); pin_function(PTE1, 1); //pin function 1 is GPIO @@ -167,37 +167,59 @@ bool result = true; INFO("Loading configuration from %s", name); FILE *fp; - INFO("Reading config file..."); + INFO("Loading config file into settings..."); + spiSD(); fp = fopen(name, "r"); if(fp == NULL) { ERR("Config file cannot be read, USE PC TO CREATE config.ini"); return false; }else{ + DBG("Reading values..."); // Read config.ini - if (fscanf (fp,"%c %*c %*s",role )!=1){ + // Role: + DBG("Role:"); + if (fscanf (fp,"%c %*c %*s",&role )!=1){ ERR("Config: cannot read role"); result = false; + }else{ + DBG("Read Role: %c", role); } - if (fscanf (fp,"%d %*c %*s",sdVersion )!=1){ + // Community ID: + DBG("Community ID:"); + if (fscanf (fp,"%u %*c %*s",&communityID )!=1){ + ERR("Config: cannot read community ID"); + result = false; + }else{ + DBG("Read community ID: %u", communityID); + } + // SD Version: + DBG("SD Version:"); + if (fscanf (fp,"%d %*c %*s",&sdVersion )!=1){ ERR("Config: cannot read version"); result = false; + }else{ + DBG("Read sdVersion: %d", sdVersion); } - if (fscanf (fp,"%u %*c %*s",communityID )!=1){ - ERR("Config: cannot read community ID"); - result = false; - } - if (fscanf (fp,"%x %*c %*s",id)!=1){ + // ID: + DBG("ID:"); + if (fscanf (fp,"%x %*c %*s",&id)!=1){ ERR("Config: cannot read ID"); result = false; + }else{ + DBG("Read read ID: %x", id); } - if (fscanf (fp,"%x %*c %*s",chan )!=1){ + // Channel: + DBG("Channel:"); + if (fscanf (fp,"%x %*c %*s",&chan )!=1){ ERR("Locker config: cannot read channel"); result = false; + }else{ + DBG("Read channel: %x", chan); } if(result == true){ // create the log directory string, this does NOT create the directory! - sprintf(LogDir, "/sd/data/%02X%04X", (communityID&0XFF),(id&0XFFFF)); + sprintf(LogDir, "/sd/data/%02x%04x", (communityID&0XFF),(id&0XFFFF)); // Print everything back: INFO("config.ini: Version %u, Community %u ID %x Channel %x, Log Directory: %s",sdVersion, communityID, id, chan, LogDir); }else{