Browse code

fix vibration every minutes on low battery

Louis authored on12/12/2022 18:41:53
Showing5 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,8 @@
1
+argv = ['/home/louis/.pebble-sdk/SDKs/current/sdk-core/pebble/waf', 'configure']
2
+environ = {'WSL_INTEROP': '/run/WSL/10_interop', 'PEBBLE_TOOLCHAIN_PATH': '/home/louis/pebble-dev/pebble-sdk-4.5-linux64/arm-cs-tools/bin', 'WSL_DISTRO_NAME': 'Ubuntu-18.04', 'HOSTTYPE': 'x86_64', 'LESSOPEN': '| /usr/bin/lesspipe %s', 'LOGNAME': 'louis', 'USER': 'louis', 'NO_GCE_CHECK': 'False', 'PATH': '/home/louis/pebble-dev/pebble-sdk-4.5-linux64/arm-cs-tools/bin:/home/louis/pebble-dev/pebble-sdk-4.5-linux64/bin:/home/louis/pebble-dev/pebble-sdk-4.5-linux64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/WindowsApps/Microsoft.WindowsTerminal_1.15.2874.0_x64__8wekyb3d8bbwe:/mnt/c/Program Files/Python310/Scripts/:/mnt/c/Program Files/Python310/:/mnt/c/Program Files/Python38/Scripts/:/mnt/c/Program Files/Python38/:/mnt/c/Program Files/Python39/Scripts/:/mnt/c/Program Files/Python39/:/mnt/c/ProgramData/Oracle/Java/javapath:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/Program Files (x86)/PuTTY/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files/nodejs/:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/Microsoft VS Code/bin:/mnt/c/Python27/:/mnt/c/Python27/Scripts/:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/mnt/c/Program Files/Calibre2/:/mnt/c/Users/Sandy/scoop/shims:/mnt/c/Users/Sandy/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/Sandy/AppData/Local/Programs/radare2:/mnt/c/Users/Sandy/AppData/Roaming/npm:/snap/bin', 'LIBGL_ALWAYS_INDIRECT': '1', 'HOME': '/home/louis', 'WT_SESSION': '35568b07-b500-40de-a6ad-f80f0f72b31c', 'DISPLAY': '172.27.224.1:0', '_': '/home/louis/pebble-dev/pebble-sdk-4.5-linux64/.env/bin/python', 'LANG': 'C.UTF-8', 'TERM': 'xterm-256color', 'SHELL': '/bin/bash', 'LESSCLOSE': '/usr/bin/lesspipe %s %s', 'NAME': 'DESKTOP-PSQDLD8', 'XDG_DATA_DIRS': '/usr/local/share:/usr/share:/var/lib/snapd/desktop', 'OLDPWD': '/home/louis', 'PYTHONHOME': '/home/louis/.pebble-sdk/SDKs/current/sdk-core/../.env', 'NODE_PATH': '/home/louis/.pebble-sdk/SDKs/current/sdk-core/../node_modules', 'WT_PROFILE_ID': '{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}', 'SHLVL': '2', 'PWD': '/home/louis/repos/Pebble-Watchface-Day-and-Night-Earth-Connection-master', 'WSLENV': 'WT_SESSION::WT_PROFILE_ID', 'LS_COLORS': 'rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:', 'PHONESIM_PATH': '/home/louis/pebble-dev/pebble-sdk-4.5-linux64/.env//bin/pypkjs', 'NOCLIMB': '1'}
3
+files = ['/mnt/c/Users/Sandy/repos/Pebble-Watchface-Day-and-Night-Earth-Connection-master/wscript']
4
+hash = -5198275514520904974
5
+options = {'files': '', 'jobs': 4, 'verbose': 0, 'nocache': False, 'progress_bar': 0, 'no_groups': False, 'distcheck_args': None, 'top': '', 'sandbox': False, 'destdir': '', 'keep': 0, 'zones': '', 'debug': False, 'prefix': '/usr/local/', 'timestamp': None, 'download': False, 'force': False, 'targets': '', 'out': ''}
6
+out_dir = '/mnt/c/Users/Sandy/repos/Pebble-Watchface-Day-and-Night-Earth-Connection-master/build'
7
+run_dir = '/mnt/c/Users/Sandy/repos/Pebble-Watchface-Day-and-Night-Earth-Connection-master'
8
+top_dir = '/mnt/c/Users/Sandy/repos/Pebble-Watchface-Day-and-Night-Earth-Connection-master'
0 9
new file mode 100644
... ...
@@ -0,0 +1,3 @@
1
+{
2
+    "C_Cpp.errorSquiggles": "Disabled"
3
+}
0 4
\ No newline at end of file
1 5
new file mode 100644
2 6
Binary files /dev/null and b/build/Pebble-Watchface-Day-and-Night-Earth-Connection-master.pbw differ
... ...
@@ -9,8 +9,7 @@
9 9
         "messageKeys": [],
