Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SolarNanoGridv3 by
SolarNanoGrid.cpp
- Committer:
- defrost
- Date:
- 2016-05-06
- Revision:
- 1:df924e0126d1
- Parent:
- 0:dc8a45ec969a
- Child:
- 2:929cf7fc6998
File content as of revision 1:df924e0126d1:
#include "pinmap.h" #include "battery.h" #include "locker.h" #include "SolarNanoGrid.h" #define DEBUG #define INFOMESSAGES #define WARNMESSAGES #define ERRMESSAGES #ifdef DEBUG #define DBG(x, ...) printf("[SNG : DBG] "x"\r\n", ##__VA_ARGS__); #else #define DBG(x, ...) #endif #ifdef ERRMESSAGES #define ERR(x, ...) printf("[SNG : ERR] "x"\r\n", ##__VA_ARGS__); #else #define ERR(x, ...) #endif #ifdef WARNMESSAGES #define WARN(x, ...) printf("[SNG : WARN] "x"\r\n", ##__VA_ARGS__); #else #define WARN(x, ...) #endif #ifdef INFOMESSAGES #define INFO(x, ...) printf("[SNG : INFO] "x"\r\n", ##__VA_ARGS__); #else #define INFO(x, ...) #endif // Constructor: SolarNanoGrid::SolarNanoGrid(SDFileSystem* sd){ // Save the sd card pointer: _sd = sd; // initialize the SNG module: char * name = "/sd/config.ini"; FILE *fp; spiSD(); mkdir("/sd/binData",777); mkdir("/sd/data",777); mkdir("/sd/compress",777); //Configuration INFO("Reading config file..."); fp = fopen(name, "r"); if (fp == NULL) { ERR("Config file cannot be read"); return; } if (fscanf (fp,"%c %*c %*s",&role )!=1) WARN("Config: cannot read role"); if (fscanf (fp,"%d %*c %*s",&sdVersion )!=1) WARN("Config: cannot read version"); if (fscanf (fp,"%x %*c %*s",&id )!=1) WARN("Config: cannot read id"); id = 1; INFO(" Type:%c, Version %u, ID %d",role,sdVersion,id); switch (role) { case('B'): case('b'): SongBat = new battery(nrf1); SongBat.initialiseBattery(fp); break; case('L'): case('l'): initialiseLocker(fp); break; } return; } void SolarNanoGrid::loop(void) { switch (role) { case('B'): { // Battery loopBattery(); break; } case('M'): { // Master // loopMaster(); break; } case('L'): { // Locker loopLocker(); break; } } }