Newer
Older
ubScopin / src / main.c


int dacX = 0x60;
int dacY = 0x61;

int main(int argc, char **argv)
{
    char buf[1];

    if (!bcm2835_init())return 1;
    bcm2835_i2c_begin();                //Start I2C operations.
    bcm2835_i2c_setSlaveAddress(0x20);  //I2C address
    bcm2835_i2c_set_baudrate(10000);    //1M baudrate

    while(1)
    {
        buf[0] = 0xEF;    //LED ON
        bcm2835_i2c_write(buf,1);
        bcm2835_delay(500);
        buf[0] = 0xFF;     //LED OFF
        bcm2835_i2c_write(buf,1);
        bcm2835_delay(500);
    }
    bcm2835_i2c_end();
    bcm2835_close();
    return 0;
}

mcp4725_setVoltageFast(int dac, u_int16_t volt) {
  bcm2835_i2c_begin();
  bcm2835_i2c_setSlaveAddress(dac);
  bcm2835_i2c_write(volt>>8);
  bcm2835_i2c_write(volt);
  bcm2835_i2c_end();
}
#include "util.h"
#include "config.h"
#include "dac.h"
#include "pecado.h"
#include "text.h"
#include "line.h"
#include "shape.h"

void setup() {
  Serial.begin(9600);
  xyz.Setup();
    //digitalWrite(A4, LOW);
//digitalWrite(A5, LOW);
}

void loop() {

  //draw_spiral();
  //draw_marchingborder();
  draw_xyxor();
}

int16_t scale = 0;
int16_t scale_sin = 1;
int8_t  scale_sin_d = -1;
int16_t textscale = 4 * 256;
int16_t  d_textscale = 100;
uint8_t a;
uint16_t textangle = 0;

uint8_t centre_x, centre_y;
uint16_t centreangle = 0;

#define XYXOR_WORD "ZLOSHA"
#define XYXOR_LEN  3

void draw_marchingborder()
{

  trazador.SetPace(0);
  for (int i = -1, f = 0; i < 256; i += 8, f++) {
    int16_t x = 128 + isin(i);
    int16_t y = 128 + icos(i);
    if (i == -1 || ((f + textangle / 4) % 2 == 0)) {
      trazador.MoveTo(x, y);
    }
    else {
      trazador.LineTo(x, y);
    }
  }
}

void draw_spiral()
{
  for (int i = -1; i < 256; i += 8) {
    int16_t x = isin(a);
    int16_t y = icos(a);
    x = 128 + (x * scale) / 128;
    y = 128 + (y * scale) / 128;
    if (i == -1) {
      trazador.MoveTo(x, y);
    }
    else {
      trazador.LineTo(x, y);
    }
    scale += 4;
    a += 8;
  }
}

char timetext[6];
char bigtext[17];
uint16_t time;
uint16_t frameno;

void updateText()
{
  timetext[0] = '0' + (time >> 12);
  timetext[1] = '0' + ((time >> 8) & 15);
  timetext[2] = (frameno & 64) == 0 ? ':' : ' ';
  timetext[3] = '0' + ((time >> 4) & 15);
  timetext[4] = '0' + (time & 15);
  timetext[5] = 0;

  if ((frameno & 16) == 0) {
    //for (int i = 0; i < 4; i++) {
    int i = rand() % 4;
    int rnd;
    while ((rnd = rand() % 32) > 25);
    bigtext[i] = 'A' + rnd;
    //}
    bigtext[4] = 0;
  }
}

void draw_xyxor()
{
  frameno++;

  trazador.SetPace(0);
  scale = 0;

  //draw_marchingborder();
  //draw_spiral();

  int ox = 128 - textscale * TEXT_CHARWIDTH * XYXOR_LEN / 2 / 256;
  int oy = 128 - textscale * TEXT_CHARHEIGHT / 2 / 256;
  irotate(&ox, &oy, 128, 128, textangle / 5);
  trazador.MoveTo(ox, oy);
  //text.Str(XYXOR_WORD, textscale, textangle/5);

  textangle--;
  textscale += d_textscale;
  if (textscale > 12 * 256 || textscale < 4 * 256) d_textscale = -d_textscale;

  centre_x = 128 + isin(centreangle) / 4;
  centre_y = 128 + icos(centreangle) / 4;
  centreangle += 1;

  if (++scale == 128) scale = 1;
Serial.println(millis());
  star.SetTransform(centre_x, centre_y, textscale/2, textscale/2, textangle/5);
  star.Trace();
  Serial.println(millis());

#if 0
  sinus.SetHalfPeriods(2);
  scale_sin += scale_sin_d;
  if (scale_sin == 32 || scale_sin == -32) scale_sin_d = -scale_sin_d;
  sinus.SetTransform(128, 200, 100, scale_sin, 0);
  sinus.Trace();
#endif

  //sinus.SetTransform(128,200, 256, scale_sin, 0);
  //scale_sin += scale_sin_d;
  //if (scale_sin == 128 || scale_sin == -128) scale_sin_d = -scale_sin_d;

  //draw_marchingborder();
#if 0
  if ((textangle & 7) == 0) {
    grid.SetTransform(128, 128, 180, 180, 0);
    //grid.SetTransform(centre_x, centre_y, 180, 180, textangle);
    grid.Trace();
  }
#endif

  if (frameno % 16 == 0) {
    time = (time & 0xff00) + bcd_increment(time & 0xff);
    if ((time & 0xff) == 0x60) {
      time = bcd_increment(time >> 8) << 8;
    }
    updateText();
  }
/*
  trazador.MoveTo(60, 50);
  text.Str(timetext, 1024, 0);
  trazador.MoveTo(30, 100);
  text.Str(bigtext, 2048, 0);
  */
}