Skip to content

Commit

Permalink
v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaztech committed Mar 27, 2024
1 parent badc2fc commit bee70f7
Show file tree
Hide file tree
Showing 26 changed files with 5,026 additions and 410 deletions.
85 changes: 61 additions & 24 deletions Arduino/PillDispenser/Check_Alerts.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ static void check_trays_timer_cb(lv_timer_t * timer) {
localtime_r(&now, &timeinfo);

for (int i = 1; i <= 10; i++) {
if (trayAlertEna[i] && !alreadyTriggered[i] && trayEnabled[i]) {
if (trayAlertEna[i] && !alreadyTriggered[i] && trayEnabled[i] && !traydisptoday[i] && !traydismtoday[i]) {
if (trayHours[i] == timeinfo.tm_hour && trayMin[i] == timeinfo.tm_min) {
// Trigger the visual alert for this tray
traytriggered[i] = true;
Expand All @@ -16,19 +16,35 @@ static void check_trays_timer_cb(lv_timer_t * timer) {
lv_obj_clear_state(ui_TrayIMG[i], LV_STATE_CHECKED); // Clear visual indication
}
lv_timer_create(reset_triggered_timer, 120000, NULL);

lv_timer_reset(alertsound_timer); //reset alert sound timer
Playsound(1);

alertinprogress = true;

lv_obj_add_state(ui_TraycfgBTN, LV_STATE_DISABLED); // Disable the tray config button
lv_obj_clear_state(ui_DispenseBTN, LV_STATE_DISABLED); // Enable the dispense button
lv_obj_clear_flag(ui_DismissBTN, LV_OBJ_FLAG_HIDDEN); // Show the dismiss button
lv_label_set_text(ui_DispenseBTNLBL, "Dispense\nFlashing\nTray(s)\n(By color)");
placethings();
lv_scr_load(ui_MainSCR);
}
}
if (resetHours == timeinfo.tm_hour && resetMin == timeinfo.tm_min) {
traydisptoday[i] = false;
traydismtoday[i] = false;
lv_obj_add_flag(ui_TrayCheckIMG[i], LV_OBJ_FLAG_HIDDEN);

char key[20]; // Key string to use for preferences
preferences.begin("traySettings", false); // Open Preferences with namespace "traySettings". False for read and write.

// Save tray alert enabled status
snprintf(key, sizeof(key), "traydisptoday%d", i);
preferences.putBool(key, traydisptoday[i]);
snprintf(key, sizeof(key), "traydismtoday%d", i);
preferences.putBool(key, traydismtoday[i]);

preferences.end(); // Close the Preferences
}
}
}

Expand All @@ -40,36 +56,66 @@ static void reset_triggered_timer(lv_timer_t * timer) { // Reset the alreadyTrig
}

static void flashing_timer(lv_timer_t * timer) {
static uint8_t ledState = 0; // Manage LED flashing state independently

for (int i = 1; i <= 10; i++) {
if (traytriggered[i]) {
// Handle tray recoloring based on flashing state and tray-specific conditions
lv_obj_set_style_img_recolor(ui_DownIMGBTN, lv_color_hex(0x3175DE), 0);
lv_obj_set_style_img_recolor(ui_UpIMGBTN, lv_color_hex(0x3175DE), 0);
if (flashing == 1 || flashing == 2) { //slow flash

if (flashing == 1 || flashing == 2) { // Slow flash
if (i <= 5) lv_obj_set_style_img_recolor_opa(ui_DownIMGBTN, LV_OPA_TRANSP, 0); // Disable recoloring
if (i >= 6) lv_obj_set_style_img_recolor_opa(ui_UpIMGBTN, LV_OPA_TRANSP, 0); // Disable recoloring
if (!trayfastflash[i]) showLED(pixels.Color(0, 0, 0));
if (!trayfastflash[i]) lv_obj_set_style_img_recolor_opa(ui_TrayIMG[i], LV_OPA_TRANSP, 0); // Disable recoloring
} else {
} else { // Normal or fast flash state
if (i <= 5) lv_obj_set_style_img_recolor_opa(ui_DownIMGBTN, 255, 0); // Enable recoloring
if (i >= 6) lv_obj_set_style_img_recolor_opa(ui_UpIMGBTN, 255, 0); // Enable recoloring
if (!trayfastflash[i]) showLED(currentpixelcolor);
if (!trayfastflash[i]) lv_obj_set_style_img_recolor_opa(ui_TrayIMG[i], 150, 0); // Enable recoloring
}

if (systemloaded) {
lv_timer_reset(inactivity_timer);//reset screensaver timer
digitalWrite(21, HIGH);
lv_timer_reset(inactivity_timer); // Reset screensaver timer
digitalWrite(21, HIGH); // Assuming this is a signal to indicate activity
}
}
if (flashing == 1 || flashing == 3) { //fast flash
if (trayfastflash[i]) lv_obj_set_style_img_recolor_opa(ui_TrayIMG[i], LV_OPA_TRANSP, 0); // Disable recoloring
if (trayfastflash[i]) showLED(pixels.Color(0, 0, 0));
} else {
if (trayfastflash[i]) lv_obj_set_style_img_recolor_opa(ui_TrayIMG[i], 150, 0); // Enable recoloring
if (trayfastflash[i]) showLED(currentpixelcolor);
}
}

//// Adjustment here to break out when there's a fastflash

for (int i = 1; i <= 10; i++) {
if (!solidLED) {
if (trayfastflash[i]) {
if (flashing == 1 || flashing == 3) { //fast flash
showLED(pixels.Color(0, 0, 0));
} else {
showLED(currentpixelcolor);
}
break;
} else {
if (traytriggered[i] && !trayfastflash[i]) {
if (flashing == 1 || flashing == 2) { //slow flash
if (!trayfastflash[i]) showLED(pixels.Color(0, 0, 0));
} else {
if (!trayfastflash[i]) showLED(currentpixelcolor);
}
}
}
} else {
showLED(currentpixelcolor);
}
}

////////

// Update flashing state
flashing++;
if (flashing == 4) flashing = 0;
if (flashing > 3) flashing = 0;
}

void placethings() {
Expand All @@ -83,9 +129,11 @@ void placethings() {
currentpixelcolor = index_to_pixel(trayColor[i]);
}
}
checkmark();
if (!anytriggered) {
alertinprogress = false;
lv_label_set_text(ui_DispenseBTNLBL, "Dispense\nSelected\nTray");
lv_obj_add_flag(ui_DismissBTN, LV_OBJ_FLAG_HIDDEN); // Hide the dismiss button
lv_obj_add_state(ui_DispenseBTN, LV_STATE_DISABLED); // Disable the dispense config button
lv_obj_add_flag(ui_PAGE2CON, LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(ui_PAGE1CON, LV_OBJ_FLAG_HIDDEN);
Expand All @@ -104,17 +152,6 @@ void placethings() {
lv_obj_clear_flag(ui_PAGE2CON, LV_OBJ_FLAG_HIDDEN);
}
}

}

static void pick_pills_screen_event_handler(lv_event_t * e) {
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_target(e);

if (code == LV_EVENT_CLICKED) {
showLED(pixels.Color(0, 0, 0));
placethings();
}
}

void showLED(uint32_t color) {
Expand Down
74 changes: 59 additions & 15 deletions Arduino/PillDispenser/Dispense_Rooutine.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,40 @@ void displace(int whichtray, int steps) {
}

void dispense(int whichtray) {
lv_timer_t* timer = lv_timer_create(dispense_step1_timer, 500, NULL);
traytodispense = whichtray;
if (!displacementinprogress) {
if (!dismissinprogress) {
lv_timer_t* timer = lv_timer_create(dispense_step1_timer, 500, NULL);
traytodispense = whichtray;
if (!displacementinprogress) {
traytriggered[whichtray] = false;
trayfastflash[whichtray] = true;
if (trayAlertEna[whichtray]) {
traydisptoday[whichtray] = true;
traydismtoday[whichtray] = false;
char key[20]; // Key string to use for preferences
preferences.begin("traySettings", false); // Open Preferences with namespace "traySettings". False for read and write.
snprintf(key, sizeof(key), "traydisptoday%d", whichtray);
preferences.putBool(key, traydisptoday[whichtray]);
snprintf(key, sizeof(key), "traydismtoday%d", whichtray);
preferences.putBool(key, traydismtoday[whichtray]);
preferences.end(); // Close the Preferences
}
}
} else {
lv_timer_t* timer = lv_timer_create(dispense_step5_timer, 25, NULL);
traytodispense = whichtray;
traytriggered[whichtray] = false;
trayfastflash[whichtray] = true;
if (trayAlertEna[whichtray]) {
traydisptoday[whichtray] = false;
traydismtoday[whichtray] = true;
char key[20]; // Key string to use for preferences
preferences.begin("traySettings", false); // Open Preferences with namespace "traySettings". False for read and write.
snprintf(key, sizeof(key), "traydisptoday%d", whichtray);
preferences.putBool(key, traydisptoday[whichtray]);
snprintf(key, sizeof(key), "traydismtoday%d", whichtray);
preferences.putBool(key, traydismtoday[whichtray]);
preferences.end(); // Close the Preferences
}
}
}

Expand Down Expand Up @@ -48,30 +77,45 @@ static void dispense_step4_timer(lv_timer_t * timer) { //Dispense Step 4
}

static void dispense_step5_timer(lv_timer_t * timer) { //Dispense Step 5
detachServo(traytodispense - 1);
if (!displacementinprogress) {
if (!dismissinprogress) {
detachServo(traytodispense - 1);
if (!displacementinprogress) {
trayfastflash[traytodispense] = false;
lv_obj_set_style_img_recolor_opa(ui_TrayIMG[traytodispense], LV_OPA_TRANSP, 0); // Disable recoloring
traytodispense = -1;
dispensebatch(currentcolordispense);
} else {
displacementinprogress = false;
lv_dropdown_set_selected(ui_DisplaceTrayDROP, 0);
lv_obj_add_flag(ui_InprogressPAN, LV_OBJ_FLAG_HIDDEN);
}
} else {
trayfastflash[traytodispense] = false;
lv_obj_set_style_img_recolor_opa(ui_TrayIMG[traytodispense], LV_OPA_TRANSP, 0); // Disable recoloring
traytodispense = -1;
dispensebatch(currentcolordispense);
} else {
displacementinprogress = false;
lv_dropdown_set_selected(ui_DisplaceTrayDROP, 0);
lv_obj_add_flag(ui_InprogressPAN, LV_OBJ_FLAG_HIDDEN);
}

lv_timer_del(timer);
}

void dispensebatch(int colorindex) {
for (int i = 1; i <= 11; i++) {
if (i == 11) {
dispensebatchinprogress = false;
showLED(currentpixelcolor);
lv_timer_reset(alertsound_timer); //reset alert sound timer
Playsound(2);
lv_scr_load(ui_PickPillsSCR);
break;
if (!dismissinprogress) {
showLED(currentpixelcolor);
lv_timer_reset(alertsound_timer); //reset alert sound timer
Playsound(2);
solidLED = true;
lv_scr_load(ui_PickPillsSCR);
break;
} else {
dismissinprogress = false;
lv_timer_reset(alertsound_timer); //reset alert sound timer
showLED(pixels.Color(0, 0, 0));
placethings();
break;
}
}
if (traytriggered[i] && trayColor[i] == colorindex) {
dispense(i);
Expand Down
76 changes: 69 additions & 7 deletions Arduino/PillDispenser/LVGL_Buttons.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,73 @@ static void DisplaceBTN_event_handler(lv_event_t * e) { // Displace Go Button
}
}

static void TrueDismissBTN_event_handler(lv_event_t * e) { // Dismiss Button
lv_event_code_t code = lv_event_get_code(e);
if (code == LV_EVENT_CLICKED) {
for (int i = 1; i <= 10; i++) {
if (i == 10) {
alertinprogress = false;
lv_obj_add_state(ui_DispenseBTN, LV_STATE_DISABLED); // Disable the button
}
if (traytriggered[i]) {
dispensebatchinprogress = true;
dismissinprogress = true;
currentpixelcolor = index_to_pixel(trayColor[i]);
currentcolordispense = trayColor[i];
dispensebatch(currentcolordispense);
break;
}
}
}
}

static void DispenseAgainBTN_event_handler(lv_event_t * e) { // Double Dispense Button
lv_event_code_t code = lv_event_get_code(e);
if (code == LV_EVENT_CLICKED) {
for (int i = 1; i <= 10; i++) {
if (trayCheckedState[i]) {
currentpixelcolor = index_to_pixel(trayColor[i]);
dispense(i);
trayCheckedState[i] = false;
lv_obj_clear_state(ui_TrayIMG[i], LV_STATE_CHECKED);
}
}
lv_obj_add_state(ui_DispenseBTN, LV_STATE_DISABLED); // Disable the button
lv_obj_add_state(ui_TraycfgBTN, LV_STATE_DISABLED); // Disable the button
}
}

static void DoubleDispenseCancelBTN_event_handler(lv_event_t * e) { // Double Dispense Button
lv_event_code_t code = lv_event_get_code(e);
if (code == LV_EVENT_CLICKED) {
for (int i = 1; i <= 10; i++) {
if (trayCheckedState[i]) {
lv_obj_clear_state(ui_TrayIMG[i], LV_STATE_CHECKED);
}
}
}
}

static void DispenseBTN_event_handler(lv_event_t * e) { // Dispense Button
lv_event_code_t code = lv_event_get_code(e);
if (code == LV_EVENT_CLICKED) {
if (!alertinprogress) { // Normal dispense
if (!alertinprogress) { // Normal dispense (only one tray)
for (int i = 1; i <= 10; i++) {
if (trayCheckedState[i]) {
currentpixelcolor = index_to_pixel(trayColor[i]);
dispense(i);
trayCheckedState[i] = false;
lv_obj_clear_state(ui_TrayIMG[i], LV_STATE_CHECKED);
if (traydisptoday[i]) {
lv_obj_clear_flag(ui_DoubletakePAN, LV_OBJ_FLAG_HIDDEN);
break;
} else {
currentpixelcolor = index_to_pixel(trayColor[i]);
dispense(i);
trayCheckedState[i] = false;
lv_obj_clear_state(ui_TrayIMG[i], LV_STATE_CHECKED);
}
}
lv_obj_add_state(ui_DispenseBTN, LV_STATE_DISABLED); // Disable the button
lv_obj_add_state(ui_TraycfgBTN, LV_STATE_DISABLED); // Disable the button
}
} else { // Alert dispense
} else { // Alert dispense (1 tray or more)
for (int i = 1; i <= 10; i++) {
if (i == 10) {
alertinprogress = false;
Expand All @@ -63,7 +115,6 @@ static void DispenseBTN_event_handler(lv_event_t * e) { // Dispense Button
}
}
}

}
}

Expand Down Expand Up @@ -124,3 +175,14 @@ static void TrayCfgSaveBTN_event_handler(lv_event_t * e) { // Tray Save Button
updateTrays();
}
}

static void pick_pills_screen_event_handler(lv_event_t * e) {
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_target(e);

if (code == LV_EVENT_CLICKED) {
solidLED = false;
showLED(pixels.Color(0, 0, 0));
placethings();
}
}
6 changes: 5 additions & 1 deletion Arduino/PillDispenser/Loading_Screen.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static void startup_step2_timer(lv_timer_t * timer) { //Startup Step 2 (Connecti
lv_obj_add_flag(ui_NoWifiIconIMG, LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(ui_WifiIconIMG, LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(ui_ClockLBL, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(ui_WifiInfoLBL, LV_OBJ_FLAG_HIDDEN);
internetstatus = 1;
String message = "Connected - IP ";
message += WiFi.localIP().toString(); // Append the IP address to the message
Expand All @@ -38,6 +39,7 @@ static void startup_step2_timer(lv_timer_t * timer) { //Startup Step 2 (Connecti
lv_obj_clear_flag(ui_NoWifiIconIMG, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(ui_WifiIconIMG, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(ui_ClockLBL, LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(ui_WifiInfoLBL, LV_OBJ_FLAG_HIDDEN);
internetstatus = 0;
lv_label_set_text(ui_LoadinginfoLBL, "Connection Error...");
lv_timer_create(startup_step3_timer, 2000, NULL);
Expand Down Expand Up @@ -160,7 +162,6 @@ static void startup_step15_timer(lv_timer_t * timer) { //Startup Step 15 (Load M
for (int i = 1; i <= 10; i++) {
loadTraySettings(i);
}
updateTrays();
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.show();

Expand All @@ -171,9 +172,12 @@ static void startup_step15_timer(lv_timer_t * timer) { //Startup Step 15 (Load M
}
lv_timer_create(check_trays_timer_cb, 15000, NULL); // 15000 ms = 15 sec
lv_timer_create(flashing_timer, 250, NULL);
updateTrays();
systemloaded = true;

//lv_obj_clear_state(ui_DispenseBTN, LV_STATE_DISABLED); // Enable the dispense button FOR DEBUGGING !!!!!!!!!!!!!!!!!
//lv_label_set_text(ui_DispenseBTNLBL, "Dispense\nFlashing\nTray(s)\n(By color)"); ///FOR DEBUGGING !!!!!!!!!!!!!!!!!
//lv_obj_clear_flag(ui_DismissBTN, LV_OBJ_FLAG_HIDDEN); // Show the dismiss button ///FOR DEBUGGING !!!!!!!!!!!!!!!!!
//placethings(); ///FOR DEBUGGING !!!!!!!!!!!!!!!!!

lv_timer_del(timer);
Expand Down
Loading

0 comments on commit bee70f7

Please sign in to comment.