Skip to content

Commit

Permalink
Merge branch 'log-file-updates' of github.com:wtgee/POCS into log-fil…
Browse files Browse the repository at this point in the history
…e-updates
  • Loading branch information
wtgee committed Dec 4, 2017
2 parents 7c398be + bb7594d commit 418cad3
Show file tree
Hide file tree
Showing 26 changed files with 3,170 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## [Unreleased]
### Changed
=======
### Added
- Merge PACE into POCS
- Logs: separate files for each level and new naming scheme

## [0.5.1] - 2017-12-02
Expand Down
3 changes: 2 additions & 1 deletion pocs/tests/test_observatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pocs.scheduler.dispatch import Scheduler
from pocs.scheduler.observation import Observation
from pocs.utils import error
from pocs.version import version

has_camera = pytest.mark.skipif(
not pytest.config.getoption("--camera"),
Expand Down Expand Up @@ -168,7 +169,7 @@ def test_standard_headers(observatory):

test_headers = {
'airmass': 1.091778,
'creator': 'POCSv0.5.1',
'creator': 'POCSv{}'.format(version),
'elevation': 3400.0,
'ha_mnt': 1.6844671878927793,
'latitude': 19.54,
Expand Down
5 changes: 2 additions & 3 deletions pocs/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# this file was automatically generated
major = 0
minor = 5
release = 1
patch = 1

version = '{}.{}.{}'.format(major, minor, release)
version = '{}.{}.{}'.format(major, minor, patch)
165 changes: 165 additions & 0 deletions resources/arduino_files/camera_board/camera_board.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#include <Wire.h>
#include <stdlib.h>
#include <Adafruit_MMA8451.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>

#define DHT_TYPE DHT22 // DHT 22 (AM2302)

/* DECLARE PINS */
const int DHT_PIN = 9; // DHT Temp & Humidity Pin
const int CAM_01_RELAY = 5;
const int CAM_02_RELAY = 6;
const int RESET_PIN = 12;


/* CONSTANTS */
Adafruit_MMA8451 accelerometer = Adafruit_MMA8451();

// Setup DHT22
DHT dht(DHT_PIN, DHT_TYPE);

int led_value = LOW;

void setup(void) {
Serial.begin(9600);
Serial.flush();

// Turn off LED inside camera box
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);

// Setup Camera relays
pinMode(CAM_01_RELAY, OUTPUT);
pinMode(CAM_02_RELAY, OUTPUT);

pinMode(RESET_PIN, OUTPUT);

// Turn on Camera relays
turn_pin_on(CAM_01_RELAY);
turn_pin_on(CAM_02_RELAY);

if (! accelerometer.begin()) {
while (1);
}

dht.begin();

// Check Accelerometer range
// accelerometer.setRange(MMA8451_RANGE_2_G);
// Serial.print("Accelerometer Range = "); Serial.print(2 << accelerometer.getRange());
// Serial.println("G");
}

void loop() {

// Read any serial input
// - Input will be two comma separated integers, the
// first specifying the pin and the second the status
// to change to (1/0). Cameras and debug led are
// supported.
// Example serial input:
// 4,1 # Turn fan on
// 13,0 # Turn led off
while (Serial.available() > 0) {
int pin_num = Serial.parseInt();
int pin_status = Serial.parseInt();

switch (pin_num) {
case CAM_01_RELAY:
case CAM_02_RELAY:
if (pin_status == 1) {
turn_pin_on(pin_num);
} else if (pin_status == 0) {
turn_pin_off(pin_num);
} else if (pin_status == 9) {
toggle_pin(pin_num);
}
break;
case RESET_PIN:
if (pin_status == 1) {
turn_pin_off(RESET_PIN);
}
break;
case LED_BUILTIN:
digitalWrite(pin_num, pin_status);
break;
}
}

// Begin reading values and outputting as JSON string
Serial.print("{");

read_status();

read_accelerometer();

read_dht_temp();

Serial.print("\"name\":\"camera_board\""); Serial.print(",");

Serial.print("\"count\":"); Serial.print(millis());

Serial.println("}");

Serial.flush();
delay(1000);
}

void read_status() {

Serial.print("\"power\":{");
Serial.print("\"camera_00\":"); Serial.print(is_pin_on(CAM_01_RELAY)); Serial.print(',');
Serial.print("\"camera_01\":"); Serial.print(is_pin_on(CAM_02_RELAY)); Serial.print(',');
Serial.print("},");
}

/* ACCELEROMETER */
void read_accelerometer() {
/* Get a new sensor event */
sensors_event_t event;
accelerometer.getEvent(&event);
uint8_t o = accelerometer.getOrientation(); // Orientation

Serial.print("\"accelerometer\":{");
Serial.print("\"x\":"); Serial.print(event.acceleration.x); Serial.print(',');
Serial.print("\"y\":"); Serial.print(event.acceleration.y); Serial.print(',');
Serial.print("\"z\":"); Serial.print(event.acceleration.z); Serial.print(',');
Serial.print("\"o\": "); Serial.print(o);
Serial.print("},");
}

//// Reading temperature or humidity takes about 250 milliseconds!
//// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
void read_dht_temp() {
float h = dht.readHumidity();
float c = dht.readTemperature(); // Celsius

Serial.print("\"humidity\":"); Serial.print(h); Serial.print(',');
Serial.print("\"temp_00\":"); Serial.print(c); Serial.print(",");
}

/************************************
* Utitlity Methods
*************************************/

void toggle_led() {
led_value = ! led_value;
digitalWrite(LED_BUILTIN, led_value);
}

void toggle_pin(int pin_num) {
digitalWrite(pin_num, !digitalRead(pin_num));
}

void turn_pin_on(int camera_pin) {
digitalWrite(camera_pin, HIGH);
}

void turn_pin_off(int camera_pin) {
digitalWrite(camera_pin, LOW);
}

int is_pin_on(int camera_pin) {
return digitalRead(camera_pin);
}
Loading

0 comments on commit 418cad3

Please sign in to comment.