Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving of user Settings added. #6

Merged
merged 6 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ lib_deps =

# Known issues

Current implementation doesn't retain the user data in the non-volatile memory of the MCU. This is because there is a issue/bug that makes accessing such saved data early after device boot up fail. Probably because when it comes to the built-in library: `preferences.h`, it needs some time to fetch data after initialising and opening a namespace. It seems to be running on a dedicated core, parallely.
Currently there are no known issues. If there is any, please open an issue in the `issus` section with a relavant label.

# Screenshot Gallery

Expand Down
3 changes: 2 additions & 1 deletion include/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define DHTTYPE DHT11 // DHT 11
#define NTP_SERVER "pool.ntp.org"
#define UTC_OFFSET_DST 0 // Daytime offset is not implemented. hence kept zero to have no effect.
#define DEFAULT_UTC_OFFSET 19800 // 5:30 hours in seconds.i.e. Sri lankas time.
#define DEFAULT_UTC_OFFSET_H 5
#define DEFAULT_UTC_OFFSET_M 30
#define WIFI_SSID "MSI 8690"
#define WIFI_PASSWORD "abcdefgh"
9 changes: 8 additions & 1 deletion include/Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void go_to_menu();
void update_time_with_check_alarm();
void println(String text, int column, int row, int text_size, bool display_now = false, int color = WHITE);
void println(tm timeinfo, const char *text, int column, int row, int text_size, bool display_now = false, int color = WHITE);
void show_modal_page(const unsigned char* bitmap,int period, String text, int x_offset);
void show_modal_page(const unsigned char *bitmap, int period, String text, int x_offset);

// FUnctions from temperature.cpp
void check_temp();
Expand All @@ -20,3 +20,10 @@ void check_temp();
void set_time_zone();
void update_time();
void print_time_now();

// Functions of preferences.cpp
void load_user_settings();
void save_time_zone();
void save_alarm(int alarm);
void reset_preferences();
void save_is_alarm_enabled();
14 changes: 10 additions & 4 deletions include/Globals.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
#include <Adafruit_SSD1306.h>
#include <DHT.h>
#include <Preferences.h>

extern Adafruit_SSD1306 display;
extern DHT dhtSensor;
extern Preferences preferences;

extern bool alarm_enabled;
extern const int n_alarms;
extern int alarm_hours[];
extern int alarm_minutes[];
extern bool alarm_triggered[];
extern struct tm timeinfo;
extern int temp_offset_hours;
extern int temp_offset_minutes;
// images
extern const unsigned char splashScreen[];
extern const unsigned char tick[];
extern const unsigned char wifi[];
extern const unsigned char waveformAnimation[31][1024];
extern const unsigned char time_zone [];
extern const unsigned char alarm_ring [];
extern const unsigned char alarm_disable [];
extern const unsigned char medicine_time [];
extern const unsigned char time_zone[];
extern const unsigned char alarm_ring[];
extern const unsigned char alarm_disable[];
extern const unsigned char medicine_time[];
extern const unsigned char reset[];
53 changes: 32 additions & 21 deletions src/alarms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#include <Functions.h>
#include <Constants.h>

bool alarm_enabled = true;
bool alarm_enabled;
const int n_alarms = 3;
int alarm_hours[] = {0, 1, 2};
int alarm_minutes[] = {1, 10, 20};
bool alarm_triggered[] = {false, false, false};
int alarm_hours[n_alarms];
int alarm_minutes[n_alarms];
bool alarm_triggered[n_alarms];

const int n_notes = 8;
const int C = 262;
Expand All @@ -21,9 +21,9 @@ const int notes[] = {C, D, E, F, G, A, B, C_H};

void ring_alarm()
{
// Turning the LED ON
// Turning the LED ON
digitalWrite(LED_1, HIGH);
show_modal_page(medicine_time ,1000,"It's Medicine Time!", 8);
show_modal_page(medicine_time, 200, "It's Medicine Time!", 8);
// Ringing the buzzer

bool break_happened = false;
Expand Down Expand Up @@ -57,20 +57,20 @@ void set_alarm(int alarm)
{
display.clearDisplay();
display.fillRoundRect(23, 12, 39, 34, 4, WHITE);
println(formatNumber(temp_hour), 26, 18, 3,false, BLACK);
println(formatNumber(temp_minute), 76, 18, 3,true, WHITE);
println(":", 60, 18, 3,true, WHITE);
println(formatNumber(temp_hour), 26, 18, 3, false, BLACK);
println(formatNumber(temp_minute), 76, 18, 3, true, WHITE);
println(":", 60, 18, 3, true, WHITE);
int pressed = wait_for_button_press();

if (pressed == PB_UP)
{
delay(200);
delay(50);
temp_hour++;
temp_hour = temp_hour % 24;
}
else if (pressed == PB_DOWN)
{
delay(200);
delay(50);
temp_hour--;
temp_hour = temp_hour % 24;
if (temp_hour < 0)
Expand All @@ -80,36 +80,36 @@ void set_alarm(int alarm)
}
else if (pressed == PB_OK)
{
delay(200);
delay(50);
alarm_hours[alarm] = temp_hour;
break;
}
else if (pressed == PB_CANCEL)
{
delay(200);
delay(50);
return;
}
}

while (true)
{
display.fillRoundRect(23, 12, 39, 34, 4, BLACK);
println(formatNumber(temp_hour), 26, 18, 3,false, WHITE);
//Above two lines removes the white background around the hour setting state.(i.e. inverts the hour part of the display back.)
println(formatNumber(temp_hour), 26, 18, 3, false, WHITE);
// Above two lines removes the white background around the hour setting state.(i.e. inverts the hour part of the display back.)
display.fillRoundRect(73, 12, 39, 34, 4, WHITE);
println(formatNumber(temp_minute), 76, 18, 3,true, BLACK);
println(formatNumber(temp_minute), 76, 18, 3, true, BLACK);

int pressed = wait_for_button_press();

if (pressed == PB_UP)
{
delay(200);
delay(50);
temp_minute++;
temp_minute = temp_minute % 60;
}
else if (pressed == PB_DOWN)
{
delay(200);
delay(50);
temp_minute--;
temp_minute = temp_minute % 60;
if (temp_minute < 0)
Expand All @@ -119,15 +119,26 @@ void set_alarm(int alarm)
}
else if (pressed == PB_OK)
{
delay(200);
delay(50);
alarm_minutes[alarm] = temp_minute;
if (!alarm_enabled)
{
alarm_enabled = true;
save_is_alarm_enabled();
for (int i = 0; i < n_alarms; i++)
{
alarm_triggered[i] = true;
}
alarm_triggered[alarm] = false;
}

show_modal_page(alarm_ring,1000,"Alarm set to "+formatNumber(temp_hour)+":"+formatNumber(temp_minute),10);
show_modal_page(alarm_ring, 1000, "Alarm set to " + formatNumber(temp_hour) + ":" + formatNumber(temp_minute), 10);
save_alarm(alarm);
break;
}
else if (pressed == PB_CANCEL)
{
delay(200);
delay(50);
break;
}
}
Expand Down
Loading