Skip to content

Commit

Permalink
Merge pull request #13 from achilikin/master
Browse files Browse the repository at this point in the history
achilikin improved RDS support
  • Loading branch information
Manawyrm committed Dec 6, 2014
2 parents 0b498f0 + b46d435 commit 2a6a0c5
Show file tree
Hide file tree
Showing 8 changed files with 332 additions and 195 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -127,6 +127,9 @@ It currently allows the following commands:
* ``ctlfmberry stereo off`` - Disables stereo signal
* ``ctlfmberry muteon`` - Mute audio
* ``ctlfmberry muteoff`` - Unmute audio
* ``ctlfmberry gainlow`` - Audio gain -9dB
* ``ctlfmberry gainoff`` - Audio gain 0dB"
* ``ctlfmberry set volume 0-6`` Audio volume level 0 to 6, equal -9dB to +9db, 3dB step
* ``ctlfmberry status`` - Print current status
* ``ctlfmberry stop`` - Stop FMBerry daemon

Expand Down
14 changes: 8 additions & 6 deletions fmberryd.c
Expand Up @@ -159,11 +159,10 @@ int main(int argc, char **argv)
// apply configuration parameters
ns741_txpwr(mmr70.txpower);
ns741_mute(mmr70.mute);
ns741_power(mmr70.power);
ns741_stereo(mmr70.stereo);
ns741_rds_set_progname(mmr70.rdsid);
ns741_rds_set_radiotext(mmr70.rdstext);

ns741_power(mmr70.power);
// Use RPI_REV1 for earlier versions of Raspberry Pi
rpi_pin_init(RPI_REVISION);

Expand All @@ -179,12 +178,13 @@ int main(int argc, char **argv)
polls[1].fd = rds;
polls[1].events = POLLPRI;
nfds = 2;
ns741_rds(1);
if (ledpin > 0) {
rpi_pin_export(ledpin, RPI_OUTPUT);
rpi_pin_set(ledpin, led);
}
ns741_rds_start();

ns741_rds(1);
ns741_rds_isr(); // send first two bytes
}

// main polling loop
Expand All @@ -195,7 +195,7 @@ int main(int argc, char **argv)

if (polls[1].revents) {
rpi_pin_poll_clear(polls[1].fd);
ProcessRDS();
ns741_rds_isr();
// flash LED if enabled on every other RDS refresh cycle
if (ledpin > 0) {
ledcounter++;
Expand Down Expand Up @@ -330,7 +330,8 @@ int ProcessTCP(int sock, mmr70_data_t *pdata)
if (str_is(buffer, "poweron"))
{
ns741_power(1);
ns741_rds_start();
ns741_rds(1);
ns741_rds_reset_radiotext();
pdata->power = 1;
break;
}
Expand Down Expand Up @@ -428,6 +429,7 @@ int ProcessTCP(int sock, mmr70_data_t *pdata)
strncpy(pdata->rdsid, arg, 8);
// ns741_rds_set_progname() will pad rdsid with spaces if needed
ns741_rds_set_progname(pdata->rdsid);
ns741_rds_reset_radiotext();
break;
}

Expand Down
1 change: 0 additions & 1 deletion fmberryd.h
Expand Up @@ -42,7 +42,6 @@ int main(int argc, char **argv);
int str_is(const char *str, const char *is);
int str_is_arg(const char *str, const char *is, const char **arg);

void *TransmitRDS();
int ListenTCP(uint16_t port);
int ProcessTCP(int sock, mmr70_data_t *pdata);
#endif
21 changes: 14 additions & 7 deletions i2c.c
@@ -1,7 +1,7 @@
/*
FMBerry - an cheap and easy way of transmitting music with your Pi.
Copyright (C) 2011-2013 by Tobias Mädel (t.maedel@alfeld.de)
Copyright (C) 2013 by Andrey Chilikin (https://github.com/achilikin)
Copyright (C) 2013-2014 by Andrey Chilikin (https://github.com/achilikin)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
Expand All @@ -20,6 +20,8 @@
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <alloca.h>
#include <memory.h>
#include <linux/i2c-dev.h>

int i2c_init(uint8_t bus, uint8_t address)
Expand Down Expand Up @@ -49,11 +51,15 @@ int i2c_select(int dev, uint8_t address)
return ioctl(dev, I2C_SLAVE, address);
}

int i2c_send_data(int dev, uint8_t *data, uint32_t len)
int i2c_send_data(int dev, uint8_t addr, uint8_t *data, uint32_t len)
{
if (write(dev, data, len) != len) {
uint8_t *buf = (uint8_t *)alloca(len+1);
memcpy(buf +1, data, len);
buf[0] = addr;
len++;

if (write(dev, buf, len) != len)
return -1;
}
return 0;
}

Expand All @@ -68,12 +74,13 @@ int i2c_send(int dev, uint8_t addr, uint8_t data)
return 0;
}

int i2c_send_word(int dev, uint8_t addr, uint8_t data0, uint8_t data1)
// send 16 bit, MSB first
int i2c_send_word(int dev, uint8_t addr, uint8_t *data)
{
char buf[3];
buf[0] = addr;
buf[1] = data0;
buf[2] = data1;
buf[1] = data[1];
buf[2] = data[0];
if ((write(dev, buf, 3)) != 3) {
return -1;
}
Expand Down
6 changes: 3 additions & 3 deletions i2c.h
@@ -1,7 +1,7 @@
/*
FMBerry - an cheap and easy way of transmitting music with your Pi.
Copyright (C) 2011-2013 by Tobias Mädel (t.maedel@alfeld.de)
Copyright (C) 2013 by Andrey Chilikin (https://github.com/achilikin)
Copyright (C) 2013-2014 by Andrey Chilikin (https://github.com/achilikin)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
Expand All @@ -22,8 +22,8 @@

int i2c_init(uint8_t bus, uint8_t address);
int i2c_select(int dev, uint8_t address);
int i2c_send_word(int dev, uint8_t addr, uint8_t data0, uint8_t data1);
int i2c_send_word(int dev, uint8_t addr, uint8_t *data);
int i2c_send(int dev, uint8_t addr, uint8_t data);
int i2c_send_data(int dev, uint8_t *data, uint32_t len);
int i2c_send_data(int dev, uint8_t addr, uint8_t *data, uint32_t len);

#endif

0 comments on commit 2a6a0c5

Please sign in to comment.