10 10
         "projectType": "native",
11 11
         "resources": {
12
-            "media": [
13
-                {
12
+            "media": [{
14 13
                     "file": "images/menu_icon.png",
15 14
                     "menuIcon": true,
16 15
                     "name": "IMAGE_MENU_ICON",
... ...
@@ -39,7 +38,6 @@
39 38
         },
40 39
         "sdkVersion": "3",
41 40
         "targetPlatforms": [
42
-            "diorite",
43 41
             "aplite"
44 42
         ],
45 43
         "uuid": "892e12bc-7a3e-411c-ba97-daa492f91088",
... ...
@@ -48,4 +46,4 @@
48 46
         }
49 47
     },
50 48
     "version": "2.1.0"
51
-}
49
+}
52 50
\ No newline at end of file
... ...
@@ -9,6 +9,7 @@
9 9
 static Window *window;
10 10
 static TextLayer *time_text_layer;
11 11
 static TextLayer *date_text_layer;
12
+static TextLayer *s_battery_layer;
12 13
 
13 14
 static GBitmap *world_bitmap;
14 15
 
... ...
@@ -16,10 +17,10 @@ static Layer *canvas;
16 17
 static GBitmap *image;
17 18
 static int redraw_counter;
18 19
 // BT connection & Battery icon declare
19
-static BitmapLayer *s_battery_icon_layer, *s_bt_icon_layer;
20
-static GBitmap *s_battery_icon_bitmap, *s_bt_icon_bitmap;
20
+static BitmapLayer *s_bt_icon_layer; //*s_battery_icon_layer
21
+static GBitmap *s_bt_icon_bitmap; //*s_battery_icon_bitmap
21 22
 static bool low_battery;
22
-static int s_battery_level;
23
+static int i_battery_level;
23 24
 // s is set to memory of size STR_SIZE, and temporarily stores strings
24 25
 char *s;
25 26
 
... ...
@@ -104,21 +105,38 @@ static void bluetooth_callback(bool connected) {
104 105
   if(!connected && !quiet_time_is_active ()) {
105 106
     // Issue a vibrating alert
106 107
     vibes_double_pulse();
107
-  }
108
+  } 
108 109
 }
109 110
 
110 111
 static void battery_callback(BatteryChargeState state) {
112
+  static char buff[4] = {};
113
+  int i = 0,temp_num = state.charge_percent, length = 0;
114
+
111 115
   // Record the new battery level
112
-  s_battery_level = state.charge_percent;
116
+  i_battery_level=state.charge_percent;
117
+  // count how many characters in the number
118
+    while(temp_num) {
119
+      temp_num /= 10;
120
+      length++;
121
+    }
122
+  for(i = 0; i < length; i++) {
123
+    buff[(length-1)-i] = '0' + (i_battery_level % 10);
124
+    i_battery_level /= 10;
125
+  }
126
+  buff[i] = '\0'; // can't forget the null byte to properly end our string
113 127
   
114
- // display icon and vibrate if low battery
115
-  if( s_battery_level < 11 && !low_battery && !state.is_charging ) {
128
+  text_layer_set_text(s_battery_layer, buff);
129
+  
130
+  // display --icon and-- vibrate if low battery and not charging
131
+  
132
+  if( state.charge_percent < 11 && !low_battery && !state.is_charging ) {
116 133
     vibes_double_pulse();
117 134
     low_battery = true;
118
-  }else if (state.is_charging) {
135
+  }else if (state.is_charging){
119 136
     low_battery = false;
120 137
   }
121
-  layer_set_hidden(bitmap_layer_get_layer(s_battery_icon_layer), !low_battery);
138
+  // Batterie is now displayed as integer, no need to display icon below
139
+  // layer_set_hidden(bitmap_layer_get_layer(s_battery_icon_layer), !low_battery);
122 140
 
123 141
 }
124 142
 
... ...
@@ -134,21 +152,29 @@ static void window_load(Window *window) {
134 152
   Layer *window_layer = window_get_root_layer(window);
135 153
   GRect bounds = layer_get_bounds(window_layer);
136 154
 
137
-  time_text_layer = text_layer_create(GRect(0, 72, 144-0, 168-72));
155
+  time_text_layer = text_layer_create(GRect(0, 72, 144-0, 49));
138 156
   text_layer_set_background_color(time_text_layer, background_color);
139 157
   text_layer_set_text_color(time_text_layer, foreground_color);
140 158
   text_layer_set_font(time_text_layer, fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49));
141
-  text_layer_set_text(time_text_layer, "");
159
+  text_layer_set_text(time_text_layer, "--");
142 160
   text_layer_set_text_alignment(time_text_layer, GTextAlignmentCenter);
143 161
   layer_add_child(window_layer, text_layer_get_layer(time_text_layer));
144 162
 
145
-  date_text_layer = text_layer_create(GRect(0, 130, 144-0, 168-130));
163
+  date_text_layer = text_layer_create(GRect(0, 121, 144-0, 21));
146 164
   text_layer_set_background_color(date_text_layer, background_color);
147 165
   text_layer_set_text_color(date_text_layer, foreground_color);
148 166
   text_layer_set_font(date_text_layer, fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21));
149
-  text_layer_set_text(date_text_layer, "");
167
+  text_layer_set_text(date_text_layer, "--");
150 168
   text_layer_set_text_alignment(date_text_layer, GTextAlignmentCenter);
151 169
   layer_add_child(window_layer, text_layer_get_layer(date_text_layer));
170
+  
171
+  s_battery_layer = text_layer_create(GRect(102, 147, 42, 20));
172
+  text_layer_set_background_color(s_battery_layer, background_color);
173
+  text_layer_set_text_color(s_battery_layer, foreground_color);
174
+  text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_LECO_20_BOLD_NUMBERS));
175
+  text_layer_set_text(s_battery_layer, "---");
176
+  text_layer_set_text_alignment(s_battery_layer, GTextAlignmentRight);
177
+  layer_add_child(window_layer, text_layer_get_layer(s_battery_layer));
152 178
 
153 179
   canvas = layer_create(GRect(0, 0, bounds.size.w, bounds.size.h));
154 180
   layer_set_update_proc(canvas, draw_watch);
... ...
@@ -160,13 +186,14 @@ static void window_load(Window *window) {
160 186
   //----------------
161 187
   
162 188
   // Create the Battery icon GBitmap
163
-  s_battery_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BATTERY );
189
+  //s_battery_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BATTERY );
164 190
   
165 191
   // Create the BitmapLayer to display the GBitmap
192
+  /*
166 193
   s_battery_icon_layer = bitmap_layer_create(GRect( 127, 143, 14, 22));
167 194
   bitmap_layer_set_bitmap(s_battery_icon_layer, s_battery_icon_bitmap);
168 195
   layer_add_child(window_layer, bitmap_layer_get_layer(s_battery_icon_layer));
169
-  
196
+  */
170 197
   //----------------
171 198
   
172 199
   // Create the Bluetooth icon GBitmap
... ...
@@ -190,8 +217,8 @@ static void window_unload(Window *window) {
190 217
   gbitmap_destroy(image);
191 218
   gbitmap_destroy(s_bt_icon_bitmap);
192 219
   bitmap_layer_destroy(s_bt_icon_layer);
193
-  gbitmap_destroy(s_battery_icon_bitmap);
194
-  bitmap_layer_destroy(s_battery_icon_layer);
220
+  //gbitmap_destroy(s_battery_icon_bitmap);
221
+  text_layer_destroy(s_battery_layer);
195 222
 }
196 223
 
197 224
 static void init(void) {