Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: EEPROM Manager
- - Source Code NOT compiled for: Arduino Pro Mini 3.3V
- - Source Code created on: 2025-10-09 16:32:12
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Build a highly customizable project management */
- /* system for Chaseone Technologies. using PHP, */
- /* MySQL AND JavaScript. The UI should be an */
- /* attractive, mobile responsive, bootstrap based */
- /* interface. The system will be used to manage */
- /* organization projects t */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <EEPROM.h>
- #include <string.h> // for memset, strncpy, strcmp
- /****** PROJECT CONFIGURATION *****/
- #define MAX_PROJECTS 6
- #define NAME_LEN 16
- #define PROJECT_SIZE sizeof(Project)
- /****** PROJECT STRUCTURE AND STORAGE HANDLING *****/
- typedef struct {
- char name[NAME_LEN];
- uint8_t status;
- uint32_t due; // due date in YYYYMMDD
- uint8_t used; // 1 if slot contains a project
- } Project;
- /****** PRIVATE PROTOTYPES ******/
- void processCommand(const char* cmd);
- void addProject(const char* name, uint8_t status, uint32_t due);
- bool readProject(uint8_t idx, Project &p);
- void writeProject(uint8_t idx, const Project &p);
- void listProjects(void);
- void clearAllProjects(void);
- void clearProjectAt(uint8_t idx);
- void setup(void);
- void loop(void);
- /****** IMPLEMENTATION ******/
- void setup(void) {
- Serial.begin(9600);
- delay(1000); // allow serial connection to establish (if using USB-serial adapter)
- Serial.println(F("Project Manager Ready (Arduino Pro Mini)"));
- Serial.println(F("Type HELP for available commands"));
- // Optional: Initialize EEPROM slots on first run (left as-is to preserve data)
- }
- void loop(void) {
- static const uint16_t LINE_LEN = 64;
- static char line[LINE_LEN];
- static uint16_t len = 0;
- while (Serial.available()) {
- int c = Serial.read();
- if (c < 0) break;
- if (c == '\r') continue;
- if (c == '\n') {
- line[len] = '\0';
- if (len > 0) processCommand(line);
- len = 0;
- } else {
- if (len < LINE_LEN - 1) line[len++] = (char)c;
- }
- }
- }
- void processCommand(const char* cmd) {
- // skip leading spaces
- while (*cmd == ' ') cmd++;
- if (strcmp(cmd, "LIST") == 0) {
- listProjects();
- } else if (strncmp(cmd, "ADD ", 4) == 0) {
- const char* rest = cmd + 4;
- char name[NAME_LEN];
- uint32_t due = 0;
- uint8_t status = 0;
- if (sscanf(rest, "%15s %u %hhu", name, &due, &status) == 3) {
- if (addProject(name, status, due)) {
- Serial.print(F("Added: "));
- Serial.println(name);
- } else {
- Serial.println(F("No free project slots available."));
- }
- } else {
- Serial.println(F("Invalid ADD format. Use: ADD <name> <YYYYMMDD> <status>"));
- }
- } else if (strncmp(cmd, "ERASE ", 6) == 0) {
- unsigned int idx;
- if (sscanf(cmd + 6, "%u", &idx) == 1) {
- if (idx < MAX_PROJECTS) {
- clearProjectAt((uint8_t)idx);
- Serial.print(F("Erased slot "));
- Serial.println(idx);
- } else {
- Serial.println(F("Invalid index"));
- }
- }
- } else if (strcmp(cmd, "CLEAR") == 0) {
- clearAllProjects();
- Serial.println(F("All slots cleared"));
- } else if (strcmp(cmd, "HELP") == 0) {
- Serial.println(F("Commands: LIST | ADD <name> <YYYYMMDD> <status> | ERASE <idx> | CLEAR | HELP"));
- } else {
- Serial.print(F("Unknown command: "));
- Serial.println(cmd);
- }
- }
- // Storage helpers
- bool readProject(uint8_t idx, Project &p) {
- if (idx >= MAX_PROJECTS) return false;
- EEPROM.get(idx * PROJECT_SIZE, p);
- return p.used != 0;
- }
- void writeProject(uint8_t idx, const Project &p) {
- if (idx >= MAX_PROJECTS) return;
- EEPROM.put(idx * PROJECT_SIZE, p);
- }
- bool addProject(const char* name, uint8_t status, uint32_t due) {
- for (uint8_t i = 0; i < MAX_PROJECTS; i++) {
- Project p;
- EEPROM.get(i * PROJECT_SIZE, p);
- if (!p.used) {
- Project np;
- memset(&np, 0, sizeof(Project));
- strncpy(np.name, name, NAME_LEN - 1);
- np.name[NAME_LEN - 1] = '\0';
- np.status = status;
- np.due = due;
- np.used = 1;
- EEPROM.put(i * PROJECT_SIZE, np);
- return true;
- }
- }
- return false;
- }
- void listProjects(void) {
- Serial.println(F("Projects:"));
- for (uint8_t i = 0; i < MAX_PROJECTS; i++) {
- Project p;
- EEPROM.get(i * PROJECT_SIZE, p);
- if (p.used) {
- Serial.print(i);
- Serial.print(": ");
- Serial.print(p.name);
- Serial.print(" Status=");
- Serial.print(p.status);
- Serial.print(" Due=");
- Serial.println(p.due);
- }
- }
- }
- void clearProjectAt(uint8_t idx) {
- if (idx >= MAX_PROJECTS) return;
- Project p;
- memset(&p, 0, sizeof(Project));
- p.used = 0;
- EEPROM.put(idx * PROJECT_SIZE, p);
- }
- void clearAllProjects(void) {
- for (uint8_t i = 0; i < MAX_PROJECTS; i++) clearProjectAt(i);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment