mirror of
https://github.com/firewalkwithm3/Sensor-Watch.git
synced 2024-11-22 19:20:30 +08:00
Merge branch 'main' of github.com:joeycastillo/Sensor-Watch into main
This commit is contained in:
commit
fe5a3eecff
21
.github/workflows/build.yml
vendored
21
.github/workflows/build.yml
vendored
|
@ -28,3 +28,24 @@ jobs:
|
|||
with:
|
||||
name: watch.uf2
|
||||
path: movement/make/build/watch.uf2
|
||||
|
||||
build-simulator:
|
||||
container:
|
||||
image: emscripten/emsdk
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Compile movement
|
||||
run: emmake make
|
||||
working-directory: 'movement/make'
|
||||
- name: Archive simulator build
|
||||
working-directory: 'movement/make/build'
|
||||
run: |
|
||||
cp watch.html index.html
|
||||
tar -czf simulator.tar.gz index.html watch.wasm watch.js
|
||||
- name: Upload simulator build
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: simulator.tar.gz
|
||||
path: movement/make/build/simulator.tar.gz
|
||||
|
|
|
@ -22,13 +22,15 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "<#watch_face_name#>_face.h"
|
||||
|
||||
void <#watch_face_name#>_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
|
||||
(void) settings;
|
||||
if (*context_ptr == NULL) {
|
||||
*context_ptr = malloc(sizeof(<#watch_face_name#>_state_t));
|
||||
memset(*context_ptr, 0, sizeof(<#watch_face_name#>));
|
||||
memset(*context_ptr, 0, sizeof(<#watch_face_name#>_state_t));
|
||||
// Do any one-time tasks in here; the inside of this conditional happens only at boot.
|
||||
}
|
||||
// Do any pin or peripheral setup here; this will be called whenever the watch wakes from deep sleep.
|
||||
|
@ -76,7 +78,7 @@ bool <#watch_face_name#>_face_loop(movement_event_t event, movement_settings_t *
|
|||
break;
|
||||
}
|
||||
|
||||
// return true if the watch can enter standby mode. If you are PWM'ing an LED or buzzing the buzzer nere,
|
||||
// return true if the watch can enter standby mode. If you are PWM'ing an LED or buzzing the buzzer here,
|
||||
// you should return false since the PWM driver does not operate in standby mode.
|
||||
return true;
|
||||
}
|
||||
|
@ -87,3 +89,4 @@ void <#watch_face_name#>_face_resign(movement_settings_t *settings, void *contex
|
|||
|
||||
// handle any cleanup before your watch face goes off-screen.
|
||||
}
|
||||
|
||||
|
|
|
@ -46,3 +46,4 @@ void <#watch_face_name#>_face_resign(movement_settings_t *settings, void *contex
|
|||
})
|
||||
|
||||
#endif // <#WATCH_FACE_NAME#>_FACE_H_
|
||||
|
||||
|
|
94
movement/template/watch_face.py
Normal file
94
movement/template/watch_face.py
Normal file
|
@ -0,0 +1,94 @@
|
|||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2022 David Keck
|
||||
#
|
||||
# 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.
|
||||
|
||||
import os
|
||||
import re
|
||||
import datetime
|
||||
import argparse
|
||||
|
||||
|
||||
MAKEFILE_INDICATOR = "# New watch faces go above this line.\n"
|
||||
INCLUDE_INDICATOR = "// New includes go above this line.\n"
|
||||
|
||||
|
||||
def replace_placeholders(contents, args):
|
||||
modified_contents = contents.replace("<#WATCH_FACE_NAME#>", args.watch_face_name.upper())
|
||||
modified_contents = modified_contents.replace("<#watch_face_name#>", args.watch_face_name)
|
||||
modified_contents = modified_contents.replace("<#year#>", datetime.datetime.now().strftime("%Y"))
|
||||
if args.author_name:
|
||||
modified_contents = modified_contents.replace("<#author_name#>", " ".join(args.author_name))
|
||||
|
||||
return modified_contents
|
||||
|
||||
|
||||
def write_output_file(args, file_type, output_dir):
|
||||
with open(f"template.{file_type}", 'r') as file_template:
|
||||
file_contents = file_template.read()
|
||||
modified_template = replace_placeholders(file_contents, args)
|
||||
file_path = f"{output_dir}{args.watch_face_name}_face.{file_type}"
|
||||
if not os.path.exists(file_path):
|
||||
with open(file_path, 'w') as output_file:
|
||||
output_file.write(modified_template)
|
||||
else:
|
||||
print(f"Generation failed: the watch face \"{args.watch_face_name}\" already exists at {file_path}. Unable to generate new files. Exiting...")
|
||||
exit(0)
|
||||
|
||||
|
||||
def write_include_file(file_path, file_type, indicator_line, line_to_insert):
|
||||
with open(file_path, 'r+') as include_file:
|
||||
include_contents = include_file.readlines()
|
||||
if line_to_insert in include_contents:
|
||||
print(f"Generation failed: {file_path} already has an entry for {line_to_insert.strip()}. Unable to generate new files. Exiting...")
|
||||
exit(0)
|
||||
new_face_index = include_contents.index(indicator_line)
|
||||
include_contents.insert(new_face_index, line_to_insert)
|
||||
include_file.seek(0)
|
||||
include_file.writelines(include_contents)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Create a new watch face.")
|
||||
parser.add_argument("watch_face_type", metavar="face_type", type=str, choices=["complication", "clock"], help="The type of watch face to create, either \"complication\" or \"clock\"")
|
||||
parser.add_argument("watch_face_name", metavar="face_name", type=str, help="The name of the watch face")
|
||||
parser.add_argument("--author_name", metavar="author_name", type=str, nargs='*', help="The name of the author")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
name_valid = re.fullmatch(r'[a-zA-Z_][a-zA-Z0-9_]*', args.watch_face_name)
|
||||
if name_valid == None:
|
||||
print(f"Generation failed: {args.watch_face_name} is not a valid C variable name. Exiting...")
|
||||
exit(0)
|
||||
|
||||
line_to_insert = f"#include \"{args.watch_face_name}_face.h\"\n"
|
||||
write_include_file(f"..{os.sep}movement_faces.h", "h", INCLUDE_INDICATOR, line_to_insert)
|
||||
|
||||
line_to_insert = f" ..{os.sep}watch_faces{os.sep}{args.watch_face_type}{os.sep}{args.watch_face_name}_face.c \\\n"
|
||||
write_include_file(f"..{os.sep}make{os.sep}Makefile", "c", MAKEFILE_INDICATOR, line_to_insert)
|
||||
|
||||
output_dir = f"..{os.sep}watch_faces{os.sep}{args.watch_face_type}{os.sep}"
|
||||
write_output_file(args, "h", output_dir)
|
||||
write_output_file(args, "c", output_dir)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
|
||||
#include "watch_adc.h"
|
||||
#include "driver_init.h"
|
||||
|
||||
static void _watch_sync_adc(void) {
|
||||
while (ADC->SYNCBUSY.reg);
|
||||
|
@ -138,13 +139,30 @@ void watch_set_analog_sampling_length(uint8_t cycles) {
|
|||
_watch_sync_adc();
|
||||
}
|
||||
|
||||
static inline uint32_t _watch_adc_get_reference_voltage(const watch_adc_reference_voltage reference) {
|
||||
switch (reference) {
|
||||
case ADC_REFERENCE_INTREF:
|
||||
return ADC_REFCTRL_REFSEL_INTREF_Val;
|
||||
break;
|
||||
case ADC_REFERENCE_VCC_DIV1POINT6:
|
||||
return ADC_REFCTRL_REFSEL_INTVCC0_Val;
|
||||
break;
|
||||
case ADC_REFERENCE_VCC_DIV2:
|
||||
return ADC_REFCTRL_REFSEL_INTVCC1_Val;
|
||||
break;
|
||||
case ADC_REFERENCE_VCC:
|
||||
return ADC_REFCTRL_REFSEL_INTVCC2_Val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void watch_set_analog_reference_voltage(watch_adc_reference_voltage reference) {
|
||||
ADC->CTRLA.bit.ENABLE = 0;
|
||||
|
||||
if (reference == ADC_REFERENCE_INTREF) SUPC->VREF.bit.VREFOE = 1;
|
||||
else SUPC->VREF.bit.VREFOE = 0;
|
||||
|
||||
ADC->REFCTRL.bit.REFSEL = reference;
|
||||
ADC->REFCTRL.bit.REFSEL = _watch_adc_get_reference_voltage(reference);
|
||||
ADC->CTRLA.bit.ENABLE = 1;
|
||||
_watch_sync_adc();
|
||||
// throw away one measurement after reference change (the channel doesn't matter).
|
||||
|
|
|
@ -27,23 +27,6 @@
|
|||
|
||||
#include "watch.h"
|
||||
|
||||
// matches adc.h
|
||||
#ifndef ADC_REFCTRL_REFSEL_INTREF_Val
|
||||
#define ADC_REFCTRL_REFSEL_INTREF_Val 0x0
|
||||
#endif
|
||||
|
||||
#ifndef ADC_REFCTRL_REFSEL_INTVCC0_Val
|
||||
#define ADC_REFCTRL_REFSEL_INTVCC0_Val 0x1
|
||||
#endif
|
||||
|
||||
#ifndef ADC_REFCTRL_REFSEL_INTVCC1_Val
|
||||
#define ADC_REFCTRL_REFSEL_INTVCC1_Val 0x2
|
||||
#endif
|
||||
|
||||
#ifndef ADC_REFCTRL_REFSEL_INTVCC2_Val
|
||||
#define ADC_REFCTRL_REFSEL_INTVCC2_Val 0x5
|
||||
#endif
|
||||
|
||||
/** @addtogroup adc Analog Input
|
||||
* @brief This section covers functions related to the SAM L22's analog-to-digital converter,
|
||||
* as well as configuring and reading values from the five analog-capable pins on the
|
||||
|
@ -112,10 +95,10 @@ void watch_set_analog_num_samples(uint16_t samples);
|
|||
void watch_set_analog_sampling_length(uint8_t cycles);
|
||||
|
||||
typedef enum {
|
||||
ADC_REFERENCE_INTREF = ADC_REFCTRL_REFSEL_INTREF_Val,
|
||||
ADC_REFERENCE_VCC_DIV1POINT6 = ADC_REFCTRL_REFSEL_INTVCC0_Val,
|
||||
ADC_REFERENCE_VCC_DIV2 = ADC_REFCTRL_REFSEL_INTVCC1_Val,
|
||||
ADC_REFERENCE_VCC = ADC_REFCTRL_REFSEL_INTVCC2_Val,
|
||||
ADC_REFERENCE_INTREF = 0,
|
||||
ADC_REFERENCE_VCC_DIV1POINT6,
|
||||
ADC_REFERENCE_VCC_DIV2,
|
||||
ADC_REFERENCE_VCC,
|
||||
} watch_adc_reference_voltage;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue