# Sinker-System-Controller (based on Sinker-Camera-Controller)

Sinker-System-Controller is an Arduino (C++) firmware for controlling the Sinker imaging system camera modules. The system is designed around a [LowPowerLabs](https://lowpowerlab.com/) [Moteino M0](https://lowpowerlab.com/category/moteino/moteinom0/), which is a compact and pin-rich breakout board for the Atmel SAMD21.

## Requirements

- [Sinker-System-Controller] hardware
- [Arduino](https://www.arduino.cc/en/software)
- [LowPowerLab SAMD Release](https://lowpowerlab.com/2020/03/04/moteino-samd-1-5-0-release/)

## Highly Recommended

- [VS Code](https://code.visualstudio.com/)
- [PlatformIO](https://platformio.org/) with [Atmel SAM Platform](https://docs.platformio.org/en/latest/platforms/atmelsam.html) and [Moteino M0 Environment](https://docs.platformio.org/en/latest/boards/atmelsam/moteino_zero.html?highlight=moteino_zero)

## Build

It is also necessary to build the SCC application using the following
compliation flag to work with the custom bootloader:

-D CRYSTALLESS

In our case, this step can be accomplished by adding a new line to
the platformio.ini file for this project:

build_flags = -D CRYSTALLESS

## System Architecture

Details of the architecture will be described soon. For the time being, the system does the following:

### Setup

1. Start the debug serial port (USB)
2. Setup pins modes
3. Initialize DS3231 real time clock
4. Start timers
5. Initialize flash
6. Start sensors
7. Add all of the config parameters to the SystemConfig object
8. Configure watchdog
9. Start all of the remaining serial ports
10. Load saved SystemConfig values from flash
11. Load saved Scheduler from flash
12. Setup timers and ISRs for camera and flash trigger signals

### Loop

1. System Update (read sensors, process data)
2. Check for user input
3. Check input voltage
4. Check environment sensors (temp, humidity, pressure)
5. Check Scheduler events
6. Check status of camera power events
7. Sleep
8. Flash status LED
9. GoTo: 1


## Reporting Issues
Please contact henthorn@mbari.org

## Licensing

- Copyright 2023 MBARI (http://www.mbari.org)

