Skip to content

Commit

Permalink
rework IrDA demo, add face to display test file
Browse files Browse the repository at this point in the history
  • Loading branch information
joeycastillo committed Dec 16, 2024
1 parent cdb92fb commit dce2187
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 1 deletion.
1 change: 1 addition & 0 deletions movement_faces.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
#include "preferences_face.h"
#include "light_sensor_face.h"
#include "irda_demo_face.h"
#include "file_demo_face.h"
#include "chirpy_demo_face.h"
// New includes go above this line.
1 change: 1 addition & 0 deletions watch-faces.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ SRCS += \
./watch-faces/settings/preferences_face.c \
./watch-faces/demo/light_sensor_face.c \
./watch-faces/demo/irda_demo_face.c \
./watch-faces/demo/file_demo_face.c \
./watch-faces/io/chirpy_demo_face.c \
# New watch faces go above this line.
109 changes: 109 additions & 0 deletions watch-faces/demo/file_demo_face.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* MIT License
*
* Copyright (c) 2024 Joey Castillo
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include <stdlib.h>
#include <string.h>
#include "file_demo_face.h"
#include "tc.h"
#include "eic.h"
#include "usb.h"
#include "uart.h"
#include "filesystem.h"

#ifdef HAS_IR_SENSOR

void file_demo_face_setup(uint8_t watch_face_index, void ** context_ptr) {
(void) watch_face_index;
if (*context_ptr == NULL) {
*context_ptr = malloc(sizeof(file_demo_state_t));
memset(*context_ptr, 0, sizeof(file_demo_state_t));
// Do any one-time tasks in here; the inside of this conditional happens only at boot.
}
}

void file_demo_face_activate(void *context) {
file_demo_state_t *state = (file_demo_state_t *)context;
(void) state;
}

bool file_demo_face_loop(movement_event_t event, void *context) {
file_demo_state_t *state = (file_demo_state_t *)context;
(void) state;
char buf[7];

switch (event.event_type) {
case EVENT_NONE:
case EVENT_ACTIVATE:
REDISPLAY:
watch_clear_display();
// display the contents of a file called "1TEST"
if (filesystem_file_exists("1TEST")) {
filesystem_read_file("1TEST", buf, sizeof(buf));
buf[6] = 0;
watch_display_text_with_fallback(WATCH_POSITION_TOP, "TF", "TST F");
watch_display_text(WATCH_POSITION_BOTTOM, buf);
} else {
watch_display_text(WATCH_POSITION_FULL, "NO FILE ");
}
break;
case EVENT_TICK:
break;
case EVENT_LIGHT_BUTTON_DOWN:
state->delete_enabled = false;
goto REDISPLAY;
break;
case EVENT_ALARM_BUTTON_UP:
if (state->delete_enabled) {
filesystem_rm("1TEST");
movement_force_led_off();
state->delete_enabled = false;
goto REDISPLAY;
} else if (filesystem_file_exists("1TEST")) {
movement_force_led_on(255, 0, 0);
watch_clear_display();
watch_display_text(WATCH_POSITION_BOTTOM, "0ElET?");
state->delete_enabled = true;
}
break;
case EVENT_TIMEOUT:
// movement_move_to_face(0);
break;
case EVENT_LOW_ENERGY_UPDATE:
watch_display_text(WATCH_POSITION_TOP_RIGHT, " <");
break;
default:
return movement_default_loop_handler(event);
}

return false;
}

void file_demo_face_resign(void *context) {
file_demo_state_t *state = (file_demo_state_t *)context;

movement_force_led_off();
state->delete_enabled = false;
}

#endif // HAS_IR_SENSOR
52 changes: 52 additions & 0 deletions watch-faces/demo/file_demo_face.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* MIT License
*
* Copyright (c) 2024 Joey Castillo
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#pragma once

#include "movement.h"

/*
* FILE DISPLAY DEMO
*
* Displays the contents of a file on the watch.
* For use with the irda_demo_face that allows uploading files to the watch.
*
*/

typedef struct {
bool delete_enabled;
} file_demo_state_t;

void file_demo_face_setup(uint8_t watch_face_index, void ** context_ptr);
void file_demo_face_activate(void *context);
bool file_demo_face_loop(movement_event_t event, void *context);
void file_demo_face_resign(void *context);

#define file_demo_face ((const watch_face_t){ \
file_demo_face_setup, \
file_demo_face_activate, \
file_demo_face_loop, \
file_demo_face_resign, \
NULL, \
})
2 changes: 1 addition & 1 deletion watch-faces/demo/irda_demo_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ bool irda_demo_face_loop(movement_event_t event, void *context) {
movement_force_led_on(0, 48, 0);
}
char buf[14];
snprintf(buf, 11, "IR%2d%c%c%c%c%c%c", bytes_read, data[0], data[1], data[2], data[3], data[4], data[5]);
snprintf(buf, 11, "IR%2d%c%c%c%c%c%c", bytes_read, data[1], data[2], data[3], data[4], data[5], data[6]);
watch_clear_display();
watch_display_text(WATCH_POSITION_FULL, buf);
data[31] = 0;
Expand Down

0 comments on commit dce2187

Please sign in to comment.